如何隐藏按钮“创建发票”但基于条件?(Odoo 11)

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


错误 :


属性中使用的字段“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>


翻阅古今
浏览 144回答 1
1回答

隔江千里

您必须在标题级别显示字段来处理这些。就像在声明按钮之前执行以下代码一样。<field name='hide_invoice' invisible='1'/>并将其删除在 partner_id 字段之前。编辑您可以尝试使用以下 xml 代码:<record id="sale_order_view_form" model="ir.ui.view">&nbsp; &nbsp; <field name="name">sale.order.form</field>&nbsp; &nbsp; <field name="model">sale.order</field>&nbsp; &nbsp; <field name="inherit_id" ref="sale.view_order_form"/>&nbsp; &nbsp; <field name="arch" type="xml">&nbsp; &nbsp; &nbsp; &nbsp; <xpath expr="//group[@name='sale_pay']/field[@name='invoice_status']" position="attributes">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <attribute name="invisible" eval="False"/>&nbsp; &nbsp; &nbsp; &nbsp; </xpath>&nbsp; &nbsp; &nbsp; &nbsp; <xpath expr="//button[@name='action_quotation_send']" position="before">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button name="%(sale.action_view_sale_advance_payment_inv)d" string="Create Invoice"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type="action" class="btn-primary"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attrs="{'invisible': [('invoice_status', '!=', 'to invoice')]}"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <field name="hide_invoice" invisible="1"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button name="%(sale.action_view_sale_advance_payment_inv)d" string="Create Invoice"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type="action" context="{'default_advance_payment_method': 'percentage'}"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attrs="{'invisible': ['|','|',('hide_invoice', '=', True),('invoice_status', '!=', 'no'), ('state', '!=', 'sale')]}"/>&nbsp; &nbsp; &nbsp; &nbsp; </xpath>&nbsp; &nbsp; </field></record>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python