确实有我被阻止,我想隐藏“创建发票”按钮,但是根据条件,我的条件是如果订单行中有服务,则该按钮是隐藏的。我创建了一个字段和一个函数,但是最后总是出现一个错误,即该字段在模型中不存在,这是我的代码:
错误:
属性中使用的字段“ 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 expr="//button[@name='action_quotation_send']" position="before">
<button name="%(sale.action_view_sale_advance_payment_inv)d" string="Create Invoice"
type="action" class="btn-primary"
attrs="{'invisible': [('invoice_status', '!=', 'to invoice')]}"/>
<button name="%(sale.action_view_sale_advance_payment_inv)d" string="Create Invoice"
type="action" context="{'default_advance_payment_method': 'percentage'}"
attrs="{'invisible': ['|','|',('hide_invoice', '=', True),('invoice_status', '!=', 'no'), ('state', '!=', 'sale')]}"/>
</xpath>
</field>
</record>
答案 0 :(得分:0)
您必须在标题级别显示字段以处理这些问题。
就像在声明按钮之前执行以下代码一样。
<field name='hide_invoice' invisible='1'/>
并在partner_id字段之前将其删除。
编辑
您可以尝试使用以下xml代码吗?
<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 expr="//button[@name='action_quotation_send']" position="before">
<button name="%(sale.action_view_sale_advance_payment_inv)d" string="Create Invoice"
type="action" class="btn-primary"
attrs="{'invisible': [('invoice_status', '!=', 'to invoice')]}"/>
<field name="hide_invoice" invisible="1"/>
<button name="%(sale.action_view_sale_advance_payment_inv)d" string="Create Invoice"
type="action" context="{'default_advance_payment_method': 'percentage'}"
attrs="{'invisible': ['|','|',('hide_invoice', '=', True),('invoice_status', '!=', 'no'), ('state', '!=', 'sale')]}"/>
</xpath>
</field>
</record>