From 88fdbfad45bbbbac17c5c36aceb9841f7eb8064a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Tue, 17 May 2011 15:35:31 +0200 Subject: [PATCH] Preserve order of sale line in invoice (transplanted from 41ec52ac100e4174ad9c94d59d8c856c4f3b612c) --- sale.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sale.py b/sale.py index 6d8a8b8b72..7122e77cee 100644 --- a/sale.py +++ b/sale.py @@ -705,7 +705,7 @@ class Sale(ModelWorkflow, ModelSQL, ModelView): :param sale: the BrowseRecord of the sale :param context: the context - :return: a dictionary with invoice line as key + :return: a dictionary with invoiced sale line id as key and a list of invoice lines values as value ''' line_obj = self.pool.get('sale.line') @@ -767,12 +767,14 @@ class Sale(ModelWorkflow, ModelSQL, ModelView): 'payment_term': sale.payment_term.id, }, context=ctx) - for line_id in invoice_lines: - for vals in invoice_lines[line_id]: + for line in sale.lines: + if line.id not in invoice_lines: + continue + for vals in invoice_lines[line.id]: vals['invoice'] = invoice_id invoice_line_id = invoice_line_obj.create(cursor, 0, vals, context=ctx) - sale_line_obj.write(cursor, user, line_id, { + sale_line_obj.write(cursor, user, line.id, { 'invoice_lines': [('add', invoice_line_id)], }, context=context)