Skip to content

Commit

Permalink
[IMP] rma: Auto-calculate package for serial products
Browse files Browse the repository at this point in the history
When returning or delivering a serial product from a RMA, we will calculate by default its package. Later, it can be modyfied by the user.
  • Loading branch information
BernatPForgeFlow committed Aug 17, 2023
1 parent 3da8341 commit 3729b56
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions rma/wizards/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,49 +206,49 @@ 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_lines.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.
# FIXME: still needs fixing, not reserving appropriate serials.
for move in pickings.move_lines.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(
{
"product_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,
"product_uom_qty": qty,
}
)
move_line_model.create(move_line_data)

move.move_line_ids.unlink()
if move.product_id.tracking == "serial":
move.write(
{
"lot_ids": [(6, 0, move.rma_line_id.lot_id.ids)],
}
)
quant = self.env['stock.quant']._gather(move.product_id, move.location_id, lot_id=move.rma_line_id.lot_id)
move.move_line_ids.write(
{
"product_uom_qty": 1 if picking_type == "incoming" else 0,
"qty_done": 0,
"package_id": quant.package_id.id if quant.package_id else None,
}
)
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,
"product_uom_qty": qty if picking_type == "incoming" else 0,
}
)
move_line_model.create(move_line_data)
pickings.with_context(force_no_bypass_reservation=True).action_assign()
return action

Expand Down

0 comments on commit 3729b56

Please sign in to comment.