Skip to content

Commit

Permalink
16.0 fix create mode (#4)
Browse files Browse the repository at this point in the history
* [FIX] account_product_fiscal_classification : In a context of product creation, if classification is not provided (in import context for exemple), _find_or_create_classification should be allways called to ensure all templates have a classification

* [FIX] account_product_fiscal_classification : if a code make a write vals={supplier_taxes_id: []} this should raise the call of _find_or_create_classification

* [FIX] account_product_fiscal_classification/tests : assertNotEquals is deprecated

* [FIX] account_product_fiscal_classification : explicit supplier and customer taxes in test, to avoid bug if default taxes are defined
  • Loading branch information
legalsylvain authored Jun 12, 2024
1 parent 53ccfda commit 2d115ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 3 additions & 7 deletions account_product_fiscal_classification/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
9 changes: 6 additions & 3 deletions account_product_fiscal_classification/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand All @@ -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 = {
Expand Down

0 comments on commit 2d115ab

Please sign in to comment.