This question has been flagged
2 Replies
3970 Views

I am inheriting maintenance.request and adding four buttons on maintenance form. I only want to show one button at new request stage and all other three on the next stage. Any help would be appreciable.

XML:

<record model="ir.ui.view" id="maintenance_requests_inherit_view">
<field name="name">Maintenance Requests</field>
<field name="model">maintenance.request</field>
<field name="inherit_id" ref="maintenance.hr_equipment_request_view_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='archive_equipment_request']" position="after">
<button string="Repaired" class="oe_highlight" type="object" name="on_repaired"> </button>
</xpath>
<xpath expr="//button[@name='archive_equipment_request']" position="after">
<button string="Inspect" class="oe_highlight" type="object" name="on_inspect"> </button>
</xpath>
<xpath expr="//button[@name='archive_equipment_request']" position="after">
<button string="Material Requisition" class="oe_highlight" type="object" name="on_material_requisition"> </button>
</xpath>
<xpath expr="//button[@name='archive_equipment_request']" position="after">
<button string="Invoice" class="oe_highlight" type="object" name="generate_invoice"> </button>
</xpath>
Avatar
Discard

states  attribute can't be used here because states are not declared in source maintenance model as a Selection field. 
maintenance_stage.py

class MaintenanceStage(models.Model):
""" Model for case stages. This models the main stages of a Maintenance Request management flow. """

_name = 'maintenance.stage'
_description = 'Maintenance Stage'
_order = 'sequence, id'

name = fields.Char('Name', required=True, translate=True)
sequence = fields.Integer('Sequence', default=20)
fold = fields.Boolean('Folded in Maintenance Pipe')
done = fields.Boolean('Request Done')

Best Answer

Hi,

Along with the button you can specify states, see this example, this cancel button will be visible only in the draft state as states="draft" is given.

<button name="action_cancel" string="Cancel" type="object" class="oe_highlight" states="draft"/>

You can apply same logic for your buttons too, give states="state1,state2" , so that the button will be visible only in this two states.

Thanks

Avatar
Discard