Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions stock_product_pack/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
class ProcurementGroup(models.Model):
_inherit = "procurement.group"

def is_pack_dont_create_move(self, product):
return (
product
and product.pack_ok
and product.dont_create_move
and product.pack_type == "detailed"
)

@api.model
def run(self, procurements, raise_user_error=True):
"""If 'run' is called on a pack product storable.
we remove the procurement with this product pack.
"""
for procurement in procurements:
if (
procurement.product_id
and procurement.product_id.pack_ok
and procurement.product_id.dont_create_move
and procurement.product_id.pack_type == "detailed"
):
if self.is_pack_dont_create_move(procurement.product_id):
procurements.remove(procurement)

return super().run(procurements, raise_user_error=raise_user_error)
31 changes: 31 additions & 0 deletions stock_product_pack/tests/test_stock_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,37 @@ def test_compute_quantities_dict(self):
self.assertEqual(self.pack_dc.virtual_available, 5)
self.assertEqual(self.pack_dc.qty_available, 5)

def test_is_pack_dont_create_move(self):
procurement_group = self.env["procurement.group"]
category_all_id = self.env.ref("product.product_category_all").id

self.assertTrue(
procurement_group.is_pack_dont_create_move(self.pack_dc_with_dm)
)
self.assertFalse(procurement_group.is_pack_dont_create_move(self.pack_dc))

non_detailed_pack = self.product_obj.create(
{
"name": "Non-detailed pack with don't create move",
"detailed_type": "product",
"pack_ok": True,
"dont_create_move": True,
"pack_type": "non_detailed",
"categ_id": category_all_id,
}
)
self.assertFalse(procurement_group.is_pack_dont_create_move(non_detailed_pack))

not_a_pack = self.product_obj.create(
{
"name": "Not a pack with don't create move",
"detailed_type": "product",
"dont_create_move": True,
"categ_id": category_all_id,
}
)
self.assertFalse(procurement_group.is_pack_dont_create_move(not_a_pack))

def test_pack_with_dont_move_the_parent(self):
"""Run a procurement for prod pack products when there are only 5 in stock then
check that MTO is applied on the moves when the rule is set to 'mts_else_mto'
Expand Down
Loading