[FIX] sale: invoice multiple SO: right sequence

Have sections order lines on each Sale Order
Have multiple Sale Orders on which the action "invoice order" is triggered
(to make one invoice for all of them)

Before this commit, the real invoice lines were not under their respective
section line
This was because we kept the sequence of the order line when making the order line
which makes little sense in a case where we merge the orders

After this commit, the invoice lines are under their respective section

OPW 1985080

closes odoo/odoo#33219

Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2019-05-07 12:50:52 +00:00
parent 2ff0ebd63b
commit 6368971ba0
+15 -4
View File
@@ -516,6 +516,9 @@ class SaleOrder(models.Model):
invoices_origin = {}
invoices_name = {}
# Keep track of the sequences of the lines
# To keep lines under their section
inv_line_sequence = 0
for order in self:
group_key = order.id if grouped else (order.partner_invoice_id.id, order.currency_id.id)
@@ -524,6 +527,7 @@ class SaleOrder(models.Model):
# Create lines in batch to avoid performance problems
line_vals_list = []
# sequence is the natural order of order_lines
for line in order.order_line:
if line.display_type == 'line_section':
pending_section = line
@@ -545,14 +549,21 @@ class SaleOrder(models.Model):
if line.qty_to_invoice > 0 or (line.qty_to_invoice < 0 and final):
if pending_section:
line_vals_list.extend(pending_section.invoice_line_create_vals(
section_invoice = pending_section.invoice_line_create_vals(
invoices[group_key].id,
pending_section.qty_to_invoice
))
)
inv_line_sequence += 1
section_invoice[0]['sequence'] = inv_line_sequence
line_vals_list.extend(section_invoice)
pending_section = None
line_vals_list.extend(line.invoice_line_create_vals(
inv_line_sequence += 1
inv_line = line.invoice_line_create_vals(
invoices[group_key].id, line.qty_to_invoice
))
)
inv_line[0]['sequence'] = inv_line_sequence
line_vals_list.extend(inv_line)
if references.get(invoices.get(group_key)):
if order not in references[invoices[group_key]]: