[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
This commit is contained in:
committed by
Goffin Simon
parent
4e5119c6e5
commit
468e2e454e
+11
-5
@@ -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.'))
|
||||
|
||||
Reference in New Issue
Block a user