[IMP] rma: Auto-calculate package for serial products

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.
This commit is contained in:
BernatPForgeFlow
2023-08-17 12:38:57 +02:00
committed by JasminSForgeFlow
parent b796ffdfc1
commit 24d83b966c

View File

@@ -211,49 +211,51 @@ class RmaMakePicking(models.TransientModel):
else: else:
pickings = self.mapped("item_ids.line_id")._get_in_pickings() pickings = self.mapped("item_ids.line_id")._get_in_pickings()
action = self.item_ids.line_id.action_view_in_shipments() 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. # Force the reservation of the RMA specific lot for incoming shipments.
# FIXME: still needs fixing, not reserving appropriate serials. move.move_line_ids.unlink()
for move in pickings.move_ids.filtered( if move.product_id.tracking == "serial":
lambda x: x.state not in ("draft", "cancel", "done", "waiting") move.write(
and x.rma_line_id {
and x.product_id.tracking in ("lot", "serial") "lot_ids": [(6, 0, move.rma_line_id.lot_id.ids)],
and x.rma_line_id.lot_id }
): )
# Force the reservation of the RMA specific lot for incoming shipments. quant = self.env["stock.quant"]._gather(
move.move_line_ids.unlink() move.product_id, move.location_id, lot_id=move.rma_line_id.lot_id
if move.product_id.tracking == "serial": )
move.write( move.move_line_ids.write(
{ {
"lot_ids": [(6, 0, move.rma_line_id.lot_id.ids)], "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,
move.move_line_ids.write( }
{ )
"quantity": 0, elif move.product_id.tracking == "lot":
} if picking_type == "incoming":
) qty = self.item_ids.filtered(
elif move.product_id.tracking == "lot": lambda x: x.line_id.id == move.rma_line_id.id
if picking_type == "incoming": ).qty_to_receive
qty = self.item_ids.filtered( else:
lambda x, move_rma_line_id=move.rma_line_id: x.line_id.id qty = self.item_ids.filtered(
== move_rma_line_id.id lambda x: x.line_id.id == move.rma_line_id.id
).qty_to_receive ).qty_to_deliver
else: move_line_data = move._prepare_move_line_vals()
qty = self.item_ids.filtered( move_line_data.update(
lambda x, move_rma_line_id=move.rma_line_id: x.line_id.id {
== move_rma_line_id.id "lot_id": move.rma_line_id.lot_id.id,
).qty_to_deliver "product_uom_id": move.product_id.uom_id.id,
move_line_data = move._prepare_move_line_vals() "qty_done": 0,
move_line_data.update( "product_uom_qty": qty if picking_type == "incoming" else 0,
{ }
"lot_id": move.rma_line_id.lot_id.id, )
"product_uom_id": move.product_id.uom_id.id, move_line_model.create(move_line_data)
"quantity": qty,
}
)
move_line_model.create(move_line_data)
pickings.with_context(force_no_bypass_reservation=True).action_assign() pickings.with_context(force_no_bypass_reservation=True).action_assign()
return action return action