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.

83 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 import _
  5. from odoo.fields import Date
  6. def date_validator(field, value, error):
  7. try:
  8. Date.from_string(value)
  9. except ValueError as e:
  10. return error(
  11. field, _("{} does not match format '%Y-%m-%d'".format(value))
  12. )
  13. # todo consistency: S_SR_GET, S_SR_RETURN_GET, S_SR_POST ...
  14. # and denormalize dict rather than updating them
  15. S_SUBSCRIPTION_REQUEST_BASE = {
  16. "name": {"type": "string", "required": True, "empty": False},
  17. "email": {"type": "string", "required": True, "empty": False},
  18. "ordered_parts": {"type": "integer", "required": True},
  19. "address": {
  20. "type": "dict",
  21. "schema": {
  22. "street": {"type": "string", "required": True, "empty": False},
  23. "zip_code": {"type": "string", "required": True, "empty": False},
  24. "city": {"type": "string", "required": True, "empty": False},
  25. "country": {"type": "string", "required": True, "empty": False},
  26. },
  27. },
  28. "lang": {"type": "string", "required": True, "empty": False},
  29. }
  30. S_SUBSCRIPTION_REQUEST_GET = {
  31. **S_SUBSCRIPTION_REQUEST_BASE,
  32. **{
  33. "id": {"type": "integer", "required": True},
  34. "date": {"type": "string", "required": True, "empty": False},
  35. "state": {"type": "string", "required": True, "empty": False},
  36. "share_product": {
  37. "type": "dict",
  38. "schema": {
  39. "id": {"type": "integer", "required": True},
  40. "name": {"type": "string", "required": True, "empty": False},
  41. },
  42. },
  43. },
  44. }
  45. S_SUBSCRIPTION_REQUEST_CREATE = {
  46. **S_SUBSCRIPTION_REQUEST_BASE,
  47. **{"share_product": {"type": "integer", "required": True}},
  48. }
  49. S_SUBSCRIPTION_REQUEST_UPDATE = {
  50. "name": {"type": "string"},
  51. "email": {"type": "string"},
  52. "ordered_parts": {"type": "integer"},
  53. "state": {"type": "string"},
  54. "address": {
  55. "type": "dict",
  56. "schema": {
  57. "street": {"type": "string"},
  58. "zip_code": {"type": "string"},
  59. "city": {"type": "string"},
  60. "country": {"type": "string"},
  61. },
  62. },
  63. "lang": {"type": "string"},
  64. "share_product": {"type": "integer"},
  65. }
  66. S_SUBSCRIPTION_REQUEST_LIST = {
  67. "count": {"type": "integer", "required": True},
  68. "rows": {
  69. "type": "list",
  70. "schema": {"type": "dict", "schema": S_SUBSCRIPTION_REQUEST_GET},
  71. },
  72. }