gpt4 book ai didi

python - 如何隐藏按钮 "Create invoice"但基于条件? (奥杜11)

转载 作者:太空宇宙 更新时间:2023-11-03 21:03:07 26 4
gpt4 key购买 nike

我确实被阻止了,我想隐藏“创建发票”按钮,但基于一个条件,我的条件是如果订单行有服务,则该按钮被隐藏。我创建了一个字段和一个函数,但最终总是出现模型中不存在该字段的错误,这是我的代码:

错误:

Field 'hide_invoice' used in attributes must be present in view but is missing

我的领域和职能(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>

最佳答案

您必须在标题级别显示字段才能处理这些。

就像在声明按钮之前执行以下代码一样。

<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>

关于python - 如何隐藏按钮 "Create invoice"但基于条件? (奥杜11),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55601894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com