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.

69 lines
2.5 KiB

  1. # Copyright 2020 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.addons.base_rest.controllers.main import _PseudoCollection
  6. from odoo.addons.component.core import WorkContext
  7. from .common import BaseEMCRestCase
  8. class TestAccountPaymentController(BaseEMCRestCase):
  9. @classmethod
  10. def setUpClass(cls, *args, **kwargs):
  11. super().setUpClass(*args, **kwargs)
  12. def setUp(self):
  13. res = super().setUp()
  14. collection = _PseudoCollection("emc.services", self.env)
  15. emc_services_env = WorkContext(
  16. model_name="rest.service.registration", collection=collection
  17. )
  18. self.ap_service = emc_services_env.component(usage="payment")
  19. self.ai_service = emc_services_env.component(usage="invoice")
  20. self.demo_request_1 = self.browse_ref(
  21. "easy_my_coop.subscription_request_1_demo"
  22. )
  23. return res
  24. def test_service_create(self):
  25. self.demo_request_1.validate_subscription_request()
  26. invoice = self.demo_request_1.capital_release_request
  27. journal = self.bank_journal
  28. result = self.ap_service.create(
  29. payment_date=Date.to_string(Date.today()),
  30. amount=self.demo_request_1.subscription_amount,
  31. payment_type="inbound",
  32. payment_method="manual",
  33. communication=invoice.reference,
  34. invoice=invoice.get_api_external_id(),
  35. journal=journal.get_api_external_id(),
  36. )
  37. demo_payment_dict = {
  38. "id": result["id"],
  39. "communication": invoice.reference,
  40. "invoice": {
  41. "id": invoice.get_api_external_id(),
  42. "name": invoice.number,
  43. },
  44. "amount": self.demo_request_1.subscription_amount,
  45. "payment_date": Date.to_string(Date.today()),
  46. "journal": {
  47. "id": self.bank_journal.get_api_external_id(),
  48. "name": self.bank_journal.name,
  49. },
  50. }
  51. self.assertEquals(demo_payment_dict, result)
  52. invoice = self.ai_service.get(invoice.get_api_external_id())
  53. self.assertEquals("paid", invoice["state"])
  54. # def test_route_create(self): # todo
  55. # external_id = self.capital_release.get_api_external_id()
  56. # route = "/api/payment/%s" % external_id
  57. # content = self.http_get_content(route)
  58. # self.assertEquals(self.demo_payment_dict, content)