Skip to content

Commit ed931e9

Browse files
Kev-Rochedreispt
authored andcommitted
[16.0][FIX] fix compute_kit_quantities
1 parent 2f8de07 commit ed931e9

3 files changed

Lines changed: 90 additions & 0 deletions

File tree

mrp_bom_version/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
from . import mrp_bom
55
from . import res_config
6+
from . import stock_move
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2025 Akretion (https://www.akretion.com).
2+
# @author Kévin Roche <kevin.roche@akretion.com>
3+
4+
from odoo import models
5+
6+
7+
class StockMove(models.Model):
8+
_inherit = "stock.move"
9+
10+
def _compute_kit_quantities(self, product_id, kit_qty, kit_bom, filters):
11+
if len(self.bom_line_id.bom_id) == 1 and self.bom_line_id.bom_id != kit_bom:
12+
if self.bom_line_id.bom_id.version < kit_bom.version:
13+
kit_bom = self.bom_line_id.bom_id
14+
return super()._compute_kit_quantities(product_id, kit_qty, kit_bom, filters)

mrp_bom_version/tests/test_mrp_bom_version.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,78 @@ def test_mrp_bom_versioning(self):
9191
self.assertEqual(
9292
new_bom.state, "draft", "New version must be created in 'draft' state"
9393
)
94+
95+
def test_historical_bom_still_used_in_picking(self):
96+
self.mrp_bom.button_activate()
97+
kit_product = self.mrp_bom.product_tmpl_id.product_variant_id
98+
99+
picking = self.env["stock.picking"].create(
100+
{
101+
"partner_id": self.env.ref("base.res_partner_1").id,
102+
"picking_type_id": self.env.ref("stock.picking_type_out").id,
103+
"location_id": self.env.ref("stock.stock_location_stock").id,
104+
"location_dest_id": self.env.ref("stock.stock_location_customers").id,
105+
}
106+
)
107+
bom_line_5 = self.mrp_bom.bom_line_ids.filtered(
108+
lambda l: l.product_id == self.env.ref("product.product_product_5")
109+
)
110+
bom_line_6 = self.mrp_bom.bom_line_ids.filtered(
111+
lambda l: l.product_id == self.env.ref("product.product_product_6")
112+
)
113+
114+
self.env["stock.move"].create(
115+
{
116+
"name": "Kit Move – compo 5",
117+
"product_id": self.env.ref("product.product_product_5").id,
118+
"product_uom_qty": 1,
119+
"product_uom": kit_product.uom_id.id,
120+
"picking_id": picking.id,
121+
"location_id": picking.location_id.id,
122+
"location_dest_id": picking.location_dest_id.id,
123+
"bom_line_id": bom_line_5.id,
124+
}
125+
)
126+
self.env["stock.move"].create(
127+
{
128+
"name": "Kit Move – compo 6",
129+
"product_id": self.env.ref("product.product_product_6").id,
130+
"product_uom_qty": 1,
131+
"product_uom": kit_product.uom_id.id,
132+
"picking_id": picking.id,
133+
"location_id": picking.location_id.id,
134+
"location_dest_id": picking.location_dest_id.id,
135+
"bom_line_id": bom_line_6.id,
136+
}
137+
)
138+
139+
picking.action_assign()
140+
picking.button_validate()
141+
142+
filters = {
143+
"incoming_moves": lambda m: m.id in picking.move_ids.ids,
144+
"outgoing_moves": lambda m: m.id not in picking.move_ids.ids,
145+
}
146+
147+
qty = picking.move_ids._compute_kit_quantities(
148+
product_id=kit_product,
149+
kit_qty=1,
150+
kit_bom=self.mrp_bom,
151+
filters=filters,
152+
)
153+
self.assertEqual(qty, 1.0)
154+
155+
self.mrp_bom.button_new_version()
156+
new_bom = self.bom_model.with_context(active_test=False).search(
157+
[
158+
("previous_bom_id", "=", self.mrp_bom.id),
159+
],
160+
limit=1,
161+
)
162+
qty2 = picking.move_ids._compute_kit_quantities(
163+
product_id=kit_product,
164+
kit_qty=1,
165+
kit_bom=new_bom,
166+
filters=filters,
167+
)
168+
self.assertEqual(qty2, 1.0)

0 commit comments

Comments
 (0)