I have implemented an audit feature for stock moves using a wizard. The shipments and moves are flagged for auditing depending on certain criteria and the flagged moves display buttons for the wizard. The stock.move model has new Boolean fields for audit flag and audit_fail. When audit flag is set True the Audit button is displayed in form and tree views. When audit_fail is set True then its corresponding button is displayed. However I need to hide audit flag when state is done and this is not happening. Refer to code.
<!-- Stock Move Form (inherit)-->
<record id="stock_move_form_inherit" model="ir.ui.view">
<field name="name">stock.move.form.inherit</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field eval="5" name="priority"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="audit" invisible="1" />
<field name="audit_fail" invisible="1" />
<field name="note" />
</field>
<field name="product_uom" position="after">
<button name="%(vmi.move_audit)d" icon="gtk-find" type="action" class="oe_highlight" string="Audit" help="Audit" attrs="{'invisible': [('audit','<>', True)]}" states="draft,waiting,confirmed,assigned" />
<button name="fail_audit" icon="gtk-dialog-warning" type="object" class="oe_highlight" string="Failed Audit" help="Failed Audit" attrs="{'invisible': [('audit_fail','<>', True)]}" />
</field>
</field>
</record>
<!-- Stock Move Tree (inherit)-->
<record id="stock_move_tree2_inherit" model="ir.ui.view">
<field name="name">stock.move.tree2.inherit</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_tree_reception_picking" />
<field eval="5" name="priority"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="audit" invisible="1" />
<field name="audit_fail" invisible="1" />
</field>
<field name="product_qty" position="after">
<button name="%(vmi.move_audit)d" icon="gtk-find" type="action" colspan="1" help="Audit" attrs="{'invisible': [('state','=','done'),('audit','<>', True)]}" />
<button name="fail_audit" icon="gtk-dialog-warning" type="object" colspan="1" help="Failed Audit" attrs="{'invisible': [('audit_fail','<>', True)]}" />
</field>
</field>
</record>
class vmi_stock_move(osv.osv):
"""Override of stock.move"""
_name = 'stock.move'
_inherit = 'stock.move'
_columns = {
'audit': fields.boolean('Audit'),
'audit_fail': fields.boolean('Failed Audit'),
}
_defaults = {
'audit': False,
'audit_fail': False,
}
I try both states attribute and attrs with domain and neither hides the button when the field is true. Only the value of the field is being used to determine display. Can I use both the field value and the state like this or is it a conflict?
You can see in screenshot where moves in Done state still have audit buttons. They should not be there when Done but the flag needs to remain set regardless.