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.

288 lines
11 KiB

  1. # Copyright 2018 Forest and Biomass Romania
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. import time
  4. from odoo.tests import common
  5. from . import abstract_test_tax_report
  6. class TestVAT(abstract_test_tax_report.AbstractTest):
  7. """
  8. Technical tests for VAT Report.
  9. """
  10. def _getReportModel(self):
  11. return self.env['report_vat_report']
  12. def _getQwebReportName(self):
  13. return 'account_financial_report.report_vat_report_qweb'
  14. def _getXlsxReportName(self):
  15. return 'a_f_r.report_vat_report_xlsx'
  16. def _getXlsxReportActionName(self):
  17. return 'account_financial_report.action_report_vat_report_xlsx'
  18. def _getReportTitle(self):
  19. return 'Odoo'
  20. def _getBaseFilters(self):
  21. return {
  22. 'date_from': time.strftime('%Y-01-01'),
  23. 'date_to': time.strftime('%Y-12-31'),
  24. 'company_id': self.env.user.company_id.id,
  25. }
  26. def _getAdditionalFiltersToBeTested(self):
  27. return [
  28. {'based_on': 'taxtags'},
  29. {'based_on': 'taxgroups'},
  30. {'tax_details': True},
  31. {'based_on': 'taxtags', 'tax_details': True},
  32. {'based_on': 'taxgroups', 'tax_details': True},
  33. ]
  34. class TestVATReport(common.TransactionCase):
  35. def setUp(self):
  36. super(TestVATReport, self).setUp()
  37. self.date_from = time.strftime('%Y-%m-01'),
  38. self.date_to = time.strftime('%Y-%m-28'),
  39. self.receivable_account = self.env['account.account'].search([
  40. ('user_type_id.name', '=', 'Receivable')
  41. ], limit=1)
  42. self.income_account = self.env['account.account'].search([
  43. ('user_type_id.name', '=', 'Income')
  44. ], limit=1)
  45. self.tax_account = self.env['account.account'].search([
  46. ('user_type_id',
  47. '=',
  48. self.env.ref(
  49. 'account.data_account_type_non_current_liabilities').id
  50. )], limit=1)
  51. self.bank_journal = self.env['account.journal'].search(
  52. [('type', '=', 'bank')], limit=1)
  53. self.tax_tag_01 = self.env['account.account.tag'].create({
  54. 'name': 'Tag 01',
  55. 'applicability': 'taxes'
  56. })
  57. self.tax_tag_02 = self.env['account.account.tag'].create({
  58. 'name': 'Tag 02',
  59. 'applicability': 'taxes'
  60. })
  61. self.tax_tag_03 = self.env['account.account.tag'].create({
  62. 'name': 'Tag 03',
  63. 'applicability': 'taxes'
  64. })
  65. self.tax_group_10 = self.env['account.tax.group'].create({
  66. 'name': 'Tax 10%',
  67. 'sequence': 1
  68. })
  69. self.tax_group_20 = self.env['account.tax.group'].create({
  70. 'name': 'Tax 20%',
  71. 'sequence': 2
  72. })
  73. self.tax_10 = self.env['account.tax'].create({
  74. 'name': 'Tax 10.0%',
  75. 'amount': 10.0,
  76. 'amount_type': 'percent',
  77. 'type_tax_use': 'sale',
  78. 'account_id': self.tax_account.id,
  79. 'refund_account_id': self.tax_account.id,
  80. 'tax_group_id': self.tax_group_10.id,
  81. 'tag_ids': [(6, 0, [self.tax_tag_01.id, self.tax_tag_02.id])]
  82. })
  83. self.tax_20 = self.env['account.tax'].create({
  84. 'sequence': 30,
  85. 'name': 'Tax 20.0%',
  86. 'amount': 20.0,
  87. 'amount_type': 'percent',
  88. 'type_tax_use': 'sale',
  89. 'tax_exigibility': 'on_payment',
  90. 'account_id': self.tax_account.id,
  91. 'refund_account_id': self.tax_account.id,
  92. 'cash_basis_account': self.tax_account.id,
  93. 'tax_group_id': self.tax_group_20.id,
  94. 'tag_ids': [(6, 0, [self.tax_tag_02.id, self.tax_tag_03.id])]
  95. })
  96. invoice = self.env['account.invoice'].create({
  97. 'partner_id': self.env.ref('base.res_partner_2').id,
  98. 'account_id': self.receivable_account.id,
  99. 'date_invoice': time.strftime('%Y-%m-03'),
  100. 'type': 'out_invoice',
  101. })
  102. self.env['account.invoice.line'].create({
  103. 'product_id': self.env.ref('product.product_product_4').id,
  104. 'quantity': 1.0,
  105. 'price_unit': 100.0,
  106. 'invoice_id': invoice.id,
  107. 'name': 'product',
  108. 'account_id': self.income_account.id,
  109. 'invoice_line_tax_ids': [(6, 0, [self.tax_10.id])],
  110. })
  111. invoice.compute_taxes()
  112. invoice.action_invoice_open()
  113. self.cbinvoice = self.env['account.invoice'].create({
  114. 'partner_id': self.env.ref('base.res_partner_2').id,
  115. 'account_id': self.receivable_account.id,
  116. 'date_invoice': time.strftime('%Y-%m-05'),
  117. 'type': 'out_invoice',
  118. })
  119. self.env['account.invoice.line'].create({
  120. 'product_id': self.env.ref('product.product_product_4').id,
  121. 'quantity': 1.0,
  122. 'price_unit': 500.0,
  123. 'invoice_id': self.cbinvoice.id,
  124. 'name': 'product',
  125. 'account_id': self.income_account.id,
  126. 'invoice_line_tax_ids': [(6, 0, [self.tax_20.id])],
  127. })
  128. self.cbinvoice.compute_taxes()
  129. self.cbinvoice.action_invoice_open()
  130. def _get_report_lines(self):
  131. company = self.env.ref('base.main_company')
  132. self.cbinvoice.pay_and_reconcile(
  133. self.bank_journal.id, 300, time.strftime('%Y-%m-10'))
  134. vat_report = self.env['report_vat_report'].create({
  135. 'date_from': self.date_from,
  136. 'date_to': self.date_to,
  137. 'company_id': company.id,
  138. 'based_on': 'taxtags',
  139. 'tax_detail': True,
  140. })
  141. vat_report.compute_data_for_report()
  142. lines = {}
  143. vat_taxtag_model = self.env['report_vat_report_taxtag']
  144. lines['tag_01'] = vat_taxtag_model.search([
  145. ('report_id', '=', vat_report.id),
  146. ('taxtag_id', '=', self.tax_tag_01.id),
  147. ])
  148. lines['tag_02'] = vat_taxtag_model.search([
  149. ('report_id', '=', vat_report.id),
  150. ('taxtag_id', '=', self.tax_tag_02.id),
  151. ])
  152. lines['tag_03'] = vat_taxtag_model.search([
  153. ('report_id', '=', vat_report.id),
  154. ('taxtag_id', '=', self.tax_tag_03.id),
  155. ])
  156. vat_tax_model = self.env['report_vat_report_tax']
  157. lines['tax_10'] = vat_tax_model.search([
  158. ('report_tax_id', '=', lines['tag_02'].id),
  159. ('tax_id', '=', self.tax_10.id),
  160. ])
  161. lines['tax_20'] = vat_tax_model.search([
  162. ('report_tax_id', '=', lines['tag_02'].id),
  163. ('tax_id', '=', self.tax_20.id),
  164. ])
  165. vat_report['based_on'] = 'taxgroups'
  166. vat_report.compute_data_for_report()
  167. lines['group_10'] = vat_taxtag_model.search([
  168. ('report_id', '=', vat_report.id),
  169. ('taxgroup_id', '=', self.tax_group_10.id),
  170. ])
  171. lines['group_20'] = vat_taxtag_model.search([
  172. ('report_id', '=', vat_report.id),
  173. ('taxgroup_id', '=', self.tax_group_20.id),
  174. ])
  175. vat_tax_model = self.env['report_vat_report_tax']
  176. lines['tax_group_10'] = vat_tax_model.search([
  177. ('report_tax_id', '=', lines['group_10'].id),
  178. ('tax_id', '=', self.tax_10.id),
  179. ])
  180. lines['tax_group_20'] = vat_tax_model.search([
  181. ('report_tax_id', '=', lines['group_20'].id),
  182. ('tax_id', '=', self.tax_20.id),
  183. ])
  184. return lines
  185. def test_01_compute(self):
  186. # Generate the vat lines
  187. lines = self._get_report_lines()
  188. # Check report based on taxtags
  189. self.assertEqual(len(lines['tag_01']), 1)
  190. self.assertEqual(len(lines['tag_02']), 1)
  191. self.assertEqual(len(lines['tag_03']), 1)
  192. self.assertEqual(len(lines['tax_10']), 1)
  193. self.assertEqual(len(lines['tax_20']), 1)
  194. self.assertEqual(lines['tag_01'].net, 100)
  195. self.assertEqual(lines['tag_01'].tax, 10)
  196. self.assertEqual(lines['tag_02'].net, 350)
  197. self.assertEqual(lines['tag_02'].tax, 60)
  198. self.assertEqual(lines['tag_03'].net, 250)
  199. self.assertEqual(lines['tag_03'].tax, 50)
  200. self.assertEqual(lines['tax_10'].net, 100)
  201. self.assertEqual(lines['tax_10'].tax, 10)
  202. self.assertEqual(lines['tax_20'].net, 250)
  203. self.assertEqual(lines['tax_20'].tax, 50)
  204. # Check report based on taxgroups
  205. self.assertEqual(len(lines['group_10']), 1)
  206. self.assertEqual(len(lines['group_20']), 1)
  207. self.assertEqual(len(lines['tax_group_10']), 1)
  208. self.assertEqual(len(lines['tax_group_20']), 1)
  209. self.assertEqual(lines['group_10'].net, 100)
  210. self.assertEqual(lines['group_10'].tax, 10)
  211. self.assertEqual(lines['group_20'].net, 250)
  212. self.assertEqual(lines['group_20'].tax, 50)
  213. self.assertEqual(lines['tax_group_10'].net, 100)
  214. self.assertEqual(lines['tax_group_10'].tax, 10)
  215. self.assertEqual(lines['tax_group_20'].net, 250)
  216. self.assertEqual(lines['tax_group_20'].tax, 50)
  217. def test_get_report_html(self):
  218. company = self.env.ref('base.main_company')
  219. vat_report = self.env['report_vat_report'].create({
  220. 'date_from': self.date_from,
  221. 'date_to': self.date_to,
  222. 'company_id': company.id,
  223. 'tax_detail': True,
  224. })
  225. vat_report.compute_data_for_report()
  226. vat_report.get_html(given_context={})
  227. def test_wizard_date_range(self):
  228. vat_wizard = self.env['vat.report.wizard']
  229. date_range = self.env['date.range']
  230. self.type = self.env['date.range.type'].create(
  231. {'name': 'Month',
  232. 'company_id': False,
  233. 'allow_overlap': False})
  234. dt = date_range.create({
  235. 'name': 'FS2016',
  236. 'date_start': time.strftime('%Y-%m-01'),
  237. 'date_end': time.strftime('%Y-%m-28'),
  238. 'type_id': self.type.id,
  239. })
  240. wizard = vat_wizard.create(
  241. {'date_range_id': dt.id,
  242. 'date_from': time.strftime('%Y-%m-28'),
  243. 'date_to': time.strftime('%Y-%m-01'),
  244. 'tax_detail': True})
  245. wizard.onchange_date_range_id()
  246. self.assertEqual(wizard.date_from, time.strftime('%Y-%m-01'))
  247. self.assertEqual(wizard.date_to, time.strftime('%Y-%m-28'))
  248. wizard._export('qweb-pdf')
  249. wizard.button_export_html()
  250. wizard.button_export_pdf()
  251. wizard.button_export_xlsx()
  252. wizard = vat_wizard.create(
  253. {'date_range_id': dt.id,
  254. 'date_from': time.strftime('%Y-%m-28'),
  255. 'date_to': time.strftime('%Y-%m-01'),
  256. 'based_on': 'taxgroups',
  257. 'tax_detail': True})
  258. wizard.onchange_date_range_id()
  259. self.assertEqual(wizard.date_from, time.strftime('%Y-%m-01'))
  260. self.assertEqual(wizard.date_to, time.strftime('%Y-%m-28'))
  261. wizard._export('qweb-pdf')
  262. wizard.button_export_html()
  263. wizard.button_export_pdf()
  264. wizard.button_export_xlsx()