From ad31097d8e136fffbee9f7a00080cea0f637dc83 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Fri, 27 Sep 2019 14:11:25 +0000 Subject: [PATCH] [FIX] stock, delivery: put in pack and discard rev[0] writes the qty done on the move lines directly in put_in_pack, meaning hitting discard in the delivery wizard left the move lines with a changed qty_done. We fix that by editing the quantities in _put_in_pack in the stock module and getting the right move lines in the delivery modules: meaning, get the normal or suggested ones (a fix missed by rev[1]) then with quantities or 0 quantities. [0] e03c1a836f2d1dd0ffad27df75fc4779fd1368de [1] f6d88a2e8dedec2362868fe72763284a065b0e61 closes odoo/odoo#37563 Signed-off-by: Simon Lejeune (sle) --- addons/delivery/wizard/choose_delivery_package.py | 11 ++++++++++- addons/stock/models/stock_picking.py | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/delivery/wizard/choose_delivery_package.py b/addons/delivery/wizard/choose_delivery_package.py index 04b03e3f501..8c54c7e130a 100644 --- a/addons/delivery/wizard/choose_delivery_package.py +++ b/addons/delivery/wizard/choose_delivery_package.py @@ -43,10 +43,19 @@ class ChooseDeliveryPackage(models.TransientModel): return {'warning': warning_mess} def put_in_pack(self): - move_line_ids = self.picking_id.move_line_ids.filtered(lambda ml: + picking_move_lines = self.picking_id.move_line_ids + if not self.picking_id.picking_type_id.show_reserved: + picking_move_lines = self.picking_id.move_line_nosuggest_ids + + move_line_ids = picking_move_lines.filtered(lambda ml: float_compare(ml.qty_done, 0.0, precision_rounding=ml.product_uom_id.rounding) > 0 and not ml.result_package_id ) + if not move_line_ids: + move_line_ids = picking_move_lines.filtered(lambda ml: float_compare(ml.product_uom_qty, 0.0, + precision_rounding=ml.product_uom_id.rounding) > 0 and float_compare(ml.qty_done, 0.0, + precision_rounding=ml.product_uom_id.rounding) == 0) + delivery_package = self.picking_id._put_in_pack(move_line_ids) # write shipping weight and product_packaging on 'stock_quant_package' if needed if self.delivery_packaging_id: diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index bf8b4d61160..79a4efb5a8d 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -1143,6 +1143,12 @@ class Picking(models.Model): for pick in self: move_lines_to_pack = self.env['stock.move.line'] package = self.env['stock.quant.package'].create({}) + + precision_digits = self.env['decimal.precision'].precision_get('Product Unit of Measure') + if float_is_zero(move_line_ids[0].qty_done, precision_digits=precision_digits): + for line in move_line_ids: + line.qty_done = line.product_uom_qty + for ml in move_line_ids: if float_compare(ml.qty_done, ml.product_uom_qty, precision_rounding=ml.product_uom_id.rounding) >= 0: @@ -1186,8 +1192,6 @@ class Picking(models.Model): move_line_ids = picking_move_lines.filtered(lambda ml: float_compare(ml.product_uom_qty, 0.0, precision_rounding=ml.product_uom_id.rounding) > 0 and float_compare(ml.qty_done, 0.0, precision_rounding=ml.product_uom_id.rounding) == 0) - for line in move_line_ids: - line.qty_done = line.product_uom_qty if move_line_ids: res = self._pre_put_in_pack_hook(move_line_ids) if not res: