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