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.

101 lines
3.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 TestAccountInvoiceController(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.ai_service = emc_services_env.component(usage="invoice")
  19. self.share_type_A = self.browse_ref(
  20. "easy_my_coop.product_template_share_type_1_demo"
  21. )
  22. self._capital_release_create()
  23. today = Date.to_string(Date.today())
  24. self.demo_invoice_dict = {
  25. "id": 1,
  26. "name": "Capital Release Example",
  27. "partner": {"id": 1, "name": "Catherine des Champs"},
  28. "account": {"id": 1, "name": "Cooperators"},
  29. "journal": {"id": 1, "name": "Subscription Journal"},
  30. "subscription_request": {},
  31. "state": "open",
  32. "date": today,
  33. "date_invoice": today,
  34. "date_due": today,
  35. "type": "out_invoice",
  36. "invoice_lines": [
  37. {
  38. "name": "Share Type A",
  39. "product": {"id": 1, "name": "Part A - Founder"},
  40. "price_unit": 100.0,
  41. "quantity": 2.0,
  42. "account": {"id": 2, "name": "Equity"},
  43. }
  44. ],
  45. }
  46. return res
  47. def _capital_release_create(self):
  48. self.coop_candidate = self.env["res.partner"].create(
  49. {
  50. "name": "Catherine des Champs",
  51. "company_id": self.company.id,
  52. "property_account_receivable_id": self.receivable.id,
  53. "property_account_payable_id": self.payable.id,
  54. }
  55. )
  56. capital_release_line = [
  57. (
  58. 0,
  59. False,
  60. {
  61. "name": "Share Type A",
  62. "account_id": self.equity_account.id,
  63. "quantity": 2.0,
  64. "price_unit": 100.0,
  65. "product_id": self.share_type_A.product_variant_id.id,
  66. },
  67. )
  68. ]
  69. self.capital_release = self.env["account.invoice"].create(
  70. {
  71. "name": "Capital Release Example",
  72. "partner_id": self.coop_candidate.id,
  73. "type": "out_invoice",
  74. "invoice_line_ids": capital_release_line,
  75. "account_id": self.cooperator_account.id,
  76. "journal_id": self.subscription_journal.id,
  77. }
  78. )
  79. self.capital_release.action_invoice_open()
  80. def test_service_get(self):
  81. external_id = self.capital_release.get_api_external_id()
  82. result = self.ai_service.get(external_id)
  83. self.assertEquals(self.demo_invoice_dict, result)
  84. def test_route_get(self):
  85. external_id = self.capital_release.get_api_external_id()
  86. route = "/api/invoice/%s" % external_id
  87. content = self.http_get_content(route)
  88. self.assertEquals(self.demo_invoice_dict, content)