@@ -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