|
1 | 1 | # Copyright 2019 Tecnativa - David Vidal |
| 2 | +# Copyright 2025 Tecnativa - Pedro M. Baeza |
2 | 3 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
3 | 4 |
|
4 | 5 | from odoo import Command |
@@ -53,48 +54,27 @@ def setUpClass(cls): |
53 | 54 | # Confirm all the sale orders |
54 | 55 | for order in cls.sale_orders: |
55 | 56 | 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 |
73 | 57 | # 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 |
76 | 60 | 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) |
96 | 77 | picking.button_validate() |
97 | | - quant_lot_1.reserved_quantity = quant_lot_2.reserved_quantity = 0.0 |
98 | 78 |
|
99 | 79 | def test_01_return_sale_stock_from_customer(self): |
100 | 80 | """Return stock from customer and the corresponding |
@@ -140,16 +120,16 @@ def test_01_return_sale_stock_from_customer(self): |
140 | 120 | self.assertTrue( |
141 | 121 | all([True if x == "done" else False for x in pickings.mapped("state")]) |
142 | 122 | ) |
143 | | - # For lot TSTPROD3LOT0001 we had 70 units |
| 123 | + # For lot TSTPROD3LOT0001 we had 50 units |
144 | 124 | prod_3_qty_lot_1 = self.prod_3.with_context( |
145 | 125 | location=self.wh1.lot_stock_id.id, lot_id=self.prod_3_lot1.id |
146 | 126 | ).qty_available |
147 | | - # For lot TSTPROD3LOT0002 we had 2 units |
| 127 | + # For lot TSTPROD3LOT0002 we had -8 units |
148 | 128 | prod_3_qty_lot_2 = self.prod_3.with_context( |
149 | 129 | location=self.wh1.lot_stock_id.id, lot_id=self.prod_3_lot2.id |
150 | 130 | ).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) |
153 | 133 | # There were 28 units in the sale orders. |
154 | 134 | self.assertAlmostEqual( |
155 | 135 | sum(sale_orders.mapped("order_line.qty_delivered")), 12.0 |
|
0 commit comments