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
23 changes: 21 additions & 2 deletions product_abc_classification/models/abc_classification_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AbcClassificationProfile(models.Model):
comodel_name="abc.classification.level", inverse_name="profile_id"
)
profile_type = fields.Selection(
selection=[],
selection=[("manual", "Manual")],
string="Type of ABC classification",
index=True,
required=True,
Expand Down Expand Up @@ -73,7 +73,26 @@ def _check_levels(self):
)

def _compute_abc_classification(self):
raise NotImplementedError()
ProductClassification = self.env["abc.classification.product.level"]
for profile in self:
default_level = profile.level_ids[0]
profile_products = profile.product_variant_ids
classified_products = ProductClassification.search(
[("profile_id", "=", profile.id)]
).mapped("product_id")
missing_classification = profile_products - classified_products
vals_list = []
for product in missing_classification:
vals_list.append(
{
"product_id": product.id,
"profile_id": profile.id,
"manual_level_id": default_level.id,
}
)
if vals_list:
ProductClassification.create(vals_list)
return True

@api.depends("product_variant_ids")
def _compute_product_count(self):
Expand Down
1 change: 1 addition & 0 deletions product_abc_classification/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import test_abc_classification_product_level
from . import test_abc_classification_profile
from . import test_abc_classification_manual_profile
from . import test_product
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2025 ForgeFlow
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from .common import ABCClassificationLevelCase


class TestABCClassificationProductLevel(ABCClassificationLevelCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.product_template.abc_classification_profile_ids = cls.classification_profile

def test_abc_classification_manual_profile(self):
"""
Test case:
Execute ABC classification compute for manual (default) profile
Expected result:
A instance is created with:
* the manual_level_id and level_id set
* computed_level_id is not set

"""
self.classification_profile._compute_abc_classification()
level = self.product_product.abc_classification_product_level_ids
self.assertTrue(level)
self.assertEqual(level.manual_level_id, self.classification_level_a)
self.assertEqual(level.level_id, self.classification_level_a)
self.assertFalse(level.computed_level_id)
Loading