diff --git a/rma/models/rma_operation.py b/rma/models/rma_operation.py
index bd3d0f167..70290e0b9 100644
--- a/rma/models/rma_operation.py
+++ b/rma/models/rma_operation.py
@@ -94,3 +94,11 @@ def _default_routes(self):
required=True,
default=lambda self: self.env.user.company_id,
)
+ in_force_same_lot = fields.Boolean(
+ "Forces the same lot to be used "
+ "in outgoing pickings as the one indicated in the RMA"
+ )
+ out_force_same_lot = fields.Boolean(
+ "Forces the same lot to be used "
+ "in incoming pickings as the one indicated in the RMA"
+ )
diff --git a/rma/models/stock_move.py b/rma/models/stock_move.py
index 9a839f180..52cbf72fe 100644
--- a/rma/models/stock_move.py
+++ b/rma/models/stock_move.py
@@ -62,6 +62,7 @@ def _get_available_quantity(
not lot_id
and self.rma_line_id.lot_id
and self.location_id.usage == "internal"
+ and self.rma_line_id.operation_id.out_force_same_lot
):
# In supplier RMA deliveries we can only send the RMA lot/serial.
lot_id = self.rma_line_id.lot_id
@@ -88,6 +89,7 @@ def _update_reserved_quantity(
not lot_id
and self.rma_line_id.lot_id
and self.location_id.usage == "internal"
+ and self.rma_line_id.operation_id.out_force_same_lot
):
# In supplier RMA deliveries we can only send the RMA lot/serial.
lot_id = self.rma_line_id.lot_id
diff --git a/rma/views/rma_operation_view.xml b/rma/views/rma_operation_view.xml
index c2bb1b59e..08a00f286 100644
--- a/rma/views/rma_operation_view.xml
+++ b/rma/views/rma_operation_view.xml
@@ -53,6 +53,10 @@
name="customer_to_supplier"
attrs="{'invisible':[('type', '=', 'supplier')]}"
/>
+
@@ -61,6 +65,10 @@
name="supplier_to_customer"
attrs="{'invisible':[('type', '=', 'customer')]}"
/>
+
diff --git a/rma/wizards/rma_make_picking.py b/rma/wizards/rma_make_picking.py
index 0b92b1d85..657d6600d 100644
--- a/rma/wizards/rma_make_picking.py
+++ b/rma/wizards/rma_make_picking.py
@@ -210,48 +210,48 @@ def action_create_picking(self):
else:
pickings = self.mapped("item_ids.line_id")._get_in_pickings()
action = self.item_ids.line_id.action_view_in_shipments()
- if picking_type == "incoming":
- # Force the reservation of the RMA specific lot for incoming shipments.
- # FIXME: still needs fixing, not reserving appropriate serials.
- for move in pickings.move_ids.filtered(
- lambda x: x.state not in ("draft", "cancel", "done", "waiting")
- and x.rma_line_id
- and x.product_id.tracking in ("lot", "serial")
- and x.rma_line_id.lot_id
- ):
- # 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.move_line_ids.write(
- {
- "reserved_uom_qty": 1,
- "qty_done": 0,
- }
- )
- elif move.product_id.tracking == "lot":
- if picking_type == "incoming":
- qty = self.item_ids.filtered(
- lambda x: x.line_id.id == move.rma_line_id.id
- ).qty_to_receive
- else:
- qty = self.item_ids.filtered(
- lambda x: x.line_id.id == move.rma_line_id.id
- ).qty_to_deliver
- move_line_data = move._prepare_move_line_vals()
- move_line_data.update(
- {
- "lot_id": move.rma_line_id.lot_id.id,
- "product_uom_id": move.product_id.uom_id.id,
- "qty_done": 0,
- "reserved_uom_qty": qty,
- }
- )
- move_line_model.create(move_line_data)
+
+ for move in pickings.move_ids.filtered(
+ lambda x: x.state not in ("draft", "cancel", "done", "waiting")
+ and x.rma_line_id
+ and x.product_id.tracking in ("lot", "serial")
+ and x.rma_line_id.lot_id
+ and x.rma_line_id.operation_id.in_force_same_lot
+ and move.location_dest_id.usage == "internal"
+ ):
+ # Force the reservation of the RMA specific lot for incoming shipments if required.
+ 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.move_line_ids.write(
+ {
+ "reserved_uom_qty": 1,
+ "qty_done": 0,
+ }
+ )
+ elif move.product_id.tracking == "lot":
+ if picking_type == "incoming":
+ qty = self.item_ids.filtered(
+ lambda x: x.line_id.id == move.rma_line_id.id
+ ).qty_to_receive
+ else:
+ qty = self.item_ids.filtered(
+ lambda x: x.line_id.id == move.rma_line_id.id
+ ).qty_to_deliver
+ move_line_data = move._prepare_move_line_vals()
+ move_line_data.update(
+ {
+ "lot_id": move.rma_line_id.lot_id.id,
+ "product_uom_id": move.product_id.uom_id.id,
+ "qty_done": 0,
+ "reserved_uom_qty": qty,
+ }
+ )
+ move_line_model.create(move_line_data)
pickings.with_context(force_no_bypass_reservation=True).action_assign()
return action