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.

82 lines
2.9 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 odoo.tests.common import TransactionCase
  4. class TestOutstandingStatement(TransactionCase):
  5. """ Tests for Outstanding Statement."""
  6. def setUp(self):
  7. super().setUp()
  8. self.res_users_model = self.env["res.users"]
  9. self.company = self.env.ref("base.main_company")
  10. self.company.external_report_layout_id = self.env.ref(
  11. "web.external_layout_standard"
  12. )
  13. self.partner1 = self.env.ref("base.res_partner_2")
  14. self.partner2 = self.env.ref("base.res_partner_3")
  15. self.g_account_user = self.env.ref("account.group_account_user")
  16. self.user = self._create_user("user_1", [self.g_account_user], self.company).id
  17. self.statement_model = self.env[
  18. "report.partner_statement.outstanding_statement"
  19. ]
  20. self.wiz = self.env["outstanding.statement.wizard"]
  21. self.report_name = "partner_statement.outstanding_statement"
  22. self.report_title = "Outstanding Statement"
  23. def _create_user(self, login, groups, company):
  24. group_ids = [group.id for group in groups]
  25. user = self.res_users_model.create(
  26. {
  27. "name": login,
  28. "login": login,
  29. "email": "example@yourcompany.com",
  30. "company_id": company.id,
  31. "company_ids": [(4, company.id)],
  32. "groups_id": [(6, 0, group_ids)],
  33. }
  34. )
  35. return user
  36. def test_customer_outstanding_statement(self):
  37. wiz_id = self.wiz.with_context(
  38. active_ids=[self.partner1.id, self.partner2.id]
  39. ).create({})
  40. wiz_id.aging_type = "months"
  41. statement = wiz_id.button_export_pdf()
  42. self.assertDictContainsSubset(
  43. {
  44. "type": "ir.actions.report",
  45. "report_name": self.report_name,
  46. "report_type": "qweb-pdf",
  47. },
  48. statement,
  49. "There was an error and the PDF report was not generated.",
  50. )
  51. data = wiz_id._prepare_statement()
  52. docids = data["partner_ids"]
  53. report = self.statement_model._get_report_values(docids, data)
  54. self.assertIsInstance(
  55. report, dict, "There was an error while compiling the report."
  56. )
  57. self.assertIn(
  58. "bucket_labels", report, "There was an error while compiling the report."
  59. )
  60. def test_customer_outstanding_report_no_wizard(self):
  61. docids = [self.partner1.id]
  62. report = self.statement_model._get_report_values(docids, False)
  63. self.assertIsInstance(
  64. report, dict, "There was an error while compiling the report."
  65. )
  66. self.assertIn(
  67. "bucket_labels", report, "There was an error while compiling the report."
  68. )