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.

174 lines
6.2 KiB

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.fields import Date
  5. from odoo.exceptions import AccessError
  6. from .test_base import EMCBaseCase
  7. class EMCCase(EMCBaseCase):
  8. def setUp(self):
  9. super(EMCCase, self).setUp()
  10. self.request = self.browse_ref(
  11. "easy_my_coop.subscription_request_1_demo"
  12. )
  13. self.bank_journal_euro = self.env["account.journal"].create(
  14. {"name": "Bank", "type": "bank", "code": "BNK67"}
  15. )
  16. self.payment_method_manual_in = self.env.ref(
  17. "account.account_payment_method_manual_in"
  18. )
  19. def test_put_on_waiting_list(self):
  20. self.as_emc_user()
  21. self.request.put_on_waiting_list()
  22. self.assertEquals(self.request.state, "waiting")
  23. def test_validate_subscription_request(self):
  24. self.as_emc_user()
  25. self.request.validate_subscription_request()
  26. self.assertEquals(self.request.state, "done")
  27. self.assertTrue(self.request.partner_id)
  28. self.assertTrue(self.request.partner_id.coop_candidate)
  29. self.assertFalse(self.request.partner_id.member)
  30. self.assertEquals(self.request.type, "new")
  31. self.assertTrue(len(self.request.capital_release_request) >= 1)
  32. self.assertEquals(self.request.capital_release_request.state, "open")
  33. self.assertTrue(self.request.capital_release_request.sent)
  34. def test_register_payment_for_capital_release(self):
  35. self.as_emc_user()
  36. self.request.validate_subscription_request()
  37. invoice = self.request.capital_release_request
  38. ctx = {"active_model": "account.invoice", "active_ids": [invoice.id]}
  39. register_payments = (
  40. self.env["account.register.payments"]
  41. .with_context(ctx)
  42. .create(
  43. {
  44. "payment_date": Date.today(),
  45. "journal_id": self.bank_journal_euro.id,
  46. "payment_method_id": self.payment_method_manual_in.id,
  47. }
  48. )
  49. )
  50. register_payments.create_payments()
  51. self.assertEquals(self.request.capital_release_request.state, "paid")
  52. partner = self.request.partner_id
  53. self.assertFalse(partner.coop_candidate)
  54. self.assertTrue(partner.member)
  55. self.assertTrue(partner.share_ids)
  56. self.assertEquals(self.request.partner_id.effective_date, Date.today())
  57. share = partner.share_ids[0]
  58. self.assertEquals(share.share_number, self.request.ordered_parts)
  59. self.assertEquals(
  60. share.share_product_id, self.request.share_product_id
  61. )
  62. self.assertEquals(share.effective_date, Date.today())
  63. def test_user_rights(self):
  64. request_values = {
  65. "name": "test create request",
  66. "email": "test@demo.net",
  67. "address": "schaerbeekstraat",
  68. "zip_code": "1111",
  69. "city": "Brussels",
  70. "country_id": self.ref("base.be"),
  71. "date": Date.today(),
  72. "source": "manual",
  73. "ordered_parts": 3,
  74. "share_product_id": self.ref(
  75. "easy_my_coop.product_template_share_type_2_demo"
  76. ).product_variant_id.id,
  77. "lang": "en_US",
  78. }
  79. # test ir model access for base user
  80. self.as_user()
  81. read_request = self.browse_ref(
  82. "easy_my_coop.subscription_request_1_demo"
  83. )
  84. with self.assertRaises(AccessError):
  85. read_request.name = "test write request"
  86. with self.assertRaises(AccessError):
  87. self.env["subscription.request"].create(request_values)
  88. with self.assertRaises(AccessError):
  89. read_request.unlink()
  90. share_line = self.browse_ref("easy_my_coop.share_line_1_demo")
  91. with self.assertRaises(AccessError):
  92. share_line.share_number = 3
  93. # test ir model access for easy my coop user
  94. self.as_emc_user()
  95. read_request = self.browse_ref(
  96. "easy_my_coop.subscription_request_1_demo"
  97. )
  98. read_request.name = "test write request"
  99. create_request = self.env["subscription.request"].create(
  100. request_values
  101. )
  102. with self.assertRaises(AccessError):
  103. create_request.unlink()
  104. share_line = self.browse_ref("easy_my_coop.share_line_1_demo")
  105. share_line.share_number = 3
  106. with self.assertRaises(AccessError):
  107. share_line.unlink()
  108. share_type = self.browse_ref(
  109. "easy_my_coop.product_template_share_type_1_demo"
  110. )
  111. share_type.list_price = 30
  112. with self.assertRaises(AccessError):
  113. self.env["product.template"].create(
  114. {
  115. "name": "Part C - Client",
  116. "short_name": "Part C",
  117. "is_share": True,
  118. "default_share_product": True,
  119. "force_min_qty": True,
  120. "minimum_quantity": 2,
  121. "by_individual": True,
  122. "by_company": True,
  123. "list_price": 50,
  124. "display_on_website": True,
  125. }
  126. )
  127. with self.assertRaises(AccessError):
  128. share_type.unlink()
  129. # test ir model access for easy my coop manager
  130. self.as_emc_manager()
  131. read_request = self.browse_ref(
  132. "easy_my_coop.subscription_request_1_demo"
  133. )
  134. read_request.name = "test write request"
  135. create_request = self.env["subscription.request"].create(
  136. request_values
  137. )
  138. create_request.unlink()
  139. share_type = self.env["product.template"].create(
  140. {
  141. "name": "Part C - Client",
  142. "short_name": "Part C",
  143. "is_share": True,
  144. "default_share_product": True,
  145. "force_min_qty": True,
  146. "minimum_quantity": 2,
  147. "by_individual": True,
  148. "by_company": True,
  149. "list_price": 50,
  150. "display_on_website": True,
  151. }
  152. )
  153. share_type.list_price = 30
  154. share_type.unlink()