From 468e2e454e1ad5b7a3fe02e50cd7920d63319581 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 3 May 2018 16:37:36 +0200 Subject: [PATCH] [FIX] sale: creating invoice name from SO ref Steps to reproduce the bug: - Create a SO with 2 lines and confirm it - Set a Customer reference on the SO with "This is, a ref" - Deliver it - Create an invoice from it with all the invoicable lines Bug: The name of the invoice was: "This is, a ref, This is, a ref" Expected behavior: The name of the invoice is: "This is, a ref" opw:1840738 --- addons/sale/sale.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 020219a7e8c..62b1598db66 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -311,6 +311,8 @@ class SaleOrder(models.Model): inv_obj = self.env['account.invoice'] precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') invoices = {} + invoices_origin = {} + invoices_name = {} for order in self: group_key = order.id if grouped else (order.partner_invoice_id.id, order.currency_id.id) @@ -321,17 +323,21 @@ class SaleOrder(models.Model): inv_data = order._prepare_invoice() invoice = inv_obj.create(inv_data) invoices[group_key] = invoice + invoices_origin[group_key] = [invoice.origin] + invoices_name[group_key] = [invoice.name] elif group_key in invoices: vals = {} - if order.name not in invoices[group_key].origin.split(', '): - vals['origin'] = invoices[group_key].origin + ', ' + order.name - if order.client_order_ref and order.client_order_ref not in invoices[group_key].name.split(', '): - vals['name'] = invoices[group_key].name + ', ' + order.client_order_ref - invoices[group_key].write(vals) + if order.name not in invoices_origin[group_key]: + invoices_origin[group_key].append(order.name) + if order.client_order_ref and order.client_order_ref not in invoices_name[group_key]: + invoices_name[group_key].append(order.client_order_ref) if line.qty_to_invoice > 0: line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice) elif line.qty_to_invoice < 0 and final: line.invoice_line_create(invoices[group_key].id, line.qty_to_invoice) + for group_key in invoices: + invoices[group_key].write({'name': ', '.join(invoices_name[group_key]), + 'origin': ', '.join(invoices_origin[group_key])}) if not invoices: raise UserError(_('There is no invoicable line.'))