Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
10062 Vizualizări

Hello all,

I'm adding a button on the sale invoices lines, in the form view of invoice.


See the button :

I want this new button invisible when the product on the sale invoice line has his field tracking = none.

But the debugger say to me that 'product_id.product_tmpl_id.tracking' is an unknown field...

I'm on a sale invoice line... to get the tracking value, I was sure that I was right. 

Don't understand, once again!

Please help!

Here is my view code :

<record id="invoice_form" model="ir.ui.view">
    <field name="name">account.invoice.form.inherit.vtm2</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="account.invoice_form" />
    <field name="arch" type="xml">
    <xpath expr="//field[@name='invoice_line_ids']//field[@name='discount']" position="after">
         <button name="split_lot" string="Lot Split" type="object" icon="fa-list" groups="stock.group_production_lot"
            attrs="{'invisible': [('product_id.product_tmpl_id.tracking', '=', 'none')]}"/>
    </xpath>
    </field>
</record>


Imagine profil
Abandonează

Hope this will helps

Cel mai bun răspuns

Hi,

While passing domain as strings on xml files, on the left hand side of condition you are supposed to give a field name and on the right side you can provide variables or strings. Try like this:

class AccountInvoiceLine(models.Model):
    _inherit = "account.invoice.line"
    
    tracking = fields.Selection(related='product_id.product_tmpl_id.tracking', String="Tracking")

And in the xml file:

<record id="invoice_form" model="ir.ui.view">    
    <field name="name">account.invoice.form.inherit.vtm2</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="account.invoice_form" />
    <field name="arch" type="xml">
         
        <xpath expr="//field[@name='invoice_line_ids']//field[@name='discount']" position="after">
            <field name="tracking" invisible="1" />
            <button name="split_lot" string="Lot Split" type="object" icon="fa-list" groups="stock.group_production_lot"
                 attrs="{'invisible': [('tracking', '=', 'none')]}"/>
        </xpath>
    </field>
</record>
Imagine profil
Abandonează
Autor

Your explanation is great! Your code is great. All your words are great! It is magic!

Autor

How do you explain the fact that we have to put the field 'tracking' (invisible) on the view? I have tried without this field on the view and it doesn't work. The view have to absolutely have this field on it?

Yes the field has to be present on the tree view, to use conditions based on that.

Because the field based on which you define the condition (domain to be sent to the server) needs to be present on the client-side