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.

202 lines
7.0 KiB

5 years ago
5 years ago
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.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. # todo missing structure fails the rules?
  26. self.request.validate_subscription_request()
  27. self.assertEquals(self.request.state, "done")
  28. self.assertTrue(self.request.partner_id)
  29. self.assertTrue(self.request.partner_id.coop_candidate)
  30. self.assertFalse(self.request.partner_id.member)
  31. self.assertEquals(self.request.type, "new")
  32. self.assertTrue(len(self.request.capital_release_request) >= 1)
  33. self.assertEquals(self.request.capital_release_request.state, "open")
  34. self.assertTrue(self.request.capital_release_request.sent)
  35. def test_register_payment_for_capital_release(self):
  36. self.as_emc_user()
  37. self.request.validate_subscription_request()
  38. invoice = self.request.capital_release_request
  39. ctx = {"active_model": "account.invoice", "active_ids": [invoice.id]}
  40. register_payments = (
  41. self.env["account.register.payments"]
  42. .with_context(ctx)
  43. .create(
  44. {
  45. "payment_date": Date.today(),
  46. "journal_id": self.bank_journal_euro.id,
  47. "payment_method_id": self.payment_method_manual_in.id,
  48. }
  49. )
  50. )
  51. register_payments.create_payments()
  52. self.assertEquals(self.request.capital_release_request.state, "paid")
  53. partner = self.request.partner_id
  54. self.assertFalse(partner.coop_candidate)
  55. self.assertTrue(partner.member)
  56. self.assertTrue(partner.share_ids)
  57. self.assertEquals(self.request.partner_id.effective_date, Date.today())
  58. share = partner.share_ids[0]
  59. self.assertEquals(share.share_number, self.request.ordered_parts)
  60. self.assertEquals(
  61. share.share_product_id, self.request.share_product_id
  62. )
  63. self.assertEquals(share.effective_date, Date.today())
  64. def test_user_rights(self):
  65. request_values = {
  66. "name": "test create request",
  67. "email": "test@demo.net",
  68. "address": "schaerbeekstraat",
  69. "zip_code": "1111",
  70. "city": "Brussels",
  71. "country_id": self.ref("base.be"),
  72. "date": Date.today(),
  73. "source": "manual",
  74. "ordered_parts": 3,
  75. "share_product_id": self.browse_ref(
  76. "easy_my_coop.product_template_share_type_2_demo"
  77. ).product_variant_id.id,
  78. "lang": "en_US",
  79. }
  80. # test ir model access for base user
  81. self.as_user()
  82. read_request = self.browse_ref(
  83. "easy_my_coop.subscription_request_1_demo"
  84. )
  85. with self.assertRaises(AccessError):
  86. read_request.name = "test write request"
  87. with self.assertRaises(AccessError):
  88. self.env["subscription.request"].create(request_values)
  89. with self.assertRaises(AccessError):
  90. read_request.unlink()
  91. share_line = self.browse_ref("easy_my_coop.share_line_1_demo")
  92. with self.assertRaises(AccessError):
  93. share_line.share_number = 3
  94. # test ir model access for easy my coop user
  95. self.as_emc_user()
  96. read_request = self.browse_ref(
  97. "easy_my_coop.subscription_request_1_demo"
  98. )
  99. read_request.name = "test write request"
  100. create_request = self.env["subscription.request"].create(
  101. request_values
  102. )
  103. with self.assertRaises(AccessError):
  104. create_request.unlink()
  105. share_line = self.browse_ref("easy_my_coop.share_line_1_demo")
  106. share_line.share_number = 3
  107. with self.assertRaises(AccessError):
  108. share_line.unlink()
  109. share_type = self.browse_ref(
  110. "easy_my_coop.product_template_share_type_1_demo"
  111. )
  112. share_type.list_price = 30
  113. with self.assertRaises(AccessError):
  114. self.env["product.template"].create(
  115. {
  116. "name": "Part C - Client",
  117. "short_name": "Part C",
  118. "is_share": True,
  119. "default_share_product": True,
  120. "force_min_qty": True,
  121. "minimum_quantity": 2,
  122. "by_individual": True,
  123. "by_company": True,
  124. "list_price": 50,
  125. "display_on_website": True,
  126. }
  127. )
  128. with self.assertRaises(AccessError):
  129. share_type.unlink()
  130. # test ir model access for easy my coop manager
  131. self.as_emc_manager()
  132. read_request = self.browse_ref(
  133. "easy_my_coop.subscription_request_1_demo"
  134. )
  135. read_request.name = "test write request"
  136. create_request = self.env["subscription.request"].create(
  137. request_values
  138. )
  139. create_request.unlink()
  140. share_type = self.env["product.template"].create(
  141. {
  142. "name": "Part C - Client",
  143. "short_name": "Part C",
  144. "is_share": True,
  145. "default_share_product": True,
  146. "force_min_qty": True,
  147. "minimum_quantity": 2,
  148. "by_individual": True,
  149. "by_company": True,
  150. "list_price": 50,
  151. "display_on_website": True,
  152. }
  153. )
  154. share_type.list_price = 30
  155. share_type.unlink()
  156. def test_validated_lines_on_subscription_request(self):
  157. request = self.request
  158. request.skip_control_ng = False
  159. self.assertFalse(request.skip_control_ng)
  160. self.assertFalse(request.iban)
  161. # empty iban - don't skip
  162. self.assertFalse(request.validated)
  163. # good iban - don't skip
  164. request.skip_control_ng = False
  165. self.request.iban = "BE71096123456769"
  166. self.assertTrue(request.validated)
  167. # wrong iban - don't skip
  168. self.request.iban = "xxxx"
  169. self.assertFalse(request.validated)
  170. # wrong iban - skip
  171. request.skip_control_ng = True
  172. self.assertTrue(request.validated)
  173. # empty iban - skip
  174. self.request.iban = False
  175. self.assertTrue(request.validated)