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.

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