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.

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