如何在 openerp 的 one2many 上隐藏一个字段?
How to hide a field on a one2many in openerp?
我在openerp中定制了sale order菜单,将其分为两个菜单,分别命名为"Local"和一个"Export"。
我在 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.
并在 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)),
情况是这样的,如果我单击本地菜单字段:length、width 和 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" />
为您想要 show/hide 字段的菜单定义操作。
<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 中给出什么?
因此,您需要通过操作通过上下文传递该值。
试试这个,让我知道你是否会得到解决方案。
在此处编辑您的代码。
在导出 SO 的操作中替换此部分。
<field name="context">
{'default_is_export':'1','is_local':False}
</field>
将此部分替换为本地 SO 的操作。
<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)" />
我在openerp中定制了sale order菜单,将其分为两个菜单,分别命名为"Local"和一个"Export"。 我在 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.
并在 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)),
情况是这样的,如果我单击本地菜单字段:length、width 和 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" />
为您想要 show/hide 字段的菜单定义操作。
<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 中给出什么?
因此,您需要通过操作通过上下文传递该值。
试试这个,让我知道你是否会得到解决方案。
在此处编辑您的代码。在导出 SO 的操作中替换此部分。
<field name="context">
{'default_is_export':'1','is_local':False}
</field>
将此部分替换为本地 SO 的操作。
<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)" />