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.

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