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.

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