Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Hiding buttons depending on state or value?

By
mike
on 9/27/13, 11:51 AM 2,710 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

1

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2050
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 9/27/13, 12:09 PM

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)]

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!!!!

mike
on 9/27/13, 12:53 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 9/27/13, 11:51 AM
Seen: 2710 times
Last updated: 3/16/15, 8:10 AM