diff --git a/account_product_fiscal_classification/models/product_template.py b/account_product_fiscal_classification/models/product_template.py index 63ddd54f9..faeecdf4c 100644 --- a/account_product_fiscal_classification/models/product_template.py +++ b/account_product_fiscal_classification/models/product_template.py @@ -34,7 +34,7 @@ class ProductTemplate(models.Model): @api.model_create_multi def create(self, vals_list): for vals in vals_list: - self._update_vals_fiscal_classification(vals) + self._update_vals_fiscal_classification(vals, create_mode=True) return super().create(vals_list) def write(self, vals): @@ -62,7 +62,7 @@ def get_view(self, view_id=None, view_type="form", **options): return result # Custom Section - def _update_vals_fiscal_classification(self, vals): + def _update_vals_fiscal_classification(self, vals, create_mode=False): FiscalClassification = self.env["account.product.fiscal.classification"] if vals.get("fiscal_classification_id"): # We use sudo to have access to all the taxes, even taxes that belong @@ -76,11 +76,7 @@ def _update_vals_fiscal_classification(self, vals): "taxes_id": [(6, 0, classification.sale_tax_ids.ids)], } ) - elif ( - vals.get("supplier_taxes_id") - or vals.get("taxes_id") - or "fiscal_classification_id" not in vals - ): + elif create_mode or {"supplier_taxes_id", "taxes_id"} & vals.keys(): self._find_or_create_classification(vals) return vals diff --git a/account_product_fiscal_classification/tests/test_module.py b/account_product_fiscal_classification/tests/test_module.py index ba317b884..14522cb20 100644 --- a/account_product_fiscal_classification/tests/test_module.py +++ b/account_product_fiscal_classification/tests/test_module.py @@ -189,10 +189,11 @@ def test_no_classification_and_create_one(self): "name": "Test Product", "company_id": self.env.company.id, "categ_id": self.category_all.id, - "taxes_id": my_tax.id, + "taxes_id": my_tax.ids, + "supplier_taxes_id": [], } product = self.ProductTemplate.with_user(self.env.user).create(vals) - self.assertNotEquals(product.fiscal_classification_id, False) + self.assertNotEqual(product.fiscal_classification_id, False) classif_co_after = self.env[ "account.product.fiscal.classification" ].search_count([]) @@ -203,9 +204,11 @@ def test_no_tax_nor_classification_and_create_one(self): "name": "Test Product", "company_id": self.env.company.id, "categ_id": self.category_all.id, + "taxes_id": [], + "supplier_taxes_id": [], } product = self.ProductTemplate.with_user(self.env.user).create(vals) - self.assertNotEquals(product.fiscal_classification_id, False) + self.assertNotEqual(product.fiscal_classification_id, False) def _create_product(self, user, category, classification): vals = {