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.

112 lines
4.4 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 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': 'fixed',
  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.signal_workflow('invoice_open')
  62. self.assertEquals(tax.base_balance, 100)
  63. self.assertEquals(tax.balance, 10)
  64. # testing wizard
  65. current_range = self.range.search([
  66. ('date_start', '=', '%s-%s-01' % (
  67. self.current_year, self.current_month))
  68. ])
  69. wizard = self.env['wizard.open.tax.balances'].new({})
  70. self.assertFalse(wizard.from_date)
  71. self.assertFalse(wizard.to_date)
  72. wizard = self.env['wizard.open.tax.balances'].new({
  73. 'date_range_id': current_range[0].id,
  74. })
  75. wizard.onchange_date_range_id()
  76. wizard._convert_to_write(wizard._cache)
  77. action = wizard.open_taxes()
  78. self.assertEqual(
  79. action['context']['from_date'], current_range[0].date_start)
  80. self.assertEqual(
  81. action['context']['to_date'], current_range[0].date_end)
  82. self.assertEqual(
  83. action['xml_id'], 'account_tax_balance.action_tax_balances_tree')
  84. # testing buttons
  85. tax_action = tax.view_tax_lines()
  86. base_action = tax.view_base_lines()
  87. self.assertTrue(
  88. tax_action['domain'][0][2][0] in
  89. [l.id for l in invoice.move_id.line_ids])
  90. self.assertEqual(
  91. tax_action['xml_id'], 'account.action_account_moves_all_tree')
  92. self.assertTrue(
  93. base_action['domain'][0][2][0] in
  94. [l.id for l in invoice.move_id.line_ids])
  95. self.assertEqual(
  96. base_action['xml_id'], 'account.action_account_moves_all_tree')
  97. # test specific method
  98. state_list = tax.get_target_state_list(target_move='all')
  99. self.assertEqual(state_list, ['posted', 'draft'])
  100. state_list = tax.get_target_state_list(target_move='whatever')
  101. self.assertEqual(state_list, [])