You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
5.8 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2016 Lorenzo Battistini - Agile Business Group
  3. # © 2016 Giovanni Capalbo <giovanni@therp.nl>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from openerp.tests.common import TransactionCase
  6. from datetime import datetime
  7. from dateutil.rrule import MONTHLY
  8. class TestAccountTaxBalance(TransactionCase):
  9. def setUp(self):
  10. super(TestAccountTaxBalance, self).setUp()
  11. self.range_type = self.env['date.range.type'].create(
  12. {'name': 'Fiscal year',
  13. 'company_id': False,
  14. 'allow_overlap': False})
  15. self.range_generator = self.env['date.range.generator']
  16. self.current_year = datetime.now().year
  17. self.current_month = datetime.now().month
  18. range_generator = self.range_generator.create({
  19. 'date_start': '%s-01-01' % self.current_year,
  20. 'name_prefix': '%s-' % self.current_year,
  21. 'type_id': self.range_type.id,
  22. 'duration_count': 1,
  23. 'unit_of_time': MONTHLY,
  24. 'count': 12})
  25. range_generator.action_apply()
  26. self.range = self.env['date.range']
  27. def test_tax_balance(self):
  28. tax_account_id = self.env['account.account'].search(
  29. [('name', '=', 'Tax Paid')], limit=1).id
  30. tax = self.env['account.tax'].create({
  31. 'name': 'Tax 10.0%',
  32. 'amount': 10.0,
  33. 'amount_type': 'percent',
  34. 'account_id': tax_account_id,
  35. })
  36. invoice_account_id = self.env['account.account'].search(
  37. [('user_type_id', '=', self.env.ref(
  38. 'account.data_account_type_receivable'
  39. ).id)], limit=1).id
  40. invoice_line_account_id = self.env['account.account'].search(
  41. [('user_type_id', '=', self.env.ref(
  42. 'account.data_account_type_expenses').id)], limit=1).id
  43. invoice = self.env['account.invoice'].create({
  44. 'partner_id': self.env.ref('base.res_partner_2').id,
  45. 'account_id': invoice_account_id,
  46. 'type': 'out_invoice',
  47. })
  48. self.env['account.invoice.line'].create({
  49. 'product_id': self.env.ref('product.product_product_4').id,
  50. 'quantity': 1.0,
  51. 'price_unit': 100.0,
  52. 'invoice_id': invoice.id,
  53. 'name': 'product that cost 100',
  54. 'account_id': invoice_line_account_id,
  55. 'invoice_line_tax_ids': [(6, 0, [tax.id])],
  56. })
  57. invoice._onchange_invoice_line_ids()
  58. invoice._convert_to_write(invoice._cache)
  59. self.assertEqual(invoice.state, 'draft')
  60. # change the state of invoice to open by clicking Validate button
  61. invoice.action_invoice_open()
  62. self.assertEquals(tax.base_balance, 100.)
  63. self.assertEquals(tax.balance, 10.)
  64. self.assertEquals(tax.base_balance_regular, 100.)
  65. self.assertEquals(tax.balance_regular, 10.)
  66. self.assertEquals(tax.base_balance_refund, 0.)
  67. self.assertEquals(tax.balance_refund, 0.)
  68. # testing wizard
  69. current_range = self.range.search([
  70. ('date_start', '=', '%s-%s-01' % (
  71. self.current_year, self.current_month))
  72. ])
  73. wizard = self.env['wizard.open.tax.balances'].new({})
  74. self.assertFalse(wizard.from_date)
  75. self.assertFalse(wizard.to_date)
  76. wizard = self.env['wizard.open.tax.balances'].new({
  77. 'date_range_id': current_range[0].id,
  78. })
  79. wizard.onchange_date_range_id()
  80. wizard._convert_to_write(wizard._cache)
  81. action = wizard.open_taxes()
  82. self.assertEqual(
  83. action['context']['from_date'], current_range[0].date_start)
  84. self.assertEqual(
  85. action['context']['to_date'], current_range[0].date_end)
  86. self.assertEqual(
  87. action['xml_id'], 'account_tax_balance.action_tax_balances_tree')
  88. # testing buttons
  89. tax_action = tax.view_tax_lines()
  90. base_action = tax.view_base_lines()
  91. self.assertTrue(
  92. tax_action['domain'][0][2][0] in
  93. [l.id for l in invoice.move_id.line_ids])
  94. self.assertEqual(
  95. tax_action['xml_id'], 'account.action_account_moves_all_tree')
  96. self.assertTrue(
  97. base_action['domain'][0][2][0] in
  98. [l.id for l in invoice.move_id.line_ids])
  99. self.assertEqual(
  100. base_action['xml_id'], 'account.action_account_moves_all_tree')
  101. # test specific method
  102. state_list = tax.get_target_state_list(target_move='all')
  103. self.assertEqual(state_list, ['posted', 'draft'])
  104. state_list = tax.get_target_state_list(target_move='whatever')
  105. self.assertEqual(state_list, [])
  106. refund = self.env['account.invoice'].create({
  107. 'partner_id': self.env.ref('base.res_partner_2').id,
  108. 'account_id': invoice_account_id,
  109. 'type': 'out_refund',
  110. })
  111. self.env['account.invoice.line'].create({
  112. 'product_id': self.env.ref('product.product_product_2').id,
  113. 'quantity': 1.0,
  114. 'price_unit': 25.0,
  115. 'invoice_id': refund.id,
  116. 'name': 'returned product that cost 25',
  117. 'account_id': invoice_line_account_id,
  118. 'invoice_line_tax_ids': [(6, 0, [tax.id])],
  119. })
  120. refund._onchange_invoice_line_ids()
  121. refund._convert_to_write(invoice._cache)
  122. self.assertEqual(refund.state, 'draft')
  123. # change the state of refund to open by clicking Validate button
  124. refund.action_invoice_open()
  125. self.assertEquals(tax.base_balance, 75.)
  126. self.assertEquals(tax.balance, 7.5)
  127. self.assertEquals(tax.base_balance_regular, 100.)
  128. self.assertEquals(tax.balance_regular, 10.)
  129. self.assertEquals(tax.base_balance_refund, -25.)
  130. self.assertEquals(tax.balance_refund, -2.5)