This question has been flagged
1 Reply
4402 Views

Hi I am using Odoo 11.

I am customizing the account.invoice model, and i'd like to add a reference to stock.production.lot in the account invoice lines. In other words, when the user adds a product in the invoice, i'd like him to choose a corresponding lot number from the available ones.

So what I need is some sort of domain_filter in order to let the lot selectbox be filled only with those lots whose id_product equals the id_product of the invoice line. However, im not sure on what syntax to use...

My custom invoice line model:

class CustomInvoiceLine(models.Model):
    _inherit = 'account.invoice.line'
    _name = 'account.invoice.line'
    
    lot_id = fields.Many2one('stock.production.lot', string='Lotto',
        ondelete='restrict', index=True)

My view:

<odoo>
  <data> 
    <record id="custom_invoice_view" model="ir.ui.view">
    	<field name="name">custom.invoice.view</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']/tree[1]/field[@name='quantity']" position="before">      
                <field name="lot_id" domain = "???????"></field>  
        </xpath>
      </field>
    </record> 
  </data>
</odoo>

Thank you in advance,
Daniele


Avatar
Discard
Best Answer

Hi Daniele,

You just need to pass product_id of the invoice line in the domain in xml file.

Ex:

<field name="lot_id" domain="[('product_id', '=', product_id)]"

This way lot_id field will show the lots that have product which is selected in the invoice line.


Avatar
Discard
Author

Thank you very much, it works!

I suppose that 'product_id' in single quotes refers to the product_id of the field (lot), and the product_id without quotes refers to the product_id of the model itself (invoice line)?

Anyway, thank you again for your kind answer.

Daniele