1

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

1 Answers1

1

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 #')
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
  • Got another solution: intra_stat = fields.Many2one(related="product_id.intrastat_id", string='Intrastat #') But I'm curious - what do you mean by registering intrastat_id into product.product table? Something like this maybe: class Prd(models.Model): _inherit = 'product.product' intrastat_id = fields.Many2one(string="Intrastat") class AccountMove(models.Model): _inherit = 'account.move.line' product = fields.Many2one('product.product') intra_stat = fields.Many2one(related="product_product", string='Intrastat #') – Matija Amondi Oct 21 '22 at 05:44
  • I edited my answer for more clear example. And no need to add *product* field in *account.move.line* because it has already field called *product_id* If you read my answer carefully, it has same solution that I mentioned. – Bhavesh Odedra Oct 21 '22 at 06:13
  • Thank you Bhavesh, now I see it. – Matija Amondi Oct 21 '22 at 10:55