Skip to content

Commit

Permalink
UPD acc_prd_fiscal_classif: finally right domain
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Jun 14, 2024
1 parent f8d0755 commit b26c207
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ def _find_or_create_classification(self, vals):
"""Find the correct Fiscal classification,
depending of the taxes, or create a new one, if no one are found."""
# search for matching classication
purchase_tax_ids = vals.get("supplier_taxes_id", [])
sale_tax_ids = vals.get("taxes_id", [])
purchase_tax_ids = vals.get("supplier_taxes_id", False)
# it doesn't work properly with [] instead of False,
sale_tax_ids = vals.get("taxes_id", False)
for elm in ("supplier_taxes_id", "taxes_id"):
if elm in vals:
del vals[elm]
domain = [
("sale_tax_ids", "in", sale_tax_ids),
("purchase_tax_ids", "in", purchase_tax_ids),
("sale_tax_ids", "=", sale_tax_ids),
("purchase_tax_ids", "=", purchase_tax_ids),
]
classification = self.env["account.product.fiscal.classification"].search(
domain, limit=1
Expand Down
41 changes: 32 additions & 9 deletions account_product_fiscal_classification/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def test_30_rules(self):
)

def test_no_classification_and_find_one(self):
classif_count = self.env["account.product.fiscal.classification"].search_count(
[]
)
classif = self.env.ref(
"account_product_fiscal_classification.fiscal_classification_A_company_1"
)
Expand All @@ -178,26 +181,46 @@ def test_no_classification_and_find_one(self):
"supplier_taxes_id": classif.purchase_tax_ids.ids,
}
product = self.ProductTemplate.with_user(self.env.user).create(vals)
# no other classification is created
self.assertEqual(
self.env["account.product.fiscal.classification"].search_count([]),
classif_count,
)
# product is linked to created classification
self.assertEqual(product.fiscal_classification_id, classif)

def test_no_classification_and_create_one(self):
classif_co = self.env["account.product.fiscal.classification"].search_count([])
my_tax = self.env["account.tax"].create(
{"name": "my_tax", "type_tax_use": "sale", "amount": 9.99}
)
vals = {
"name": "Test Product",
"company_id": self.env.company.id,
"categ_id": self.category_all.id,
"taxes_id": my_tax.ids,
"supplier_taxes_id": [],
}
product = self.ProductTemplate.with_user(self.env.user).create(vals)
classif_co = self.env["account.product.fiscal.classification"].search_count([])

def create_product():
vals = {
"name": "Test Product",
"company_id": self.env.company.id,
"categ_id": self.category_all.id,
"taxes_id": my_tax.ids,
"supplier_taxes_id": [],
}
return self.ProductTemplate.with_user(self.env.user).create(vals)

product = create_product()
self.assertNotEqual(product.fiscal_classification_id, False)
classif_co_after = self.env[
"account.product.fiscal.classification"
].search_count([])
self.assertEqual(classif_co_after, classif_co + 1)
# check other products with same tax combination
# doesn't create other classification
product2 = create_product()
classif_co_final = self.env[
"account.product.fiscal.classification"
].search_count([])
self.assertEqual(
product.fiscal_classification_id, product2.fiscal_classification_id
)
self.assertEqual(classif_co_final, classif_co_after)

def test_no_tax_nor_classification_and_create_one(self):
vals = {
Expand Down

0 comments on commit b26c207

Please sign in to comment.