我在openerp中自定义了销售订单菜单,将其分为两个名为“Local”的菜单,另一个菜单为“Export”。 我在 sale.order 类中添加了一些字段:
'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.
和 sale.order.line 类:
'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)),
情况就是这样,如果我点击本地菜单,则会在sale.order中显示字段:长度,宽度和高度。行必须隐藏在视图上。
我在sale_order视图中这样做了:
<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>
使用 invisible =“context.get('is_local',True)”,它的问题就是如果我选择导出菜单w / c也会隐藏字段不应该隐藏。当我使用 attrs =“{'invisible':[('is_local','=',True)]}”时,它不会隐藏本地和导出菜单上的字段。我不知道使用什么技术。
我正在使用openerp v7
非常感谢任何帮助!
====================================== 修改
<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','<>','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" />
答案 0 :(得分:1)
定义要显示/隐藏字段的菜单的操作。
<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>
并将该操作分配给菜单。然后你的代码工作正常。
您没有得到正确输出的原因是,一旦您的相关记录被存储,相关字段总是给出值。在你的情况下,如果没有创建订单,那么它在is_local和is_export中提供了什么?
因此,您需要通过操作将该值传递给上下文。
试试这个并告诉我你是否会得到解决方案。
在这里编辑了你的代码。<field name="context">
{'default_is_export':'1','is_local':False}
</field>
<field name="context">
{'is_local':True}
</field>
<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)" />