Ich habe eine Schaltfläche, die ich nur anzeigen muss, wenn der Benutzer ein Superuser (admin) ist. Mein Problem ist, dass, wenn ich xpath verwende, um die attrs einzuschließen, nichts wie erwartet funktioniert. Mein Code ist:bedingt einen Knopf ausblenden openerp/odoo
<record id="wms_stock_view_move_form" model="ir.ui.view">
<field name="name">wms.stock.view.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="arch" type="xml">
<field name="location_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<field name="location_id" position="after">
<field name="is_superuser"/>
</field>
<field name="location_dest_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<xpath expr='//form[@string="Stock Moves"]' position='attributes'>
<attribute name="create">false</attribute>
<attribute name="edit">false</attribute>
<attribute name="delete">false</attribute>
</xpath>
<xpath expr="//button[@name='action_cancel']" position="attributes">
<attribute name="attrs">{'invisible':[('is_superuser','=', True)]}</attribute>
</xpath>
</field>
</record>
hier is_superuser ist ein berechnetes Feld, dessen Code ist:
is_superuser = fields.Boolean(compute='_is_super_user')
def _is_super_user(self):
if self._uid == SUPERUSER_ID:
self.is_superuser = True
else:
self.is_superuser = False
Der ursprüngliche Code für die Schaltfläche, in seiner ursprünglichen Ansicht ist:
<button name="action_cancel" states="draft,assigned,confirmed" string="Cancel Move" type="object"/>
irgendeine Idee, was mache ich falsch? Danke im Voraus.