Condition to display a header button only after a customer have been saved

62 views Asked by At

I have tried so many ways to display "Offer Letter" button only when a customer is saved. But it seems i am not getting the condition right here:

<xpath expr="//form/*" position="before">
                    <header>
                        <button name="offer_letter" string="Offer Letter" type="object" class="oe_highlight"
                                attrs="{'invisible':[('what condition?')]}"/>
                    </header>
                </xpath>

Below is my code snippet:

The Model:

class res_partner(models.Model):
    _inherit = 'res.partner'

    baf = fields.Boolean("Application Form", help="Specify customer who bought application form")

    @api.multi
    def offer_letter_method(self):
        return self.env['report'].get_action(self, 'sales_custom.offer_letter_view')

The View:

<record model="ir.ui.view" id="customer_custom_form_view">
            <field name="name">customer.custom</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <xpath expr="//form/*" position="before">
                    <header>
                        <button name="offer_letter" string="Offer Letter" type="object" class="oe_highlight"
                                attrs="{'invisible':[('what condition?')]}"/>
                    </header>
                </xpath>
                <xpath expr="//field[@name='name']" position="after">
                    <field name="baf"/>
                    <label for="baf"/>
                </xpath>
            </field>
        </record>

Kindly assist.

1

There are 1 answers

0
Emipro Technologies Pvt. Ltd. On BEST ANSWER

You should try as following :

<record model="ir.ui.view" id="customer_custom_form_view">
    <field name="name">customer.custom</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <xpath expr="//form/*" position="before">
            <header>
                <button name="offer_letter" string="Offer Letter" type="object" class="oe_highlight"
                        attrs="{'invisible':[('id','=',False)]}"/>
                       <field name="id" invisible="1"/>
            </header>
        </xpath>
        <xpath expr="//field[@name='name']" position="after">
            <field name="baf"/>
            <label for="baf"/>
        </xpath>
    </field>
</record>