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.

114 lines
4.1 KiB

  1. # Copyright 2018 ForgeFlow, S.L. (https://www.forgeflow.com)
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from datetime import date
  4. from odoo import fields
  5. from odoo.tests.common import TransactionCase
  6. class TestActivityStatement(TransactionCase):
  7. """ Tests for Activity Statement."""
  8. def setUp(self):
  9. super().setUp()
  10. self.res_users_model = self.env["res.users"]
  11. self.company = self.env.ref("base.main_company")
  12. self.company.external_report_layout_id = self.env.ref(
  13. "web.external_layout_standard"
  14. )
  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], self.company).id
  19. self.statement_model = self.env["report.partner_statement.activity_statement"]
  20. self.wiz = self.env["activity.statement.wizard"]
  21. self.report_name = "partner_statement.activity_statement"
  22. self.report_title = "Activity Statement"
  23. self.today = fields.Date.context_today(self.wiz)
  24. def _create_user(self, login, groups, company):
  25. group_ids = [group.id for group in groups]
  26. user = self.res_users_model.create(
  27. {
  28. "name": login,
  29. "login": login,
  30. "email": "example@yourcompany.com",
  31. "company_id": company.id,
  32. "company_ids": [(4, company.id)],
  33. "groups_id": [(6, 0, group_ids)],
  34. }
  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(
  57. report, dict, "There was an error while compiling the report."
  58. )
  59. self.assertIn(
  60. "bucket_labels", report, "There was an error while compiling the report."
  61. )
  62. def test_customer_activity_report_no_wizard(self):
  63. docids = [self.partner1.id, self.partner2.id]
  64. report = self.statement_model._get_report_values(docids, False)
  65. self.assertIsInstance(
  66. report, dict, "There was an error while compiling the report."
  67. )
  68. self.assertIn(
  69. "bucket_labels", report, "There was an error while compiling the report."
  70. )
  71. def test_date_formatting(self):
  72. date_fmt = "%d/%m/%Y"
  73. test_date = date(2018, 9, 30)
  74. res = self.statement_model._format_date_to_partner_lang(test_date, date_fmt)
  75. self.assertEqual(res, "30/09/2018")
  76. test_date_string = "2018-09-30"
  77. res = self.statement_model._format_date_to_partner_lang(
  78. test_date_string, date_fmt
  79. )
  80. self.assertEqual(res, "30/09/2018")
  81. def test_onchange_aging_type(self):
  82. """Test that partner data is filled accordingly"""
  83. wiz_id = self.wiz.with_context(
  84. active_ids=[self.partner1.id, self.partner2.id]
  85. ).new()
  86. wiz_id.aging_type = "months"
  87. wiz_id.onchange_aging_type()
  88. self.assertEqual(wiz_id.date_end.month, wiz_id.date_start.month)
  89. self.assertTrue(wiz_id.date_end.day > wiz_id.date_start.day)
  90. self.assertTrue(wiz_id.date_end < self.today)
  91. wiz_id.aging_type = "days"
  92. wiz_id.onchange_aging_type()
  93. self.assertEqual((wiz_id.date_end - wiz_id.date_start).days, 30)
  94. self.assertTrue(wiz_id.date_end == self.today)