From 96f20a75fef07a32435cbc2dca21e785ec88c509 Mon Sep 17 00:00:00 2001 From: Georges Racinet Date: Thu, 1 Nov 2012 21:39:35 +0100 Subject: [PATCH] [TEST] starting unit tests for taxes bzr revid: gracinet@ishtar.anybox.fr-20121101203935-jbcp6cwikhn56ahm --- addons/account/tests/__init__.py | 4 +++ addons/account/tests/test_tax.py | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 addons/account/tests/__init__.py create mode 100644 addons/account/tests/test_tax.py diff --git a/addons/account/tests/__init__.py b/addons/account/tests/__init__.py new file mode 100644 index 00000000000..11fe4186db6 --- /dev/null +++ b/addons/account/tests/__init__.py @@ -0,0 +1,4 @@ +from . import test_tax + +fast_suite = [test_tax, + ] diff --git a/addons/account/tests/test_tax.py b/addons/account/tests/test_tax.py new file mode 100644 index 00000000000..a172a17e30d --- /dev/null +++ b/addons/account/tests/test_tax.py @@ -0,0 +1,49 @@ +from openerp.tests.common import TransactionCase + +class TestTax(TransactionCase): + """Tests for taxes (account.tax) + + We don't really need at this point to link taxes to tax codes + (account.tax.code) nor to companies (base.company) to check computation + results. + """ + + def setUp(self): + super(TestTax, self).setUp() + self.tax_model = self.registry('account.tax') + + def test_programmatic_tax(self): + cr, uid = self.cr, self.uid + tax_id = self.tax_model.create(cr, uid, dict( + name="Programmatic tax", + type='code', + python_compute='result = 12.0', + python_compute_inv='result = 11.0', + )) + + tax_records = self.tax_model.browse(cr, uid, [tax_id]) + res = self.tax_model.compute_all(cr, uid, tax_records, 50.0, 2) + + tax_detail = res['taxes'][0] + self.assertEquals(tax_detail['amount'], 24.0) + self.assertEquals(res['total_included'], 124.0) + + def test_percent_tax(self): + """Test computations done by a 10 percent tax.""" + cr, uid = self.cr, self.uid + tax_id = self.tax_model.create(cr, uid, dict( + name="Percent tax", + type='percent', + amount='0.1', + )) + + tax_records = self.tax_model.browse(cr, uid, [tax_id]) + res = self.tax_model.compute_all(cr, uid, tax_records, 50.0, 2) + + tax_detail = res['taxes'][0] + self.assertEquals(tax_detail['amount'], 10.0) + self.assertEquals(res['total_included'], 110.0) + + # now the inverse computation + res = self.tax_model.compute_inv(cr, uid, tax_records, 55.0, 2) + self.assertEquals(res[0]['amount'], 10.0)