Odoo Help


Invoice lines and sale order lines relation

on 11/10/13, 4:35 PM 7,327 views


probably a novice question but here it is.

I need to create a relation on each invoice line to its corresponding sale order line creating a new field on the invoice line form. (Just the same way that delivery out lines are related to sale orders lines). Is it possible to do this easily?.

Thanks in advance.



Jeudy Nicolas

--Jeudy Nicolas--

| 6 7 8
Pelousey, France
--Jeudy Nicolas--

- Linux administrator - Functional guy with OpenERP - Python, html, css, javascript developer OpenERP Ready Partner

Jeudy Nicolas
On 11/11/13, 6:17 PM


You already have this:

Look on the sale.order.line model.

image description

  • invoice_lines: list of invoice lines linked to this sale.order.line
  • invoiced : if this sale.order.line has been invoiced

You need the reversed one from account.invoice.line ? Add this to your account.invoice.line model (not tested but should works):

'sale_order_lines': fields.many2many('sale.order.line', 'sale_order_line_invoice_rel', 'invoice_id', 'order_line_id', 'Sale Order  Lines', readonly=True)
On 11/12/13, 9:57 AM

Hi Nicolas,

thank you very much for your kind response but this is not exactly what i needed.

I meant one to one relation for each object (invoice_line_id --> sale_order_line_id).



This is what i did (works for me but it's not very neat):

On account_invoice.py (account)

Add column in account_invoice_line:

'sale_order_line_id': fields.many2one('sale.order.line', 'Sales Order Line', help='Sale Order Line'),

On sale.py (sale)

Add column on _prepare_order_line_invoice_line function:

‘sale_order_line_id’: line.id,

That's it.


That's what Nicolas posted. sale_order_line_invoice_rel is what relate them. Of course it's not a 1:1 relation. It's a N:N relation.

GH Mediacloud, Grover Menacho
on 11/12/13, 10:04 AM

Yes the rel between sale.order.line and account.invoice.line is not 1:1 by default, but you have the same behaviour as you need. If it works for you ok ,but I think it should be a many2many field as it is.

Tuxservices, Jeudy Nicolas
on 11/12/13, 12:18 PM

I change a typo error on my response.. if you look on the first record ou sale_order_lines (sale_order_lines[0]) you will find your record.

Tuxservices, Jeudy Nicolas
on 11/12/13, 12:21 PM

OK, thank you very much Nicolas.

on 11/12/13, 12:25 PM

No prob. Can you make your question as answered and check the good answer ?

Tuxservices, Jeudy Nicolas
on 11/12/13, 12:49 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/10/13, 4:35 PM
Seen: 7327 times
Last updated: 2/25/18, 6:31 AM