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.

110 lines
3.7 KiB

  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. "is_bond": False,
  13. "is_loan": True,
  14. "default_issue": "xx",
  15. "subscription_start_date": Date.today(),
  16. "subscription_end_date": Date.today() + timedelta(days=60),
  17. "user_id": self.ref("easy_my_coop.res_users_manager_emc_demo"),
  18. "term_date": Date.today() + timedelta(days=600), # ?
  19. "rate": 0.03,
  20. "face_value": 100,
  21. "minimum_amount": 4000,
  22. "maximum_amount": 10, # ?
  23. "maximum_amount_per_sub": 1000,
  24. "interest_payment": "yearly",
  25. "by_company": True,
  26. "by_individual": True,
  27. "display_on_website": True,
  28. "taxes_rate": 0.08,
  29. }
  30. self.as_emc_manager()
  31. loan_issue = self.env["loan.issue"].create(loan_issue_values)
  32. loan_issue.action_confirm()
  33. loan_issue.action_open()
  34. loan_issue.action_cancel()
  35. loan_issue.action_draft()
  36. loan_issue.action_open()
  37. def test_emc_user_cannot_manager_loan_issue(self):
  38. self.as_emc_user()
  39. loan_issue_values = {
  40. "name": "test loan issue",
  41. "is_bond": False,
  42. "is_loan": True,
  43. "default_issue": True,
  44. "user_id": self.ref("easy_my_coop.res_users_manager_emc_demo"),
  45. "subscription_start_date": Date.today(),
  46. "subscription_end_date": Date.today() + timedelta(days=60),
  47. "term_date": Date.today() + timedelta(days=600), # ?
  48. "rate": 0.03,
  49. "face_value": 100,
  50. "minimum_amount": 2000,
  51. "maximum_amount": 10000, # ?
  52. "maximum_amount_per_sub": 1000,
  53. "interest_payment": "yearly",
  54. "by_company": True,
  55. "by_individual": True,
  56. "display_on_website": True,
  57. "taxes_rate": 0.08,
  58. }
  59. with self.assertRaises(AccessError):
  60. self.env["loan.issue"].create(loan_issue_values)
  61. loan_issue = self.browse_ref("easy_my_coop_loan.loan_issue_1_demo")
  62. with self.assertRaises(AccessError):
  63. loan_issue.name = "some name"
  64. with self.assertRaises(AccessError):
  65. loan_issue.action_confirm()
  66. with self.assertRaises(AccessError):
  67. loan_issue.action_open()
  68. with self.assertRaises(AccessError):
  69. loan_issue.action_cancel()
  70. with self.assertRaises(AccessError):
  71. loan_issue.action_draft()
  72. with self.assertRaises(AccessError):
  73. loan_issue.action_open()
  74. self.as_emc_manager()
  75. loan_issue_manager = self.browse_ref(
  76. "easy_my_coop_loan.loan_issue_1_demo"
  77. )
  78. loan_issue_manager.action_confirm()
  79. loan_issue_manager.action_open()
  80. self.as_emc_user()
  81. line = self.env["loan.issue.line"].create(
  82. {
  83. "loan_issue_id": loan_issue.id,
  84. "quantity": 3,
  85. "partner_id": self.browse_ref(
  86. "easy_my_coop.res_partner_cooperator_4_demo"
  87. ).id,
  88. }
  89. )
  90. line.action_validate()
  91. line.action_cancel()
  92. line.action_draft()
  93. line.action_validate()
  94. line.action_request_payment()
  95. line.action_paid()
  96. loan_issue.compute_loan_interest()