summaryrefslogtreecommitdiff
path: root/addons/account_tax_python
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-05-13 15:26:12 +0200
committerChristophe Simonis <chs@odoo.com>2019-05-13 15:26:12 +0200
commit8dd5a85267b522ba569ab9ed44901f95fffbeb4f (patch)
treeddb62d1e83e1b810b96c05f6819ca66f8d6b4955 /addons/account_tax_python
parent15716642e1975b4f2f29916011a4be29804cda88 (diff)
parent60e71302a38b36214efec1213882f573e3ea453c (diff)
[MERGE] forward port branch saas-12.3 up to 60e71302a38
Diffstat (limited to 'addons/account_tax_python')
-rw-r--r--addons/account_tax_python/models/account_tax.py4
-rw-r--r--addons/account_tax_python/tests/__init__.py3
-rw-r--r--addons/account_tax_python/tests/test_tax.py61
3 files changed, 66 insertions, 2 deletions
diff --git a/addons/account_tax_python/models/account_tax.py b/addons/account_tax_python/models/account_tax.py
index f9058e6f512..0c1f140ee57 100644
--- a/addons/account_tax_python/models/account_tax.py
+++ b/addons/account_tax_python/models/account_tax.py
@@ -36,7 +36,7 @@ class AccountTaxPython(models.Model):
return super(AccountTaxPython, self)._compute_amount(base_amount, price_unit, quantity, product, partner)
@api.multi
- def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None):
+ def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None, is_refund=False):
taxes = self.filtered(lambda r: r.amount_type != 'code')
company = self.env.company_id
for tax in self.filtered(lambda r: r.amount_type == 'code'):
@@ -45,7 +45,7 @@ class AccountTaxPython(models.Model):
safe_eval(tax.python_applicable, localdict, mode="exec", nocopy=True)
if localdict.get('result', False):
taxes += tax
- return super(AccountTaxPython, taxes).compute_all(price_unit, currency, quantity, product, partner)
+ return super(AccountTaxPython, taxes).compute_all(price_unit, currency, quantity, product, partner, is_refund=is_refund)
class AccountTaxTemplatePython(models.Model):
diff --git a/addons/account_tax_python/tests/__init__.py b/addons/account_tax_python/tests/__init__.py
new file mode 100644
index 00000000000..b9eada7706e
--- /dev/null
+++ b/addons/account_tax_python/tests/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from . import test_tax
diff --git a/addons/account_tax_python/tests/test_tax.py b/addons/account_tax_python/tests/test_tax.py
new file mode 100644
index 00000000000..2ad4529cd4b
--- /dev/null
+++ b/addons/account_tax_python/tests/test_tax.py
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+from odoo.addons.account.tests.test_tax import TestTax
+from odoo.tests import tagged
+
+
+@tagged('post_install', '-at_install')
+class TestTaxPython(TestTax):
+
+ def setUp(self):
+ super(TestTaxPython, self).setUp()
+
+ self.python_tax = self.tax_model.create({
+ 'name': 'Python TAx',
+ 'amount_type': 'code',
+ 'amount': 0.0,
+ 'python_compute': 'result = ((price_unit * quantity) - ((price_unit * quantity) / 1.12)) * 0.5',
+ 'sequence': 1,
+ })
+
+ def test_tax_python_basic(self):
+ res = self.python_tax.compute_all(130.0)
+ self._check_compute_all_results(
+ 136.96, # 'total_included'
+ 130.0, # 'total_excluded'
+ [
+ # base , amount | seq | amount | incl | incl_base
+ # --------------------------------------------------
+ (130.0, 6.96), # | 1 | 6% | t |
+ # --------------------------------------------------
+ ],
+ res
+ )
+
+ def test_tax_python_price_include(self):
+ self.python_tax.price_include = True
+ res = self.python_tax.compute_all(130.0)
+ self._check_compute_all_results(
+ 130, # 'total_included'
+ 123.04, # 'total_excluded'
+ [
+ # base , amount | seq | amount | incl | incl_base
+ # ---------------------------------------------------
+ (123.04, 6.96), # | 1 | 6% | t |
+ # ---------------------------------------------------
+ ],
+ res
+ )
+
+ res = (self.python_tax + self.python_tax).compute_all(130.0)
+ self._check_compute_all_results(
+ 130, # 'total_included'
+ 116.07, # 'total_excluded'
+ [
+ # base , amount | seq | amount | incl | incl_base
+ # ---------------------------------------------------
+ (116.07, 6.96), # | 1 | 6% | t |
+ (116.07, 6.97), # | 1 | 6% | t |
+ # ---------------------------------------------------
+ ],
+ res
+ )