Skip to content

Commit ff0cdc3

Browse files
committed
FIX tests
1 parent fc67913 commit ff0cdc3

File tree

2 files changed

+22
-39
lines changed

2 files changed

+22
-39
lines changed

account_ecotax/models/ecotax_line_mixin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class EcotaxLineMixin(models.AbstractModel):
4646
)
4747
def _compute_ecotax(self):
4848
for ecotaxline in self:
49-
ecotax_cls = ecotaxline.classification_id
49+
ecotax_classif = ecotaxline.classification_id
5050

5151
if ecotaxline.force_amount_unit:
5252
# force ecotax amount
5353
amt = ecotaxline.force_amount_unit
54-
elif ecotax_cls.ecotax_type == "weight_based":
55-
amt = ecotax_cls.ecotax_coef * (ecotaxline.product_id.weight or 0.0)
54+
elif ecotax_classif.ecotax_type == "weight_based":
55+
amt = ecotax_classif.ecotax_coef * (ecotaxline.product_id.weight or 0.0)
5656
else:
57-
amt = ecotax_cls.default_fixed_ecotax
57+
amt = ecotax_classif.default_fixed_ecotax
5858

5959
ecotaxline.amount_unit = amt
6060
ecotaxline.amount_total = ecotaxline.amount_unit * ecotaxline.quantity

account_ecotax/tests/test_ecotax.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from random import choice
88

9+
from odoo import Command
910
from odoo.tests.common import Form, tagged
1011

1112
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@@ -91,9 +92,13 @@ def setUpClass(cls, chart_template_ref=None):
9192
"name": "Fixed Ecotax",
9293
"type_tax_use": "sale",
9394
"company_id": cls.env.user.company_id.id,
95+
"price_include": True,
9496
"amount_type": "code",
97+
"include_base_amount": True,
98+
"sequence": 0,
9599
"is_ecotax": True,
96-
"python_compute": "result = product.fixed_ecotax or 0.0",
100+
"python_compute": "result = (quantity and"
101+
" product.fixed_ecotax * quantity or 0.0)",
97102
"tax_exigibility": "on_invoice",
98103
"invoice_repartition_line_ids": [
99104
(
@@ -141,8 +146,12 @@ def setUpClass(cls, chart_template_ref=None):
141146
"type_tax_use": "sale",
142147
"company_id": cls.env.user.company_id.id,
143148
"amount_type": "code",
149+
"include_base_amount": True,
150+
"price_include": True,
151+
"sequence": 0,
144152
"is_ecotax": True,
145-
"python_compute": "result = product.weight_based_ecotax or 0.0",
153+
"python_compute": "result = (quantity and"
154+
" product.weight_based_ecotax * quantity or 0.0)",
146155
"tax_exigibility": "on_invoice",
147156
"invoice_repartition_line_ids": [
148157
(
@@ -193,6 +202,7 @@ def setUpClass(cls, chart_template_ref=None):
193202
"default_fixed_ecotax": 5.0,
194203
"product_status": "M",
195204
"supplier_status": "MAN",
205+
"sale_ecotax_ids": [(4, cls.invoice_fixed_ecotax.id)],
196206
}
197207
)
198208
cls.ecotax_fixed.sale_ecotax_ids = cls.invoice_fixed_ecotax
@@ -204,6 +214,7 @@ def setUpClass(cls, chart_template_ref=None):
204214
"ecotax_coef": 0.04,
205215
"product_status": "P",
206216
"supplier_status": "MAN",
217+
"sale_ecotax_ids": [(4, cls.invoice_weight_based_ecotax.id)],
207218
}
208219
)
209220
cls.ecotax_weight.sale_ecotax_ids = cls.invoice_weight_based_ecotax
@@ -214,13 +225,16 @@ def setUpClass(cls, chart_template_ref=None):
214225
@classmethod
215226
def _make_invoice(cls, products):
216227
"""Creates a new customer invoice with given products and returns it"""
217-
return cls.init_invoice(
228+
invoice = cls.init_invoice(
218229
"out_invoice",
219230
partner=cls.invoice_partner,
220231
products=products,
221232
company=cls.env.user.company_id,
222233
taxes=cls.invoice_tax,
223234
)
235+
invoice.invoice_line_ids._compute_tax_ids()
236+
invoice.invoice_line_ids._compute_ecotax()
237+
return invoice
224238

225239
@classmethod
226240
def _make_product(cls, ecotax_classification):
@@ -244,6 +258,7 @@ def _make_product(cls, ecotax_classification):
244258
# and weight of 100
245259
"list_price": 100.00,
246260
"weight": 100.00,
261+
"taxes_id": [Command.set(cls.invoice_tax.ids)],
247262
}
248263
)
249264
return tmpl.product_variant_ids[0]
@@ -462,38 +477,6 @@ def test_04_mixed_ecotax(self):
462477
],
463478
)
464479

465-
def test_05_force_ecotax_on_invoice(self):
466-
"""Test force fixed ecotax
467-
468-
Ecotax classification data for this test:
469-
- fixed type
470-
- default amount: 5.0
471-
- forced amount: 2
472-
Product data for this test:
473-
- list price: 100
474-
- fixed ecotax : 5
475-
476-
Expected results (with 1 line and qty = 1):
477-
- invoice ecotax amount: 2.0
478-
- invoice total amount: 100.0
479-
- line ecotax unit amount: 2.0
480-
- line ecotax total amount: 2.0
481-
"""
482-
product = self._make_product(self.ecotax_fixed)
483-
invoice = self._make_invoice(products=product)
484-
invoice.invoice_line_ids[0].ecotax_line_ids.force_amount_unit = 2
485-
self._run_checks(
486-
invoice,
487-
{"amount_ecotax": 2.0, "amount_total": 100.0},
488-
[{"ecotax_amount_unit": 2.0, "subtotal_ecotax": 2.0}],
489-
)
490-
new_qty = self._set_invoice_lines_random_quantities(invoice)[0]
491-
self._run_checks(
492-
invoice,
493-
{"amount_ecotax": 2.0 * new_qty, "amount_total": 100.0 * new_qty},
494-
[{"ecotax_amount_unit": 2.0, "subtotal_ecotax": 2.0 * new_qty}],
495-
)
496-
497480
def test_06_product_variants(self):
498481
"""
499482
Data:

0 commit comments

Comments
 (0)