This question has been flagged
3 Replies
19709 Views

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','&lt;&gt;', 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','&lt;&gt;', 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','&lt;&gt;', True)]}" />
                  <button name="fail_audit" icon="gtk-dialog-warning" type="object" colspan="1" help="Failed Audit" attrs="{'invisible': [('audit_fail','&lt;&gt;', 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. Move form with audit buttonMove tree with audit button

Avatar
Discard
Best Answer

You want to hide it when state is done OR audit is false?

audit is a boolean, keep it simple make it = False instead of <> True

Second add the OR | operator at the front, the default operator between tuples is AND & in this case.

['|',('state','=','done'),('audit','=', False)]
Avatar
Discard
Author

Perfect. I added the OR operator and it works as desired. Now I can leave the boolean set for determining if a move was completed without the required audit being performed. Excellent! Thank you so much for the assistance!!!!

Best Answer

Try this

<button name="your_button_name"  string="My Button"  type="object" class="oe_highlight" attrs="{'invisible':['|',('state','=','done'),('audit','=', False)]}"/>

Avatar
Discard