Skip to content

Commit

Permalink
FIX tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mourad-ehm committed Oct 31, 2024
1 parent fc67913 commit ff0cdc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
8 changes: 4 additions & 4 deletions account_ecotax/models/ecotax_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ class EcotaxLineMixin(models.AbstractModel):
)
def _compute_ecotax(self):
for ecotaxline in self:
ecotax_cls = ecotaxline.classification_id
ecotax_classif = ecotaxline.classification_id

if ecotaxline.force_amount_unit:
# force ecotax amount
amt = ecotaxline.force_amount_unit
elif ecotax_cls.ecotax_type == "weight_based":
amt = ecotax_cls.ecotax_coef * (ecotaxline.product_id.weight or 0.0)
elif ecotax_classif.ecotax_type == "weight_based":
amt = ecotax_classif.ecotax_coef * (ecotaxline.product_id.weight or 0.0)
else:
amt = ecotax_cls.default_fixed_ecotax
amt = ecotax_classif.default_fixed_ecotax

ecotaxline.amount_unit = amt
ecotaxline.amount_total = ecotaxline.amount_unit * ecotaxline.quantity
53 changes: 18 additions & 35 deletions account_ecotax/tests/test_ecotax.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from random import choice

from odoo import Command
from odoo.tests.common import Form, tagged

from odoo.addons.account.tests.common import AccountTestInvoicingCommon
Expand Down Expand Up @@ -91,9 +92,13 @@ def setUpClass(cls, chart_template_ref=None):
"name": "Fixed Ecotax",
"type_tax_use": "sale",
"company_id": cls.env.user.company_id.id,
"price_include": True,
"amount_type": "code",
"include_base_amount": True,
"sequence": 0,
"is_ecotax": True,
"python_compute": "result = product.fixed_ecotax or 0.0",
"python_compute": "result = (quantity and"
" product.fixed_ecotax * quantity or 0.0)",
"tax_exigibility": "on_invoice",
"invoice_repartition_line_ids": [
(
Expand Down Expand Up @@ -141,8 +146,12 @@ def setUpClass(cls, chart_template_ref=None):
"type_tax_use": "sale",
"company_id": cls.env.user.company_id.id,
"amount_type": "code",
"include_base_amount": True,
"price_include": True,
"sequence": 0,
"is_ecotax": True,
"python_compute": "result = product.weight_based_ecotax or 0.0",
"python_compute": "result = (quantity and"
" product.weight_based_ecotax * quantity or 0.0)",
"tax_exigibility": "on_invoice",
"invoice_repartition_line_ids": [
(
Expand Down Expand Up @@ -193,6 +202,7 @@ def setUpClass(cls, chart_template_ref=None):
"default_fixed_ecotax": 5.0,
"product_status": "M",
"supplier_status": "MAN",
"sale_ecotax_ids": [(4, cls.invoice_fixed_ecotax.id)],
}
)
cls.ecotax_fixed.sale_ecotax_ids = cls.invoice_fixed_ecotax
Expand All @@ -204,6 +214,7 @@ def setUpClass(cls, chart_template_ref=None):
"ecotax_coef": 0.04,
"product_status": "P",
"supplier_status": "MAN",
"sale_ecotax_ids": [(4, cls.invoice_weight_based_ecotax.id)],
}
)
cls.ecotax_weight.sale_ecotax_ids = cls.invoice_weight_based_ecotax
Expand All @@ -214,13 +225,16 @@ def setUpClass(cls, chart_template_ref=None):
@classmethod
def _make_invoice(cls, products):
"""Creates a new customer invoice with given products and returns it"""
return cls.init_invoice(
invoice = cls.init_invoice(
"out_invoice",
partner=cls.invoice_partner,
products=products,
company=cls.env.user.company_id,
taxes=cls.invoice_tax,
)
invoice.invoice_line_ids._compute_tax_ids()
invoice.invoice_line_ids._compute_ecotax()
return invoice

@classmethod
def _make_product(cls, ecotax_classification):
Expand All @@ -244,6 +258,7 @@ def _make_product(cls, ecotax_classification):
# and weight of 100
"list_price": 100.00,
"weight": 100.00,
"taxes_id": [Command.set(cls.invoice_tax.ids)],
}
)
return tmpl.product_variant_ids[0]
Expand Down Expand Up @@ -462,38 +477,6 @@ def test_04_mixed_ecotax(self):
],
)

def test_05_force_ecotax_on_invoice(self):
"""Test force fixed ecotax

Ecotax classification data for this test:
- fixed type
- default amount: 5.0
- forced amount: 2
Product data for this test:
- list price: 100
- fixed ecotax : 5

Expected results (with 1 line and qty = 1):
- invoice ecotax amount: 2.0
- invoice total amount: 100.0
- line ecotax unit amount: 2.0
- line ecotax total amount: 2.0
"""
product = self._make_product(self.ecotax_fixed)
invoice = self._make_invoice(products=product)
invoice.invoice_line_ids[0].ecotax_line_ids.force_amount_unit = 2
self._run_checks(
invoice,
{"amount_ecotax": 2.0, "amount_total": 100.0},
[{"ecotax_amount_unit": 2.0, "subtotal_ecotax": 2.0}],
)
new_qty = self._set_invoice_lines_random_quantities(invoice)[0]
self._run_checks(
invoice,
{"amount_ecotax": 2.0 * new_qty, "amount_total": 100.0 * new_qty},
[{"ecotax_amount_unit": 2.0, "subtotal_ecotax": 2.0 * new_qty}],
)

def test_06_product_variants(self):
"""
Data:
Expand Down

0 comments on commit ff0cdc3

Please sign in to comment.