我真的被阻止了,我想隐藏“创建发票”按钮,但根据条件,我的条件是,如果订单行有服务,则隐藏按钮。我创建了一个字段和一个函数,但最后总是出现模型中不存在该字段的错误,这是我的代码:
错误 :
属性中使用的字段“hide_invoice”必须存在于视图中但缺失
我的领域和功能(Python):
from odoo import api, fields, models,_
class SaleOrder(models.Model):
_inherit = 'sale.order'
hide_invoice = fields.Boolean(compute="_hide_button_invoice", string="",)
@api.multi
@api.depends('tasks_count')
def _hide_button_invoice(self):
for order in self:
if order.tasks_count > 0:
order.hide_invoice = True
elif order.tasks_count == 0:
order.hide_invoice = False
我的 XML(我在表单上看到它有效):
<odoo>
<record id="button_invoice_view_form" model="ir.ui.view">
<field name="name">sale.order.button.create.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="before">
<field name ="hide_invoice"/>
</xpath>
</field>
</record>
</odoo>
然后我想隐藏按钮:
<record id="sale_order_view_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='sale_pay']/field[@name='invoice_status']" position="attributes">
<attribute name="invisible" eval="False"/>
</xpath>
</xpath>
</field>
</record>
隔江千里
相关分类