I need to invisible a column of one2many field based on parent field. By inheriting account.invoice model i have added a field inv_type. In account_invoice_line i need to make invisible field 'quantity' if inv_type = 'utility'.
我需要根据父字段隐藏一个one2many字段的列。通过继承account.invoice模型,我添加了一个字段inv_type。在account_invoice_line中,如果inv_type ='utility',我需要创建不可见字段'quantity'。
I tried below code:
我尝试下面的代码:
xml:
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>
It throwing an client error:
它抛出一个客户端错误:
Odoo Client Error
Error: Unknown field parent.invoice_type in domain [["parent.invoice_type","=","utility"]]
Please suggest a solution.. thanks..
请提出解决方案..谢谢..
2 个解决方案
#1
0
Really complicated, as a suggestion you can use an attribute that applies in odoo 9:
真的很复杂,作为建议你可以使用适用于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>
In the invoicing module it has to affect the fields_view_get function, I understand that you want to hide the columns of the invoice product list so it must affect the account.invoice.line object:
在发票模块中,它必须影响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)
#2
0
In Odoo 8.0 I had to implement it a little bit others. It has the same logic in view but I had to use the fields_view_get method of sale.order and it is needed to load the order from its identifier:
在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
#1
0
Really complicated, as a suggestion you can use an attribute that applies in odoo 9:
真的很复杂,作为建议你可以使用适用于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>
In the invoicing module it has to affect the fields_view_get function, I understand that you want to hide the columns of the invoice product list so it must affect the account.invoice.line object:
在发票模块中,它必须影响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)
#2
0
In Odoo 8.0 I had to implement it a little bit others. It has the same logic in view but I had to use the fields_view_get method of sale.order and it is needed to load the order from its identifier:
在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