diff --git a/product_abc_classification/models/abc_classification_profile.py b/product_abc_classification/models/abc_classification_profile.py index 996186af797..7a7ef7da7a3 100644 --- a/product_abc_classification/models/abc_classification_profile.py +++ b/product_abc_classification/models/abc_classification_profile.py @@ -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, @@ -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): diff --git a/product_abc_classification/tests/__init__.py b/product_abc_classification/tests/__init__.py index 8292c06ca32..644a77664ca 100644 --- a/product_abc_classification/tests/__init__.py +++ b/product_abc_classification/tests/__init__.py @@ -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 diff --git a/product_abc_classification/tests/test_abc_classification_manual_profile.py b/product_abc_classification/tests/test_abc_classification_manual_profile.py new file mode 100644 index 00000000000..e042018879d --- /dev/null +++ b/product_abc_classification/tests/test_abc_classification_manual_profile.py @@ -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)