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.

111 lines
4.1 KiB

  1. # Copyright 2018 Eficent Business and IT Consulting Services S.L.
  2. # (http://www.eficent.com)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from datetime import date
  5. from odoo.tests.common import TransactionCase
  6. from odoo import fields
  7. class TestActivityStatement(TransactionCase):
  8. """
  9. Tests for Activity Statement.
  10. """
  11. def setUp(self):
  12. super().setUp()
  13. self.res_users_model = self.env['res.users']
  14. self.company = self.env.ref('base.main_company')
  15. self.partner1 = self.env.ref('base.res_partner_1')
  16. self.partner2 = self.env.ref('base.res_partner_2')
  17. self.g_account_user = self.env.ref('account.group_account_user')
  18. self.user = self._create_user('user_1', [self.g_account_user],
  19. self.company).id
  20. self.statement_model = \
  21. self.env['report.partner_statement.activity_statement']
  22. self.wiz = self.env['activity.statement.wizard']
  23. self.report_name = 'partner_statement.activity_statement'
  24. self.report_title = 'Activity Statement'
  25. self.today = fields.Date.context_today(self.wiz)
  26. def _create_user(self, login, groups, company):
  27. group_ids = [group.id for group in groups]
  28. user = self.res_users_model.create({
  29. 'name': login,
  30. 'login': login,
  31. 'password': 'demo',
  32. 'email': 'example@yourcompany.com',
  33. 'company_id': company.id,
  34. 'company_ids': [(4, company.id)],
  35. 'groups_id': [(6, 0, group_ids)]
  36. })
  37. return user
  38. def test_customer_activity_statement(self):
  39. wiz_id = self.wiz.with_context(
  40. active_ids=[self.partner1.id, self.partner2.id],
  41. ).create({})
  42. wiz_id.aging_type = 'months'
  43. wiz_id.show_aging_buckets = False
  44. statement = wiz_id.button_export_pdf()
  45. self.assertDictContainsSubset(
  46. {
  47. 'type': 'ir.actions.report',
  48. 'report_name': self.report_name,
  49. 'report_type': 'qweb-pdf',
  50. },
  51. statement,
  52. 'There was an error and the PDF report was not generated.'
  53. )
  54. data = wiz_id._prepare_statement()
  55. docids = data['partner_ids']
  56. report = self.statement_model._get_report_values(docids, data)
  57. self.assertIsInstance(report, dict,
  58. "There was an error while compiling the report.")
  59. self.assertIn("bucket_labels", report,
  60. "There was an error while compiling the report.")
  61. def test_customer_activity_report_no_wizard(self):
  62. docids = [self.partner1.id, self.partner2.id]
  63. report = self.statement_model._get_report_values(docids, False)
  64. self.assertIsInstance(report, dict,
  65. "There was an error while compiling the report.")
  66. self.assertIn("bucket_labels", report,
  67. "There was an error while compiling the report.")
  68. def test_date_formatting(self):
  69. date_fmt = '%d/%m/%Y'
  70. test_date = date(2018, 9, 30)
  71. res = self.statement_model._format_date_to_partner_lang(
  72. test_date, date_fmt
  73. )
  74. self.assertEqual(res, '30/09/2018')
  75. test_date_string = '2018-09-30'
  76. res = self.statement_model._format_date_to_partner_lang(
  77. test_date_string, date_fmt
  78. )
  79. self.assertEqual(res, '30/09/2018')
  80. def test_onchange_aging_type(self):
  81. """Test that partner data is filled accodingly"""
  82. wiz_id = self.wiz.with_context(
  83. active_ids=[self.partner1.id, self.partner2.id],
  84. ).new()
  85. wiz_id.aging_type = 'months'
  86. wiz_id.onchange_aging_type()
  87. self.assertEqual(wiz_id.date_end.month, wiz_id.date_start.month)
  88. self.assertTrue(wiz_id.date_end.day > wiz_id.date_start.day)
  89. self.assertTrue(wiz_id.date_end < self.today)
  90. wiz_id.aging_type = 'days'
  91. wiz_id.onchange_aging_type()
  92. self.assertEqual((wiz_id.date_end - wiz_id.date_start).days, 30)
  93. self.assertTrue(wiz_id.date_end == self.today)