我需要根据父字段隐藏一个one2many字段的列。 通过继承account.invoice模型,我添加了一个字段inv_type。在account_invoice_line中,我需要制作隐藏字段'数量'如果inv_type ='实用程序'。
我尝试了以下代码:
的xml:
<record id="ams_invoice_form" model="ir.ui.view">
<field name="name">account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"></field>
<field name="inherit_id" ref="ams.3e_invoice_form"></field>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field/tree/field[@name='quantity']" position="replace">
<field name="quantity" attrs="{'invisible':[('parent.inv_type,'=','utility')]}" />
<field name="consumed_unit"/>
<field name="fixed_charge"/>
</xpath>
</field>
</record>
抛出客户端错误:
Odoo Client Error
Error: Unknown field parent.invoice_type in domain [["parent.invoice_type","=","utility"]]
请提出解决方案..谢谢..
答案 0 :(得分:0)
真的很复杂,作为建议你可以使用适用于odoo 9的属性:
<record id="ams_invoice_form" model="ir.ui.view">
<field name="name">account.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"></field>
<field name="inherit_id" ref="ams.3e_invoice_form"></field>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field/tree/field[@name='quantity']" position="replace">
<field name="quantity" invisible="context.get('ok_invisible', False)"/>
<field name="consumed_unit"/>
<field name="fixed_charge"/>
</xpath>
</field>
</record>
在发票模块中,它必须影响fields_view_get函数,我知道您要隐藏发票产品列表的列,因此它必须影响account.invoice.line对象:
class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False):
if self.invoice_id.inv_type == 'utility':
self = self.with_context(ok_invisible=True)
else:
self = self.with_context(ok_invisible=False)
return super(AccountInvoiceLine, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
答案 1 :(得分:0)
在Odoo 8.0中,我不得不实施一些其他功能。它在视图中具有相同的逻辑,但我必须使用sale.order的fields_view_get方法,并且需要从其标识符加载订单:
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False,
submenu=False):
order = False
params = self.env.context.get('params', False)
if params:
order_id = params.get('id', False)
if order_id:
order = self.browse(order_id)
if order and not order.is_agreement:
self = self.with_context(hide_agreement_cols=False)
result = super(SaleOrder, self).fields_view_get(
view_id=view_id, view_type=view_type,
toolbar=toolbar, submenu=submenu
)
return result