[MERGE] forward port branch 9.0 up to 468e2e454e
This commit is contained in:
@@ -334,6 +334,9 @@ class SaleOrder(models.Model):
|
||||
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
|
||||
invoices = {}
|
||||
references = {}
|
||||
invoices_origin = {}
|
||||
invoices_name = {}
|
||||
|
||||
for order in self:
|
||||
group_key = order.id if grouped else (order.partner_invoice_id.id, order.currency_id.id)
|
||||
for line in order.order_line.sorted(key=lambda l: l.qty_to_invoice < 0):
|
||||
@@ -344,13 +347,14 @@ class SaleOrder(models.Model):
|
||||
invoice = inv_obj.create(inv_data)
|
||||
references[invoice] = order
|
||||
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(', ') and order.client_order_ref != invoices[group_key].name:
|
||||
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:
|
||||
@@ -360,6 +364,10 @@ class SaleOrder(models.Model):
|
||||
if order not in references[invoices[group_key]]:
|
||||
references[invoice] = references[invoice] | order
|
||||
|
||||
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