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.

110 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. 'email': 'example@yourcompany.com',
  32. 'company_id': company.id,
  33. 'company_ids': [(4, company.id)],
  34. 'groups_id': [(6, 0, group_ids)]
  35. })
  36. return user
  37. def test_customer_activity_statement(self):
  38. wiz_id = self.wiz.with_context(
  39. active_ids=[self.partner1.id, self.partner2.id],
  40. ).create({})
  41. wiz_id.aging_type = 'months'
  42. wiz_id.show_aging_buckets = False
  43. statement = wiz_id.button_export_pdf()
  44. self.assertDictContainsSubset(
  45. {
  46. 'type': 'ir.actions.report',
  47. 'report_name': self.report_name,
  48. 'report_type': 'qweb-pdf',
  49. },
  50. statement,
  51. 'There was an error and the PDF report was not generated.'
  52. )
  53. data = wiz_id._prepare_statement()
  54. docids = data['partner_ids']
  55. report = self.statement_model._get_report_values(docids, data)
  56. self.assertIsInstance(report, dict,
  57. "There was an error while compiling the report.")
  58. self.assertIn("bucket_labels", report,
  59. "There was an error while compiling the report.")
  60. def test_customer_activity_report_no_wizard(self):
  61. docids = [self.partner1.id, self.partner2.id]
  62. report = self.statement_model._get_report_values(docids, False)
  63. self.assertIsInstance(report, dict,
  64. "There was an error while compiling the report.")
  65. self.assertIn("bucket_labels", report,
  66. "There was an error while compiling the report.")
  67. def test_date_formatting(self):
  68. date_fmt = '%d/%m/%Y'
  69. test_date = date(2018, 9, 30)
  70. res = self.statement_model._format_date_to_partner_lang(
  71. test_date, date_fmt
  72. )
  73. self.assertEqual(res, '30/09/2018')
  74. test_date_string = '2018-09-30'
  75. res = self.statement_model._format_date_to_partner_lang(
  76. test_date_string, date_fmt
  77. )
  78. self.assertEqual(res, '30/09/2018')
  79. def test_onchange_aging_type(self):
  80. """Test that partner data is filled accodingly"""
  81. wiz_id = self.wiz.with_context(
  82. active_ids=[self.partner1.id, self.partner2.id],
  83. ).new()
  84. wiz_id.aging_type = 'months'
  85. wiz_id.onchange_aging_type()
  86. self.assertEqual(wiz_id.date_end.month, wiz_id.date_start.month)
  87. self.assertTrue(wiz_id.date_end.day > wiz_id.date_start.day)
  88. self.assertTrue(wiz_id.date_end < self.today)
  89. wiz_id.aging_type = 'days'
  90. wiz_id.onchange_aging_type()
  91. self.assertEqual((wiz_id.date_end - wiz_id.date_start).days, 30)
  92. self.assertTrue(wiz_id.date_end == self.today)