From 0c4bc1cf72d69110246fd133f6c9f55245fa3bd0 Mon Sep 17 00:00:00 2001
From: Martin Trigaux <mat@openerp.com>
Date: Tue, 3 Jun 2014 16:56:07 +0200
Subject: [PATCH] [FIX] sale: keep customer reference in grouped invoice (opw
 606523)

---
 addons/sale/sale.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 364ca36b1c2e..af62b014c053 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -525,14 +525,18 @@ class sale_order(osv.osv):
             if grouped:
                 res = self._make_invoice(cr, uid, val[0][0], reduce(lambda x, y: x + y, [l for o, l in val], []), context=context)
                 invoice_ref = ''
+                origin_ref = ''
                 for o, l in val:
-                    invoice_ref += o.name + '|'
+                    invoice_ref += (o.client_order_ref or o.name) + '|'
+                    origin_ref += (o.origin or o.name) + '|'
                     self.write(cr, uid, [o.id], {'state': 'progress'})
                     cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (o.id, res))
                 #remove last '|' in invoice_ref
-                if len(invoice_ref) >= 1: 
+                if len(invoice_ref) >= 1:
                     invoice_ref = invoice_ref[:-1]
-                invoice.write(cr, uid, [res], {'origin': invoice_ref, 'name': invoice_ref})
+                if len(origin_ref) >= 1:
+                    origin_ref = origin_ref[:-1]
+                invoice.write(cr, uid, [res], {'origin': origin_ref, 'name': invoice_ref})
             else:
                 for order, il in val:
                     res = self._make_invoice(cr, uid, order, il, context=context)
-- 
GitLab