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.

104 lines
3.5 KiB

5 years ago
5 years ago
5 years ago
  1. # Copyright 2019 Coop IT Easy SCRL fs
  2. # Robin Keunen <robin@coopiteasy.be>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from odoo.addons.easy_my_coop.tests.test_base import EMCBaseCase
  5. from odoo.fields import Date
  6. from datetime import timedelta
  7. from odoo.exceptions import AccessError
  8. class EMCLoanCase(EMCBaseCase):
  9. def test_complete_loan_flow(self):
  10. loan_issue_values = {
  11. "name": "test loan issue",
  12. "default_issue": "xx",
  13. "subscription_start_date": Date.today(),
  14. "subscription_end_date": Date.today() + timedelta(days=60),
  15. "user_id": self.ref("easy_my_coop.res_users_manager_emc_demo"),
  16. "term_date": Date.today() + timedelta(days=600), # ?
  17. "rate": 0.03,
  18. "face_value": 100,
  19. "minimum_amount": 4000,
  20. "maximum_amount": 10, # ?
  21. "interest_payment": "end",
  22. "by_company": True,
  23. "by_individual": True,
  24. "display_on_website": True,
  25. "taxes_rate": 0.08,
  26. }
  27. self.as_emc_manager()
  28. loan_issue = self.env["loan.issue"].create(loan_issue_values)
  29. loan_issue.action_confirm()
  30. loan_issue.action_open()
  31. loan_issue.action_cancel()
  32. loan_issue.action_draft()
  33. loan_issue.action_open()
  34. def test_emc_user_cannot_manage_loan_issue(self):
  35. self.as_emc_user()
  36. loan_issue_values = {
  37. "name": "test loan issue",
  38. "default_issue": True,
  39. "user_id": self.ref("easy_my_coop.res_users_manager_emc_demo"),
  40. "subscription_start_date": Date.today(),
  41. "subscription_end_date": Date.today() + timedelta(days=60),
  42. "term_date": Date.today() + timedelta(days=600), # ?
  43. "rate": 0.03,
  44. "face_value": 100,
  45. "minimum_amount": 2000,
  46. "maximum_amount": 10000, # ?
  47. "interest_payment": "end",
  48. "by_company": True,
  49. "by_individual": True,
  50. "display_on_website": True,
  51. "taxes_rate": 0.08,
  52. }
  53. with self.assertRaises(AccessError):
  54. self.env["loan.issue"].create(loan_issue_values)
  55. loan_issue = self.browse_ref("easy_my_coop_loan.loan_issue_1_demo")
  56. with self.assertRaises(AccessError):
  57. loan_issue.name = "some name"
  58. with self.assertRaises(AccessError):
  59. loan_issue.action_confirm()
  60. with self.assertRaises(AccessError):
  61. loan_issue.action_open()
  62. with self.assertRaises(AccessError):
  63. loan_issue.action_cancel()
  64. with self.assertRaises(AccessError):
  65. loan_issue.action_draft()
  66. with self.assertRaises(AccessError):
  67. loan_issue.action_open()
  68. self.as_emc_manager()
  69. loan_issue_manager = self.browse_ref(
  70. "easy_my_coop_loan.loan_issue_1_demo"
  71. )
  72. loan_issue_manager.action_confirm()
  73. loan_issue_manager.action_open()
  74. self.as_emc_user()
  75. line = self.env["loan.issue.line"].create(
  76. {
  77. "loan_issue_id": loan_issue.id,
  78. "quantity": 3,
  79. "partner_id": self.browse_ref(
  80. "easy_my_coop.res_partner_cooperator_4_demo"
  81. ).id,
  82. }
  83. )
  84. line.action_validate()
  85. line.action_cancel()
  86. line.action_draft()
  87. line.action_validate()
  88. line.action_request_payment()
  89. line.action_paid()
  90. loan_issue.compute_loan_interest()