From f8fc006e1e18bf965876bd0ad93ca251d86c7614 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 21 Jun 2018 09:05:21 +0200 Subject: [PATCH] [FIX] sale_mrp, sale_stock: sort moves `sorted` returns a new sorted recordset, but doesn't modify the actual one. Therefore, the current code doesn't work as expected. opw-1824734 --- addons/sale_mrp/sale_mrp.py | 5 +---- addons/sale_stock/models/account_invoice.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/addons/sale_mrp/sale_mrp.py b/addons/sale_mrp/sale_mrp.py index 56e769e1ac4..eef7d34349f 100644 --- a/addons/sale_mrp/sale_mrp.py +++ b/addons/sale_mrp/sale_mrp.py @@ -95,10 +95,7 @@ class AccountInvoiceLine(models.Model): qty_done = sum([x.uom_id._compute_quantity(x.quantity, x.product_id.uom_id) for x in s_line.invoice_lines if x.invoice_id.state in ('open', 'paid')]) quantity = self.uom_id._compute_quantity(self.quantity, self.product_id.uom_id) # Put moves in fixed order by date executed - moves = self.env['stock.move'] - for procurement in s_line.procurement_ids: - moves |= procurement.move_ids - moves.sorted(lambda x: x.date) + moves = s_line.mapped('procurement_ids.move_ids').sorted(lambda x: x.date) # Go through all the moves and do nothing until you get to qty_done # Beyond qty_done we need to calculate the average of the price_unit # on the moves we encounter. diff --git a/addons/sale_stock/models/account_invoice.py b/addons/sale_stock/models/account_invoice.py index 96f35cf5424..084ffbd3706 100644 --- a/addons/sale_stock/models/account_invoice.py +++ b/addons/sale_stock/models/account_invoice.py @@ -25,10 +25,7 @@ class AccountInvoiceLine(models.Model): qty_done = sum([x.uom_id._compute_quantity(x.quantity, x.product_id.uom_id) for x in s_line.invoice_lines if x.invoice_id.state in ('open', 'paid')]) quantity = self.uom_id._compute_quantity(self.quantity, self.product_id.uom_id) # Put moves in fixed order by date executed - moves = self.env['stock.move'] - for procurement in s_line.procurement_ids: - moves |= procurement.move_ids - moves.sorted(lambda x: x.date) + moves = s_line.mapped('procurement_ids.move_ids').sorted(lambda x: x.date) # Go through all the moves and do nothing until you get to qty_done # Beyond qty_done we need to calculate the average of the price_unit # on the moves we encounter.