From 0aa2bc0acf36d9a8f857505da4081890307cc3e0 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 21 Jun 2018 09:12:00 +0200 Subject: [PATCH] [FIX] point_of_sale, 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/point_of_sale/models/pos_order.py | 6 ++++-- addons/sale_mrp/models/sale_mrp.py | 3 +-- addons/sale_stock/models/account_invoice.py | 4 +--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 00360ff1384..5c1b93285ee 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -417,8 +417,10 @@ class PosOrder(models.Model): def _get_pos_anglo_saxon_price_unit(self, product, partner_id, quantity): price_unit = product._get_anglo_saxon_price_unit() if product._get_invoice_policy() == "delivery": - moves = self.filtered(lambda o: o.partner_id.id == partner_id).mapped('picking_id.move_lines').filtered(lambda m: m.product_id.id == product.id) - moves.sorted(lambda x: x.date) + moves = self.filtered(lambda o: o.partner_id.id == partner_id)\ + .mapped('picking_id.move_lines')\ + .filtered(lambda m: m.product_id.id == product.id)\ + .sorted(lambda x: x.date) average_price_unit = product._compute_average_price(0, quantity, moves) price_unit = average_price_unit or price_unit # In the SO part, the entries will be inverted by function compute_invoice_totals diff --git a/addons/sale_mrp/models/sale_mrp.py b/addons/sale_mrp/models/sale_mrp.py index adbcebd4f18..5586d2742e6 100644 --- a/addons/sale_mrp/models/sale_mrp.py +++ b/addons/sale_mrp/models/sale_mrp.py @@ -62,8 +62,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 = s_line.move_ids - moves.sorted(lambda x: x.date) + moves = s_line.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 4bfe0e94ad3..dfe4ac8954d 100644 --- a/addons/sale_stock/models/account_invoice.py +++ b/addons/sale_stock/models/account_invoice.py @@ -25,9 +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'] - moves |= s_line.move_ids - moves.sorted(lambda x: x.date) + moves = s_line.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.