Skip to content

Commit e3db827

Browse files
committed
[IMP] stock_product_pack: Extract pack move removal check into method
1 parent c4c83cc commit e3db827

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

stock_product_pack/models/stock_rule.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
class ProcurementGroup(models.Model):
77
_inherit = "procurement.group"
88

9+
def is_pack_dont_create_move(self, product):
10+
return (
11+
product
12+
and product.pack_ok
13+
and product.dont_create_move
14+
and product.pack_type == "detailed"
15+
)
16+
917
@api.model
1018
def run(self, procurements, raise_user_error=True):
1119
"""If 'run' is called on a pack product storable.
1220
we remove the procurement with this product pack.
1321
"""
1422
for procurement in procurements:
15-
if (
16-
procurement.product_id
17-
and procurement.product_id.pack_ok
18-
and procurement.product_id.dont_create_move
19-
and procurement.product_id.pack_type == "detailed"
20-
):
23+
if self.is_pack_dont_create_move(procurement.product_id):
2124
procurements.remove(procurement)
2225

2326
return super().run(procurements, raise_user_error=raise_user_error)

stock_product_pack/tests/test_stock_product_pack.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,37 @@ def test_compute_quantities_dict(self):
178178
self.assertEqual(self.pack_dc.virtual_available, 5)
179179
self.assertEqual(self.pack_dc.qty_available, 5)
180180

181+
def test_is_pack_dont_create_move(self):
182+
procurement_group = self.env["procurement.group"]
183+
category_all_id = self.env.ref("product.product_category_all").id
184+
185+
self.assertTrue(
186+
procurement_group.is_pack_dont_create_move(self.pack_dc_with_dm)
187+
)
188+
self.assertFalse(procurement_group.is_pack_dont_create_move(self.pack_dc))
189+
190+
non_detailed_pack = self.product_obj.create(
191+
{
192+
"name": "Non-detailed pack with don't create move",
193+
"detailed_type": "product",
194+
"pack_ok": True,
195+
"dont_create_move": True,
196+
"pack_type": "non_detailed",
197+
"categ_id": category_all_id,
198+
}
199+
)
200+
self.assertFalse(procurement_group.is_pack_dont_create_move(non_detailed_pack))
201+
202+
not_a_pack = self.product_obj.create(
203+
{
204+
"name": "Not a pack with don't create move",
205+
"detailed_type": "product",
206+
"dont_create_move": True,
207+
"categ_id": category_all_id,
208+
}
209+
)
210+
self.assertFalse(procurement_group.is_pack_dont_create_move(not_a_pack))
211+
181212
def test_pack_with_dont_move_the_parent(self):
182213
"""Run a procurement for prod pack products when there are only 5 in stock then
183214
check that MTO is applied on the moves when the rule is set to 'mts_else_mto'

0 commit comments

Comments
 (0)