Skip to content

Commit 4ccc3fa

Browse files
committed
[FIX] sale_stock_return_request: Fix tests
Previously, they were tricking how stock works, and an update over Odoo has revealed the trick, so let's do things properly, adjusting the method to do the deliveries, and changing quantities to the proper ones. Fixes OCA#3936
1 parent b5ad198 commit 4ccc3fa

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

sale_stock_return_request/tests/test_stock_return_request.py

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

45
from odoo import Command
@@ -53,48 +54,27 @@ def setUpClass(cls):
5354
# Confirm all the sale orders
5455
for order in cls.sale_orders:
5556
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
7357
# Deliver products. For each picking:
74-
# 10 units of TSTPROD3LOT0001 -> -20 units of 90 already existing
75-
# 2 units of TSTPROD3LOT0002 -> -4 units of 10 already existing
58+
# 10 units of TSTPROD3LOT0001 -> -20 units of 70 already existing
59+
# 4 units of TSTPROD3LOT0002 -> -8 units of 0 already existing
7660
for picking in cls.sale_orders.mapped("picking_ids"):
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-
)
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)
9677
picking.button_validate()
97-
quant_lot_1.reserved_quantity = quant_lot_2.reserved_quantity = 0.0
9878

9979
def test_01_return_sale_stock_from_customer(self):
10080
"""Return stock from customer and the corresponding
@@ -140,16 +120,16 @@ def test_01_return_sale_stock_from_customer(self):
140120
self.assertTrue(
141121
all([True if x == "done" else False for x in pickings.mapped("state")])
142122
)
143-
# For lot TSTPROD3LOT0001 we had 70 units
123+
# For lot TSTPROD3LOT0001 we had 50 units
144124
prod_3_qty_lot_1 = self.prod_3.with_context(
145125
location=self.wh1.lot_stock_id.id, lot_id=self.prod_3_lot1.id
146126
).qty_available
147-
# For lot TSTPROD3LOT0002 we had 2 units
127+
# For lot TSTPROD3LOT0002 we had -8 units
148128
prod_3_qty_lot_2 = self.prod_3.with_context(
149129
location=self.wh1.lot_stock_id.id, lot_id=self.prod_3_lot2.id
150130
).qty_available
151-
self.assertAlmostEqual(prod_3_qty_lot_1, 82.0)
152-
self.assertAlmostEqual(prod_3_qty_lot_2, 6.0)
131+
self.assertAlmostEqual(prod_3_qty_lot_1, 62.0)
132+
self.assertAlmostEqual(prod_3_qty_lot_2, -4.0)
153133
# There were 28 units in the sale orders.
154134
self.assertAlmostEqual(
155135
sum(sale_orders.mapped("order_line.qty_delivered")), 12.0

0 commit comments

Comments
 (0)