|
1 | 1 | # Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) |
2 | 2 | # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). |
| 3 | +from odoo import Command |
3 | 4 | from odoo.tests import Form |
4 | 5 |
|
5 | 6 | from .test_common import TestCommon |
@@ -99,3 +100,42 @@ def test_create_move_same_uom_rounding_half_up(self): |
99 | 100 | } |
100 | 101 | ) |
101 | 102 | self.assertEqual(move.product_uom_qty, 5.0) |
| 103 | + |
| 104 | + def test_create_move_linked_sml_not_unreserved(self): |
| 105 | + # The UoM conversion in create must not trigger unreservation of |
| 106 | + # explicitly linked SML |
| 107 | + sml = self.env["stock.move.line"].create( |
| 108 | + { |
| 109 | + "product_id": self.product.id, |
| 110 | + "product_uom_id": self.cm_uom.id, |
| 111 | + "quantity": 70, |
| 112 | + "location_id": self.location.id, |
| 113 | + "location_dest_id": self.location_dest.id, |
| 114 | + "company_id": self.env.company.id, |
| 115 | + } |
| 116 | + ) |
| 117 | + move = self.env["stock.move"].create( |
| 118 | + { |
| 119 | + "name": self.product.display_name, |
| 120 | + "location_id": self.location.id, |
| 121 | + "location_dest_id": self.location_dest.id, |
| 122 | + "product_id": self.product.id, |
| 123 | + "product_uom_qty": 30, |
| 124 | + "product_uom": self.cm_uom.id, |
| 125 | + "picking_type_id": self.stock_picking_type_2.id, |
| 126 | + "state": "assigned", |
| 127 | + "move_line_ids": [Command.link(sml.id)], |
| 128 | + } |
| 129 | + ) |
| 130 | + self.assertTrue(sml.exists()) |
| 131 | + self.assertEqual(sml.move_id, move) |
| 132 | + # UoM was converted on the SM but not on the SML |
| 133 | + self.assertEqual(move.product_uom, self.meter_uom) |
| 134 | + self.assertEqual(sml.product_uom_id, self.cm_uom) |
| 135 | + # SML quantity is unchanged (70 cm) |
| 136 | + self.assertEqual(sml.quantity, 70) |
| 137 | + # SM demand converted: 30 cm --> 0.3 m |
| 138 | + self.assertEqual(move.product_uom_qty, 0.3) |
| 139 | + # SM reserved qty is computed from SML: 70 cm --> 0.7 m |
| 140 | + # Quantities are coherent, but SML is kept as original |
| 141 | + self.assertEqual(move.quantity, 0.7) |
0 commit comments