test_account_journal_dashboard.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # -*- coding: utf-8 -*-
  2. from freezegun import freeze_time
  3. from odoo.addons.account.tests.common import AccountTestInvoicingCommon
  4. from odoo.tests import tagged
  5. from odoo.tools.misc import format_amount
  6. @tagged('post_install', '-at_install')
  7. class TestAccountJournalDashboard(AccountTestInvoicingCommon):
  8. @freeze_time("2019-01-22")
  9. def test_customer_invoice_dashboard(self):
  10. journal = self.company_data['default_journal_sale']
  11. invoice = self.env['account.move'].create({
  12. 'move_type': 'out_invoice',
  13. 'journal_id': journal.id,
  14. 'partner_id': self.partner_a.id,
  15. 'invoice_date': '2019-01-21',
  16. 'date': '2019-01-21',
  17. 'invoice_line_ids': [(0, 0, {
  18. 'product_id': self.product_a.id,
  19. 'quantity': 40.0,
  20. 'name': 'product test 1',
  21. 'discount': 10.00,
  22. 'price_unit': 2.27,
  23. 'tax_ids': [],
  24. })]
  25. })
  26. refund = self.env['account.move'].create({
  27. 'move_type': 'out_refund',
  28. 'journal_id': journal.id,
  29. 'partner_id': self.partner_a.id,
  30. 'invoice_date': '2019-01-21',
  31. 'date': '2019-01-21',
  32. 'invoice_line_ids': [(0, 0, {
  33. 'product_id': self.product_a.id,
  34. 'quantity': 1.0,
  35. 'name': 'product test 1',
  36. 'price_unit': 13.3,
  37. 'tax_ids': [],
  38. })]
  39. })
  40. # Check Draft
  41. dashboard_data = journal.get_journal_dashboard_datas()
  42. self.assertEqual(dashboard_data['number_draft'], 2)
  43. self.assertIn('68.42', dashboard_data['sum_draft'])
  44. self.assertEqual(dashboard_data['number_waiting'], 0)
  45. self.assertIn('0.00', dashboard_data['sum_waiting'])
  46. # Check Both
  47. invoice.action_post()
  48. dashboard_data = journal.get_journal_dashboard_datas()
  49. self.assertEqual(dashboard_data['number_draft'], 1)
  50. self.assertIn('-\N{ZERO WIDTH NO-BREAK SPACE}13.30', dashboard_data['sum_draft'])
  51. self.assertEqual(dashboard_data['number_waiting'], 1)
  52. self.assertIn('81.72', dashboard_data['sum_waiting'])
  53. # Check waiting payment
  54. refund.action_post()
  55. dashboard_data = journal.get_journal_dashboard_datas()
  56. self.assertEqual(dashboard_data['number_draft'], 0)
  57. self.assertIn('0.00', dashboard_data['sum_draft'])
  58. self.assertEqual(dashboard_data['number_waiting'], 2)
  59. self.assertIn('68.42', dashboard_data['sum_waiting'])
  60. # Check partial
  61. payment = self.env['account.payment'].create({
  62. 'amount': 10.0,
  63. 'payment_type': 'outbound',
  64. 'partner_type': 'customer',
  65. 'partner_id': self.partner_a.id,
  66. })
  67. payment.action_post()
  68. (refund + payment.move_id).line_ids\
  69. .filtered(lambda line: line.account_type == 'asset_receivable')\
  70. .reconcile()
  71. dashboard_data = journal.get_journal_dashboard_datas()
  72. self.assertEqual(dashboard_data['number_draft'], 0)
  73. self.assertIn('0.00', dashboard_data['sum_draft'])
  74. self.assertEqual(dashboard_data['number_waiting'], 2)
  75. self.assertIn('78.42', dashboard_data['sum_waiting'])
  76. dashboard_data = journal.get_journal_dashboard_datas()
  77. self.assertEqual(dashboard_data['number_late'], 2)
  78. self.assertIn('78.42', dashboard_data['sum_late'])
  79. def test_sale_purchase_journal_for_multi_currency_purchase(self):
  80. currency = self.currency_data['currency']
  81. company_currency = self.company_data['currency']
  82. invoice = self.env['account.move'].create({
  83. 'move_type': 'in_invoice',
  84. 'invoice_date': '2017-01-01',
  85. 'date': '2017-01-01',
  86. 'partner_id': self.partner_a.id,
  87. 'currency_id': currency.id,
  88. 'invoice_line_ids': [
  89. (0, 0, {'name': 'test', 'price_unit': 200})
  90. ],
  91. })
  92. invoice.action_post()
  93. payment = self.env['account.payment'].create({
  94. 'amount': 90.0,
  95. 'date': '2016-01-01',
  96. 'payment_type': 'outbound',
  97. 'partner_type': 'supplier',
  98. 'partner_id': self.partner_a.id,
  99. 'currency_id': currency.id,
  100. })
  101. payment.action_post()
  102. (invoice + payment.move_id).line_ids.filtered_domain([
  103. ('account_id', '=', self.company_data['default_account_payable'].id)
  104. ]).reconcile()
  105. dashboard_data = self.company_data['default_journal_purchase'].get_journal_dashboard_datas()
  106. self.assertEqual(format_amount(self.env, 70, company_currency), dashboard_data['sum_waiting'])
  107. self.assertEqual(format_amount(self.env, 70, company_currency), dashboard_data['sum_late'])
  108. def test_sale_purchase_journal_for_multi_currency_sale(self):
  109. currency = self.currency_data['currency']
  110. company_currency = self.company_data['currency']
  111. invoice = self.env['account.move'].create({
  112. 'move_type': 'out_invoice',
  113. 'invoice_date': '2017-01-01',
  114. 'date': '2017-01-01',
  115. 'partner_id': self.partner_a.id,
  116. 'currency_id': currency.id,
  117. 'invoice_line_ids': [
  118. (0, 0, {'name': 'test', 'price_unit': 200})
  119. ],
  120. })
  121. invoice.action_post()
  122. payment = self.env['account.payment'].create({
  123. 'amount': 90.0,
  124. 'date': '2016-01-01',
  125. 'payment_type': 'inbound',
  126. 'partner_type': 'customer',
  127. 'partner_id': self.partner_a.id,
  128. 'currency_id': currency.id,
  129. })
  130. payment.action_post()
  131. (invoice + payment.move_id).line_ids.filtered_domain([
  132. ('account_id', '=', self.company_data['default_account_receivable'].id)
  133. ]).reconcile()
  134. dashboard_data = self.company_data['default_journal_sale'].get_journal_dashboard_datas()
  135. self.assertEqual(format_amount(self.env, 70, company_currency), dashboard_data['sum_waiting'])
  136. self.assertEqual(format_amount(self.env, 70, company_currency), dashboard_data['sum_late'])