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.

337 lines
11 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 ACSONE SA/NV
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import time
  5. from datetime import datetime
  6. from dateutil.relativedelta import relativedelta
  7. from odoo.fields import Date
  8. from odoo.tests.common import TransactionCase
  9. from . import abstract_test_foreign_currency as a_t_f_c
  10. class TestJournalLedger(a_t_f_c.AbstractTestForeignCurrency):
  11. """
  12. Technical tests for General Ledger Report.
  13. """
  14. def _getReportModel(self):
  15. return self.env['report_journal_qweb']
  16. def _getQwebReportName(self):
  17. return 'account_financial_report_qweb.report_journal_qweb'
  18. def _getXlsxReportName(self):
  19. return 'account_financial_report_qweb.report_journal_xlsx'
  20. def _getXlsxReportActionName(self):
  21. return 'account_financial_report_qweb.' \
  22. 'action_report_journal_ledger'
  23. def _getReportTitle(self):
  24. return 'Journal Ledger'
  25. def _getBaseFilters(self):
  26. return {
  27. 'date_from': time.strftime('%Y-01-01'),
  28. 'date_to': time.strftime('%Y-12-31'),
  29. 'company_id': self.company.id,
  30. 'journal_ids': [(6, 0, self.journal_sale.ids)]
  31. }
  32. def _getAdditionalFiltersToBeTested(self):
  33. return [
  34. {'move_target': "All",
  35. 'sort_option': "Date",
  36. 'group_option': "Journal",
  37. 'with_account_name': True,
  38. 'foreign_currency': True},
  39. ]
  40. def test_04_compute_data(self):
  41. return True
  42. class TestJournalReport(TransactionCase):
  43. def setUp(self):
  44. super(TestJournalReport, self).setUp()
  45. self.AccountObj = self.env['account.account']
  46. self.InvoiceObj = self.env['account.invoice']
  47. self.JournalObj = self.env['account.journal']
  48. self.JournalReportObj = self.env['journal.report.wizard']
  49. self.MoveObj = self.env['account.move']
  50. self.ReportJournalQweb = self.env['report_journal_qweb']
  51. self.TaxObj = self.env['account.tax']
  52. self.company = self.env.ref('base.main_company')
  53. today = datetime.today()
  54. last_year = today - relativedelta(years=1)
  55. self.previous_fy_date_start = Date.to_string(
  56. last_year.replace(month=1, day=1))
  57. self.previous_fy_date_end = Date.to_string(
  58. last_year.replace(month=12, day=31))
  59. self.fy_date_start = Date.to_string(
  60. today.replace(month=1, day=1))
  61. self.fy_date_end = Date.to_string(
  62. today.replace(month=12, day=31))
  63. self.receivable_account = self.AccountObj.search([
  64. ('user_type_id.name', '=', 'Receivable')
  65. ], limit=1)
  66. self.income_account = self.AccountObj.search([
  67. ('user_type_id.name', '=', 'Income')
  68. ], limit=1)
  69. self.payable_account = self.AccountObj.search([
  70. ('user_type_id.name', '=', 'Payable')
  71. ], limit=1)
  72. self.journal_sale = self.JournalObj.create({
  73. 'name': "Test journal sale",
  74. 'code': "TST-JRNL-S",
  75. 'type': 'sale',
  76. 'company_id': self.company.id,
  77. })
  78. self.journal_purchase = self.JournalObj.create({
  79. 'name': "Test journal purchase",
  80. 'code': "TST-JRNL-P",
  81. 'type': 'sale',
  82. 'company_id': self.company.id,
  83. })
  84. self.tax_15_s = self.TaxObj.create({
  85. 'sequence': 30,
  86. 'name': 'Tax 15.0% (Percentage of Price)',
  87. 'amount': 15.0,
  88. 'amount_type': 'percent',
  89. 'include_base_amount': False,
  90. 'type_tax_use': 'sale',
  91. })
  92. self.tax_20_s = self.TaxObj.create({
  93. 'sequence': 30,
  94. 'name': 'Tax 20.0% (Percentage of Price)',
  95. 'amount': 20.0,
  96. 'amount_type': 'percent',
  97. 'include_base_amount': False,
  98. 'type_tax_use': 'sale',
  99. })
  100. self.tax_15_p = self.TaxObj.create({
  101. 'sequence': 30,
  102. 'name': 'Tax 15.0% (Percentage of Price)',
  103. 'amount': 15.0,
  104. 'amount_type': 'percent',
  105. 'include_base_amount': False,
  106. 'type_tax_use': 'purchase',
  107. })
  108. self.tax_20_p = self.TaxObj.create({
  109. 'sequence': 30,
  110. 'name': 'Tax 20.0% (Percentage of Price)',
  111. 'amount': 20.0,
  112. 'amount_type': 'percent',
  113. 'include_base_amount': False,
  114. 'type_tax_use': 'purchase',
  115. })
  116. self.partner_2 = self.env.ref('base.res_partner_2')
  117. def _add_move(
  118. self, date, journal,
  119. receivable_debit, receivable_credit, income_debit, income_credit):
  120. move_name = 'move name'
  121. move_vals = {
  122. 'journal_id': journal.id,
  123. 'date': date,
  124. 'line_ids': [
  125. (0, 0, {
  126. 'name': move_name,
  127. 'debit': receivable_debit,
  128. 'credit': receivable_credit,
  129. 'account_id': self.receivable_account.id
  130. }),
  131. (0, 0, {
  132. 'name': move_name,
  133. 'debit': income_debit,
  134. 'credit': income_credit,
  135. 'account_id': self.income_account.id
  136. }),
  137. ]
  138. }
  139. return self.MoveObj.create(move_vals)
  140. def check_report_journal_debit_credit(
  141. self, report, expected_debit, expected_credit):
  142. self.assertEqual(
  143. expected_debit,
  144. sum([journal.debit for journal in report.report_journal_ids])
  145. )
  146. self.assertEqual(
  147. expected_credit,
  148. sum([journal.credit for journal in report.report_journal_ids])
  149. )
  150. def check_report_journal_debit_credit_taxes(
  151. self, report,
  152. expected_base_debit, expected_base_credit,
  153. expected_tax_debit, expected_tax_credit):
  154. self.assertEqual(
  155. expected_base_debit,
  156. sum([
  157. journal.base_debit
  158. for journal in report.report_journal_tax_line_ids
  159. ])
  160. )
  161. self.assertEqual(
  162. expected_base_credit,
  163. sum([
  164. journal.base_credit
  165. for journal in report.report_journal_tax_line_ids
  166. ])
  167. )
  168. self.assertEqual(
  169. expected_tax_debit,
  170. sum([
  171. journal.tax_debit
  172. for journal in report.report_journal_tax_line_ids
  173. ])
  174. )
  175. self.assertEqual(
  176. expected_tax_credit,
  177. sum([
  178. journal.tax_credit
  179. for journal in report.report_journal_tax_line_ids
  180. ])
  181. )
  182. def test_01_test_total(self):
  183. today_date = Date.today()
  184. last_year_date = Date.to_string(
  185. datetime.today() - relativedelta(years=1))
  186. move1 = self._add_move(
  187. today_date, self.journal_sale,
  188. 0, 100, 100, 0)
  189. move2 = self._add_move(
  190. last_year_date, self.journal_sale,
  191. 0, 100, 100, 0)
  192. report = self.ReportJournalQweb.create({
  193. 'date_from': self.fy_date_start,
  194. 'date_to': self.fy_date_end,
  195. 'company_id': self.company.id,
  196. 'journal_ids': [(6, 0, [self.journal_sale.ids])]
  197. })
  198. report.compute_data_for_report()
  199. self.check_report_journal_debit_credit(report, 100, 100)
  200. move3 = self._add_move(
  201. today_date, self.journal_sale,
  202. 0, 100, 100, 0)
  203. report.refresh()
  204. self.check_report_journal_debit_credit(report, 200, 200)
  205. report.move_target = 'posted'
  206. report.refresh()
  207. self.check_report_journal_debit_credit(report, 0, 0)
  208. move1.post()
  209. report.refresh()
  210. self.check_report_journal_debit_credit(report, 100, 100)
  211. move2.post()
  212. report.refresh()
  213. self.check_report_journal_debit_credit(report, 100, 100)
  214. move3.post()
  215. report.refresh()
  216. self.check_report_journal_debit_credit(report, 200, 200)
  217. report.date_from = self.previous_fy_date_start
  218. report.refresh()
  219. self.check_report_journal_debit_credit(report, 300, 300)
  220. def test_02_test_taxes_out_invoice(self):
  221. invoice_values = {
  222. 'journal_id': self.journal_sale.id,
  223. 'partner_id': self.partner_2.id,
  224. 'type': 'out_invoice',
  225. 'invoice_line_ids': [
  226. (0, 0, {
  227. 'quantity': 1.0,
  228. 'price_unit': 100,
  229. 'account_id': self.receivable_account.id,
  230. 'name': "Test",
  231. 'invoice_line_tax_ids': [(6, 0, [self.tax_15_s.id])],
  232. }),
  233. (0, 0, {
  234. 'quantity': 1.0,
  235. 'price_unit': 100,
  236. 'account_id': self.receivable_account.id,
  237. 'name': "Test",
  238. 'invoice_line_tax_ids': [(6, 0, [
  239. self.tax_15_s.id, self.tax_20_s.id
  240. ])],
  241. })
  242. ]
  243. }
  244. invoice = self.InvoiceObj.create(invoice_values)
  245. invoice.action_invoice_open()
  246. report = self.ReportJournalQweb.create({
  247. 'date_from': self.fy_date_start,
  248. 'date_to': self.fy_date_end,
  249. 'company_id': self.company.id,
  250. 'journal_ids': [(6, 0, [self.journal_sale.ids])]
  251. })
  252. report.compute_data_for_report()
  253. self.check_report_journal_debit_credit(report, 250, 250)
  254. self.check_report_journal_debit_credit_taxes(report, 0, 300, 0, 50)
  255. def test_03_test_taxes_in_invoice(self):
  256. invoice_values = {
  257. 'journal_id': self.journal_sale.id,
  258. 'partner_id': self.partner_2.id,
  259. 'type': 'in_invoice',
  260. 'invoice_line_ids': [
  261. (0, 0, {
  262. 'quantity': 1.0,
  263. 'price_unit': 100,
  264. 'account_id': self.payable_account.id,
  265. 'name': "Test",
  266. 'invoice_line_tax_ids': [(6, 0, [self.tax_15_p.id])],
  267. }),
  268. (0, 0, {
  269. 'quantity': 1.0,
  270. 'price_unit': 100,
  271. 'account_id': self.payable_account.id,
  272. 'name': "Test",
  273. 'invoice_line_tax_ids': [(6, 0, [
  274. self.tax_15_p.id, self.tax_20_p.id
  275. ])],
  276. })
  277. ]
  278. }
  279. invoice = self.InvoiceObj.create(invoice_values)
  280. invoice.action_invoice_open()
  281. report = self.ReportJournalQweb.create({
  282. 'date_from': self.fy_date_start,
  283. 'date_to': self.fy_date_end,
  284. 'company_id': self.company.id,
  285. 'journal_ids': [(6, 0, [self.journal_sale.ids])]
  286. })
  287. report.compute_data_for_report()
  288. self.check_report_journal_debit_credit(report, 250, 250)
  289. self.check_report_journal_debit_credit_taxes(report, 300, 0, 50, 0)