Search code examples
odoo-15

Show related field from product template on account move


I'd like to show intrastat_id field that is on product form in account move (when creating invoices)

I'm inheriting it like this

class ProductTemplate(models.Model):
    _inherit = 'account.move.line'
 
product_template_id = fields.Many2one('product.template')
intra_stat = fields.Many2one(related="product_template_id.intrastat_id", string='Intrastat #')

It shows nothing - blank field in lines. What am I doing wrong? I double checked if Intrastat (commodity code) is set on product.

enter image description here


Solution

  • It seems your product_template_id field value is False. account.move.line has product_id field which auto set during stock journal entry creation.

    In your case, you should remove the product.template table approach and focus on product.product table.

    Also do not forget to register intrastat_id into product.product table if you don't already declared.

    For example: Declare following field in the account.move.line object:

    intra_stat = fields.Many2one(related="product_id.intrastat_id", string='Intrastat #')