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.

75 lines
2.2 KiB

  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.component.core import Component
  5. from odoo.fields import Date
  6. from . import schemas
  7. class SubscriptionRequestService(Component):
  8. _inherit = "base.rest.service"
  9. _name = "subscription.request.services"
  10. _usage = "subscription_request" # service_name
  11. _collection = "emc.services"
  12. _description = """
  13. Subscription requests
  14. """
  15. def _to_dict(self, sr):
  16. sr.ensure_one()
  17. return {
  18. "id": sr.id,
  19. "name": sr.name,
  20. "email": sr.email,
  21. "date": Date.to_string(sr.date),
  22. "ordered_parts": sr.ordered_parts,
  23. "share_product": {
  24. "id": sr.share_product_id.id,
  25. "name": sr.share_product_id.name,
  26. },
  27. "address": {
  28. "street": sr.address,
  29. "zip_code": sr.zip_code,
  30. "city": sr.city,
  31. "country": sr.country_id.code,
  32. },
  33. "lang": sr.lang,
  34. }
  35. def get(self, _id):
  36. # fixme remove sudo
  37. sr = self.env["subscription.request"].sudo().search([("id", "=", _id)])
  38. if sr:
  39. return self._to_dict(sr)
  40. else:
  41. raise wrapJsonException(
  42. NotFound(_("No subscription request for id %s") % _id)
  43. )
  44. return {"response": "Get called with message " + message}
  45. def search(self, params=None):
  46. # fixme remove sudo
  47. if params is None:
  48. requests = self.env["subscription.request"].sudo().search([])
  49. else:
  50. requests = self.env["subscription.request"].sudo().search([])
  51. response = {
  52. "count": len(requests),
  53. "rows": [self._to_dict(sr) for sr in requests],
  54. }
  55. return response
  56. def _validator_get(self):
  57. return {"_id": {"type": "integer"}}
  58. def _validator_return_get(self):
  59. return schemas.S_SUBSCRIPTION_REQUEST
  60. def _validator_search(self):
  61. return {}
  62. def _validator_return_search(self):
  63. return schemas.S_SUBSCRIPTION_REQUEST_LIST