How to hide a field on one in openerp?

I set up a sales order menu in openerp, turning it into two menus called Local and the other called Export. I add some kind of field to the sale.order class :

'is_local' : fields.boolean('Local'), #Default as true if user clicked the Local menu.
'is_export' : fields.boolean('Export'), #Default as true if user clicked the Export menu.

      

and the sale.order.line class:

'is_local' : fields.related('order_id','is_local',type='boolean',string='Local',store=True)
'is_export' : fields.related('order_id','is_export',type='boolean',string='Export',store=True)
'length' : fields.float('Length', digits=(12,2)),
'width' : fields.float('Width', digits=(12,2)),
'height' : fields.float('Height', digits=(12,2)),

      

The situation is this: if I click on the local menu of the field: length , width and height on the sale.order site. the row must be hidden in the view.

I did this on my sale_order view:

<field name="order_line" context="{'default_is_local': local}"/>
    <tree string="Order line">
        <field name="is_local"/>
        <field name="length" invisible="context.get('is_local',True)"/>
    .
    .
    .
</field>

      

Using invisible = "context.get ('is_local', True)" its problem is that it also hides the field, if I select the export w / c menu, it should not be hidden When I use attrs = "{' invisible ': [(' is_local ',' = ', True)]} " , it does not hide this field in both local and export menu. I don't know which method should be used.

I am using openerp v7

Any help is greatly appreciated!

====================================== EDIT

<record id="view_order_form_inherit" model="ir.ui.view">
<field name="name">biz1.view.order.sale</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="priority">1</field>
<field name="arch" type="xml">
    <xpath expr="//field[@name='partner_id']" position="after">
        <field name="is_export" attrs="{'invisible':[('is_export','=',False)]}" />
        <field name="is_local" attrs="{'invisible':[('is_local','=',False)]}" />
    </xpath>
    <xpath expr="//field[@name='order_line']" position="replace">
        <field name="order_line" context="{'default_is_local':is_local}"
            colspan="4" nolabel="1" widget="one2many_list">
            <tree string="Order Line" editable="bottom" />
            <field name="sequence" widget="handle" />
            <field name="state" invisible="1" />
            <field name="th_weight" invisible="1" />
            <field name="is_local" />
            <field name="product_id"
                context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                groups="base.group_user"
                on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, context)" />
            <field name="name" />
            <field name="product_uom_qty"
                context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)" />
            <field name="product_uom"
                on_change="product_uom_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, False, parent.date_order, context)"
                groups="product.group_uom" options='{"no_open": True}' />
            <field name="product_uos_qty" groups="product.group_uos"
                invisible="1" />
            <field name="product_uos" string="UoS" groups="product.group_uos"
                invisible="1" />
            <field name="tax_id" widget="many2many_tags"
                domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]" />
            <field name="price_unit" />
            <field name="length" invisible="context.get('is_local',True)"  />
            <field name="width" invisible="context.get('is_local',True)"   />
            <field name="height" invisible="context.get('is_local',True)"  />
            <field name="discount" groups="sale.group_discount_per_so_line" />
            <field name="price_subtotal" />
        </tree>
        </field>
    </xpath>
</field></record>


<!-- ##### LOCAL SO #### -->

<record id="action_local_sale_orders" model="ir.actions.act_window">
<field name="name">Local SO</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="view_id" ref="view_order_form_inherit" />
<field name="context">
    {'default_is_local':'1'}
</field>
<field name="domain">[('is_local','=','1')]</field>
<field name="help" type="html">
    <p class="oe_view_nocontent_create">
        Click to create a quotation that can be converted into a sales order.
     </p>
    <p>
        OpenERP will help you efficiently handle the complete sales flow: quotation,
        sales order, delivery, invoicing and payment.
    </p>
</field>
</record>

<menuitem action="action_local_sale_orders" name="Local"
id="menu_local_sale_order" parent="base.menu_sales" sequence="6"
groups="base.group_sale_salesman,base.group_sale_manager" />


<!-- ##### EXPORT SO #### -->

<record id="action_export_sale_orders" model="ir.actions.act_window">
<field name="name">Export SO</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="view_id" ref="view_order_form_inherit" />
<field name="context">
    {'default_is_export':'1'}
</field>
<field name="domain">[('is_export','=','1')]</field>
<field name="help" type="html">
    <p class="oe_view_nocontent_create">
        Click to create a quotation that can be converted into a sales order.
     </p>
    <p>
        OpenERP will help you efficiently handle the complete sales flow: quotation,
        sales order, delivery, invoicing and payment.
    </p>
</field>
</record>

<menuitem action="action_export_sale_orders" name="Export"
id="menu_export_sale_order" parent="base.menu_sales" sequence="6"
groups="base.group_sale_salesman,base.group_sale_manager" />

      

+3


source to share


1 answer


Define the actions for the menu where you want to show / hide fields.

<record id="action_id" model="ir.actions.act_window">
    <field name="name">Name</field>
    <field name="res_model">Model</field>
    <field name="type">ir.actions.act_window</field>
    <field name="view_type">form</field>
    <field name="view_mode">form</field>
    <field name="context">{'is_local' : True}</field>
</record>

      

And assign this action in the menu. and then your code works fine.

The reason you don't get proper output is because related fields always give a value after your related records have been saved. in your case, if the order is not created, then what does it give in is_local and is_export?

So, you need to pass this value through the context using an action.

Try this and let me know if you get a solution or not.



Edited your code here.

Replace this part in the Export SO action.

<field name="context">
    {'default_is_export':'1','is_local':False}
</field>

      

Replace this part in the Local SO action.

<field name="context">
    {'is_local':True}
</field>

      

And replace those fields in the field of view.

<field name="length" invisible="context.get('is_local',False)"  />
<field name="width" invisible="context.get('is_local',False)"   />
<field name="height" invisible="context.get('is_local',False)"  />

      

+1


source







All Articles