Skip to content

Commit 1c6969d

Browse files
committed
Revert "[FIX] sale_stock_return_request: Fix tests"
This reverts commit 4ccc3fa. Related to OCA/stock-logistics-request#85 (comment)
1 parent 2669512 commit 1c6969d

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

sale_stock_return_request/tests/test_stock_return_request.py

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Copyright 2019 Tecnativa - David Vidal
2-
# Copyright 2025 Tecnativa - Pedro M. Baeza
32
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
43

54
from odoo import Command
@@ -54,27 +53,48 @@ def setUpClass(cls):
5453
# Confirm all the sale orders
5554
for order in cls.sale_orders:
5655
order.action_confirm()
56+
# Adjust quants to avoid reservation quircks
57+
quant_lot_1 = cls.env["stock.quant"].search(
58+
[
59+
("product_id", "=", cls.prod_3.id),
60+
("lot_id", "=", cls.prod_3_lot1.id),
61+
("location_id", "=", cls.wh1.lot_stock_id.id),
62+
]
63+
)
64+
quant_lot_2 = cls.env["stock.quant"].search(
65+
[
66+
("product_id", "=", cls.prod_3.id),
67+
("lot_id", "=", cls.prod_3_lot2.id),
68+
("location_id", "=", cls.wh1.lot_stock_id.id),
69+
]
70+
)
71+
quant_lot_1.reserved_quantity = 90.0
72+
quant_lot_2.reserved_quantity = 10.0
5773
# Deliver products. For each picking:
58-
# 10 units of TSTPROD3LOT0001 -> -20 units of 70 already existing
59-
# 4 units of TSTPROD3LOT0002 -> -8 units of 0 already existing
74+
# 10 units of TSTPROD3LOT0001 -> -20 units of 90 already existing
75+
# 2 units of TSTPROD3LOT0002 -> -4 units of 10 already existing
6076
for picking in cls.sale_orders.mapped("picking_ids"):
61-
picking.move_line_ids.unlink()
62-
move = picking.move_ids
63-
vals = {
64-
"move_id": move.id,
65-
"picking_id": picking.id,
66-
"location_id": move.location_id.id,
67-
"location_dest_id": move.location_dest_id.id,
68-
"product_uom_id": move.product_uom.id,
69-
"product_id": move.product_id.id,
70-
"lot_id": cls.prod_3_lot1.id,
71-
"quantity": 10.0,
72-
}
73-
cls.env["stock.move.line"].create(vals)
74-
vals["lot_id"] = cls.prod_3_lot2.id
75-
vals["quantity"] = 4
76-
cls.env["stock.move.line"].create(vals)
77+
for ml in picking.move_line_ids:
78+
ml.write(
79+
{
80+
"lot_id": cls.prod_3_lot1.id,
81+
"quantity": 10.0,
82+
}
83+
)
84+
ml.create(
85+
{
86+
"move_id": ml.move_id.id,
87+
"picking_id": ml.picking_id.id,
88+
"location_id": ml.location_id.id,
89+
"location_dest_id": ml.location_dest_id.id,
90+
"product_uom_id": ml.product_uom_id.id,
91+
"product_id": cls.prod_3.id,
92+
"lot_id": cls.prod_3_lot2.id,
93+
"quantity": 4.0,
94+
}
95+
)
7796
picking.button_validate()
97+
quant_lot_1.reserved_quantity = quant_lot_2.reserved_quantity = 0.0
7898

7999
def test_01_return_sale_stock_from_customer(self):
80100
"""Return stock from customer and the corresponding
@@ -120,16 +140,16 @@ def test_01_return_sale_stock_from_customer(self):
120140
self.assertTrue(
121141
all([True if x == "done" else False for x in pickings.mapped("state")])
122142
)
123-
# For lot TSTPROD3LOT0001 we had 50 units
143+
# For lot TSTPROD3LOT0001 we had 70 units
124144
prod_3_qty_lot_1 = self.prod_3.with_context(
125145
location=self.wh1.lot_stock_id.id, lot_id=self.prod_3_lot1.id
126146
).qty_available
127-
# For lot TSTPROD3LOT0002 we had -8 units
147+
# For lot TSTPROD3LOT0002 we had 2 units
128148
prod_3_qty_lot_2 = self.prod_3.with_context(
129149
location=self.wh1.lot_stock_id.id, lot_id=self.prod_3_lot2.id
130150
).qty_available
131-
self.assertAlmostEqual(prod_3_qty_lot_1, 62.0)
132-
self.assertAlmostEqual(prod_3_qty_lot_2, -4.0)
151+
self.assertAlmostEqual(prod_3_qty_lot_1, 82.0)
152+
self.assertAlmostEqual(prod_3_qty_lot_2, 6.0)
133153
# There were 28 units in the sale orders.
134154
self.assertAlmostEqual(
135155
sum(sale_orders.mapped("order_line.qty_delivered")), 12.0

0 commit comments

Comments
 (0)