Skip to content

Commit

Permalink
[IMP] introduce fields in_force_same_lot and out_force_same_lot
Browse files Browse the repository at this point in the history
Those fields in the rma.operation allows us to control if we want to ensure that the
same lot as the one indicated in the RMA should be used in deliveries to customers
and receipts from suppliers
  • Loading branch information
JordiBForgeFlow committed Feb 27, 2024
1 parent 58349e4 commit 3a19fa4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 42 deletions.
4 changes: 4 additions & 0 deletions rma/data/rma_operation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<field name="type">customer</field>
<field name="in_route_id" ref="rma.route_rma_customer" />
<field name="out_route_id" ref="rma.route_rma_customer" />
<field name="in_force_same_lot">True</field>
<field name="out_force_same_lot">False</field>
</record>

<record id="rma_operation_supplier_replace" model="rma.operation">
Expand All @@ -18,6 +20,8 @@
<field name="type">supplier</field>
<field name="in_route_id" ref="rma.route_rma_supplier" />
<field name="out_route_id" ref="rma.route_rma_supplier" />
<field name="in_force_same_lot">False</field>
<field name="out_force_same_lot">True</field>
</record>

<record id="rma_operation_ds_replace" model="rma.operation">
Expand Down
10 changes: 10 additions & 0 deletions rma/models/rma_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,13 @@ def _default_routes(self):
required=True,
default=lambda self: self.env.user.company_id,
)
in_force_same_lot = fields.Boolean(
string="Force same lot in incoming shipments",
help="Forces the same lot to be used "
"in outgoing pickings as the one indicated in the RMA",
)
out_force_same_lot = fields.Boolean(
string="Force same lot in outgoing shipments",
help="Forces the same lot to be used "
"in incoming pickings as the one indicated in the RMA",
)
2 changes: 2 additions & 0 deletions rma/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions rma/views/rma_operation_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
name="customer_to_supplier"
attrs="{'invisible':[('type', '=', 'supplier')]}"
/>
<field
name="in_force_same_lot"
groups="stock.group_production_lot"
/>
</group>
<group name="outbound" string="Outbound">
<field name="out_route_id" />
Expand All @@ -61,6 +65,10 @@
name="supplier_to_customer"
attrs="{'invisible':[('type', '=', 'customer')]}"
/>
<field
name="out_force_same_lot"
groups="stock.group_production_lot"
/>
</group>
</group>
</sheet>
Expand Down
84 changes: 42 additions & 42 deletions rma/wizards/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 x.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
Expand Down
4 changes: 4 additions & 0 deletions rma_put_away/tests/test_rma_put_away.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def setUpClass(cls):
"put_away_location_id": cls.put_away_loc.id,
"in_route_id": cls.rma_route_cust.id,
"out_route_id": cls.rma_route_cust.id,
"out_force_same_lot": True,
"in_force_same_lot": True,
}
)
cls.operation_2 = cls.rma_op_obj.create(
Expand All @@ -97,6 +99,8 @@ def setUpClass(cls):
"put_away_location_id": cls.put_away_loc.id,
"in_route_id": cls.rma_route_cust.id,
"out_route_id": cls.rma_route_cust.id,
"out_force_same_lot": True,
"in_force_same_lot": True,
}
)

Expand Down

0 comments on commit 3a19fa4

Please sign in to comment.