mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX] rma
Avoid reserving units that are not available. Also ensures the lot picked is the correct one by adding a dependency to stock_move_forced_lot.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
"in odoo",
|
||||
"author": "ForgeFlow",
|
||||
"website": "https://github.com/ForgeFlow/stock-rma",
|
||||
"depends": ["stock", "mail", "web"],
|
||||
"depends": ["stock", "mail", "web", "stock_move_forced_lot"],
|
||||
"demo": ["demo/stock_demo.xml"],
|
||||
"data": [
|
||||
"security/rma.xml",
|
||||
|
||||
@@ -355,7 +355,9 @@ class TestRma(common.SavepointCase):
|
||||
).default_get([str(move.id), str(cls.partner_id.id)])
|
||||
data = wizard.with_user(
|
||||
cls.rma_basic_user
|
||||
)._prepare_rma_line_from_stock_move(move)
|
||||
)._prepare_rma_line_from_stock_move(
|
||||
move, lot=len(move.lot_ids) == 1 and move.lot_ids[0] or False
|
||||
)
|
||||
data["type"] = "supplier"
|
||||
if dropship:
|
||||
data.update(
|
||||
@@ -1361,3 +1363,87 @@ class TestRma(common.SavepointCase):
|
||||
mv.quantity_done = mv.product_uom_qty
|
||||
picking._action_done()
|
||||
self.assertEqual(picking.state, "done", "Final picking should has done state")
|
||||
|
||||
def test_12_move_reserving_correct_lot(self):
|
||||
lot1 = self.lot_obj.create(
|
||||
{
|
||||
"product_id": self.product_1_serial.id,
|
||||
"name": "LOT1",
|
||||
}
|
||||
)
|
||||
lot2 = self.lot_obj.create(
|
||||
{
|
||||
"product_id": self.product_1_serial.id,
|
||||
"name": "LOT2",
|
||||
}
|
||||
)
|
||||
products2move = [
|
||||
(
|
||||
self.product_1_serial,
|
||||
1,
|
||||
lot1.id,
|
||||
)
|
||||
]
|
||||
rma_supplier_id = self._create_rma_from_move(
|
||||
products2move,
|
||||
"supplier",
|
||||
self.env.ref("base.res_partner_2"),
|
||||
dropship=False,
|
||||
)
|
||||
rma = rma_supplier_id.rma_line_ids
|
||||
rma.action_rma_to_approve()
|
||||
wizard = self.rma_make_picking.with_context(
|
||||
{
|
||||
"active_ids": rma.ids,
|
||||
"active_model": "rma.order.line",
|
||||
"picking_type": "outgoing",
|
||||
"active_id": rma.ids[0],
|
||||
}
|
||||
).create({})
|
||||
wizard.action_create_picking()
|
||||
res = rma.action_view_out_shipments()
|
||||
self.assertTrue("res_id" in res, "Incorrect number of pickings" "created")
|
||||
picking = self.env["stock.picking"].browse(res["res_id"])
|
||||
self.assertEqual(len(picking), 1, "Incorrect number of pickings created")
|
||||
|
||||
quant_lot1 = self.env["stock.quant"].search(
|
||||
[
|
||||
("product_id", "=", self.product_1_serial.id),
|
||||
("lot_id", "=", lot1.id),
|
||||
("location_id", "=", self.stock_rma_location.id),
|
||||
]
|
||||
)
|
||||
quant_lot1.quantity = 0
|
||||
quant_lot2 = self.env["stock.quant"].search(
|
||||
[
|
||||
("product_id", "=", self.product_1_serial.id),
|
||||
("lot_id", "=", lot2.id),
|
||||
("location_id", "=", self.stock_rma_location.id),
|
||||
]
|
||||
)
|
||||
quant_lot2.quantity = 0
|
||||
moves = picking.move_lines
|
||||
self.assertFalse(
|
||||
moves.move_line_ids,
|
||||
"There should not be any move_line created (no quantity to reserve).",
|
||||
)
|
||||
picking.action_assign()
|
||||
self.assertFalse(
|
||||
moves.move_line_ids,
|
||||
"There should not be any move_line created (no quantity to reserve).",
|
||||
)
|
||||
quant_lot2.quantity = 1
|
||||
picking.action_assign()
|
||||
self.assertFalse(
|
||||
moves.move_line_ids,
|
||||
"There should not be any move_line created "
|
||||
"(no quantity to reserve for the lot of the rma).",
|
||||
)
|
||||
quant_lot1.quantity = 1
|
||||
picking.action_assign()
|
||||
self.assertTrue(moves.move_line_ids)
|
||||
self.assertEqual(moves.move_line_ids.lot_id, lot1)
|
||||
for mv in picking.move_lines.move_line_ids:
|
||||
mv.qty_done = mv.product_uom_qty
|
||||
picking._action_done()
|
||||
self.assertEqual(picking.state, "done", "Final picking should has done state")
|
||||
|
||||
@@ -133,6 +133,7 @@ class RmaMakePicking(models.TransientModel):
|
||||
"location_id": location,
|
||||
"rma_line_id": line.id,
|
||||
"route_ids": route,
|
||||
"lot_id": line.lot_id.id,
|
||||
}
|
||||
return procurement_data
|
||||
|
||||
@@ -216,13 +217,11 @@ class RmaMakePicking(models.TransientModel):
|
||||
move_line_model = self.env["stock.move.line"]
|
||||
picking_type = self.env.context.get("picking_type")
|
||||
if picking_type == "outgoing":
|
||||
pickings = self.mapped("item_ids.line_id")._get_out_pickings()
|
||||
action = self.item_ids.line_id.action_view_out_shipments()
|
||||
else:
|
||||
pickings = self.mapped("item_ids.line_id")._get_in_pickings()
|
||||
action = self.item_ids.line_id.action_view_in_shipments()
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user