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.

77 lines
2.9 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. 'password': 'demo',
  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. return user
  35. def test_customer_outstanding_statement(self):
  36. wiz_id = self.wiz.with_context(
  37. active_ids=[self.partner1.id, self.partner2.id],
  38. ).create({})
  39. wiz_id.aging_type = 'months'
  40. statement = wiz_id.button_export_pdf()
  41. self.assertDictContainsSubset(
  42. {
  43. 'type': 'ir.actions.report',
  44. 'report_name': self.report_name,
  45. 'report_type': 'qweb-pdf',
  46. },
  47. statement,
  48. 'There was an error and the PDF report was not generated.'
  49. )
  50. data = wiz_id._prepare_statement()
  51. docids = data['partner_ids']
  52. report = self.statement_model._get_report_values(docids, data)
  53. self.assertIsInstance(report,
  54. dict,
  55. "There was an error while compiling the report.")
  56. self.assertIn("bucket_labels", report,
  57. "There was an error while compiling the report.")
  58. def test_customer_outstanding_report_no_wizard(self):
  59. docids = [self.partner1.id]
  60. report = self.statement_model._get_report_values(docids, False)
  61. self.assertIsInstance(report, dict,
  62. "There was an error while compiling the report.")
  63. self.assertIn("bucket_labels", report,
  64. "There was an error while compiling the report.")