diff --git a/rma/models/stock_move.py b/rma/models/stock_move.py index c17b0170..886f095e 100644 --- a/rma/models/stock_move.py +++ b/rma/models/stock_move.py @@ -104,3 +104,34 @@ class StockMove(models.Model): def _prepare_merge_moves_distinct_fields(self): res = super()._prepare_merge_moves_distinct_fields() return res + ["rma_line_id"] + + def _set_lot_ids(self, lot_ids): + lots = self.env["stock.move"].browse(lot_ids) + self.ensure_one() + for move in self: + if move.product_id.tracking != "serial": + continue + move_lines_commands = [] + if move.picking_type_id.show_reserved is False: + mls = move.move_line_nosuggest_ids + else: + mls = move.move_line_ids + mls = mls.filtered(lambda ml: ml.lot_id) + for ml in mls: + if ml.qty_done and ml.lot_id not in lots: + move_lines_commands.append((2, ml.id)) + ls = move.move_line_ids.lot_id + for lot in lots: + if lot not in ls: + move_line_vals = self._prepare_move_line_vals(quantity=0) + move_line_vals["lot_id"] = lot.id + move_line_vals["lot_name"] = lot.name + move_line_vals["product_uom_id"] = move.product_id.uom_id.id + move_line_vals["qty_done"] = 1 + move_lines_commands.append((0, 0, move_line_vals)) + else: + move_line = move.move_line_ids.filtered( + lambda line: line.lot_id.id == lot.id + ) + move_line.qty_done = 1 + move.write({"move_line_ids": move_lines_commands}) diff --git a/rma/wizards/rma_make_picking.py b/rma/wizards/rma_make_picking.py index 2c459e4c..1848a0bb 100644 --- a/rma/wizards/rma_make_picking.py +++ b/rma/wizards/rma_make_picking.py @@ -209,7 +209,7 @@ class RmaMakePicking(models.TransientModel): # Force the reservation of the RMA specific lot for incoming shipments. move.move_line_ids.unlink() if move.product_id.tracking == "serial": - move.write({"lot_ids": [(6, 0, move.rma_line_id.lot_id.ids)]}) + move._set_lot_ids(move.rma_line_id.lot_id.ids) move.move_line_ids.write({"product_uom_qty": 1, "qty_done": 0}) elif move.product_id.tracking == "lot": if picking_type == "incoming":