test_tax.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. from odoo.addons.account.tests.test_tax import TestTaxCommon
  3. from odoo.tests import tagged
  4. @tagged('post_install', '-at_install')
  5. class TestTaxPython(TestTaxCommon):
  6. @classmethod
  7. def setUpClass(cls):
  8. super(TestTaxPython, cls).setUpClass()
  9. cls.python_tax = cls.env['account.tax'].create({
  10. 'name': 'Python TAx',
  11. 'amount_type': 'code',
  12. 'amount': 0.0,
  13. 'python_compute': 'result = ((price_unit * quantity) - ((price_unit * quantity) / 1.12)) * 0.5',
  14. 'sequence': 1,
  15. })
  16. def test_tax_python_basic(self):
  17. res = self.python_tax.compute_all(130.0)
  18. self._check_compute_all_results(
  19. 136.96, # 'total_included'
  20. 130.0, # 'total_excluded'
  21. [
  22. # base , amount | seq | amount | incl | incl_base
  23. # --------------------------------------------------
  24. (130.0, 6.96), # | 1 | 6% | t |
  25. # --------------------------------------------------
  26. ],
  27. res
  28. )
  29. def test_tax_python_price_include(self):
  30. self.python_tax.price_include = True
  31. res = self.python_tax.compute_all(130.0)
  32. self._check_compute_all_results(
  33. 130, # 'total_included'
  34. 123.04, # 'total_excluded'
  35. [
  36. # base , amount | seq | amount | incl | incl_base
  37. # ---------------------------------------------------
  38. (123.04, 6.96), # | 1 | 6% | t |
  39. # ---------------------------------------------------
  40. ],
  41. res
  42. )
  43. res = (self.python_tax + self.python_tax).compute_all(130.0)
  44. self._check_compute_all_results(
  45. 130, # 'total_included'
  46. 116.07, # 'total_excluded'
  47. [
  48. # base , amount | seq | amount | incl | incl_base
  49. # ---------------------------------------------------
  50. (116.07, 6.96), # | 1 | 6% | t |
  51. (116.07, 6.97), # | 1 | 6% | t |
  52. # ---------------------------------------------------
  53. ],
  54. res
  55. )