中国本土应用
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.

126 lines
3.5KB

  1. # -*- coding: utf-8 -*-
  2. from odoo import models, _
  3. import logging
  4. _logger = logging.getLogger(__name__)
  5. class WecomApiToolsAction(models.AbstractModel):
  6. _name = "wecomapi.tools.action"
  7. _description = "Wecom API Tools - Action"
  8. def ApiExceptionDialog(
  9. self,
  10. ex,
  11. raise_exception=False,
  12. ):
  13. """
  14. API 错误弹框
  15. """
  16. ir_config = self.env["ir.config_parameter"].sudo()
  17. debug = ir_config.get_param("wecom.debug_enabled")
  18. error = self.env["wecom.service_api_error"].get_error_by_code(ex.errCode)
  19. if debug:
  20. _logger.warning(
  21. _("Wecom API error: %s, error name: %s, error message: %s")
  22. % (str(ex.errCode), error["name"], ex.errMsg)
  23. )
  24. if raise_exception:
  25. params = {
  26. "title": _("Failed"),
  27. "message": _(
  28. "Error code: %s,Error description: %s,Error troubleshooting method: %s,Error Details:%s"
  29. )
  30. % (
  31. str(ex.errCode),
  32. str(error["name"]),
  33. error["method"],
  34. ex.errMsg,
  35. ),
  36. "size": "md", # medium
  37. }
  38. action = {
  39. "type": "ir.actions.client",
  40. "tag": "wecom_api_error_dialogs",
  41. "params": {
  42. "title": params["title"],
  43. "size": params["size"],
  44. "code": str(ex.errCode),
  45. "description": str(error["name"]),
  46. "method": str(error["method"]),
  47. "details": ex.errMsg,
  48. },
  49. }
  50. return action
  51. def WecomInfoNotification(self, msg):
  52. """
  53. API 提示信息
  54. """
  55. action = {
  56. "type": "ir.actions.client",
  57. "tag": "display_notification",
  58. "params": {
  59. "title": msg["title"],
  60. "type": "info",
  61. "message": msg["message"],
  62. "sticky": msg["sticky"],
  63. },
  64. }
  65. return action
  66. def WecomSuccessNotification(self, msg):
  67. """
  68. API 成功提示信息
  69. """
  70. params = {
  71. "title": msg["title"],
  72. "type": "success",
  73. "message": msg["message"],
  74. "sticky": msg["sticky"],
  75. }
  76. if "next" in msg:
  77. params.update({"next": msg["next"]})
  78. action = {
  79. "type": "ir.actions.client",
  80. "tag": "display_notification",
  81. "params": params,
  82. }
  83. return action
  84. def WecomWarningNotification(self, msg):
  85. """
  86. API 警告提示信息
  87. """
  88. action = {
  89. "type": "ir.actions.client",
  90. "tag": "display_notification",
  91. "params": {
  92. "title": msg["title"],
  93. "type": "warning",
  94. "message": msg["message"],
  95. "sticky": msg["sticky"],
  96. },
  97. }
  98. return action
  99. def WecomErrorNotification(self, msg):
  100. """
  101. API 错误提示信息
  102. """
  103. action = {
  104. "type": "ir.actions.client",
  105. "tag": "display_notification",
  106. "params": {
  107. "title": msg["title"],
  108. "type": "error",
  109. "message": msg["message"],
  110. "sticky": msg["sticky"],
  111. },
  112. }
  113. return action
上海开阖软件有限公司 沪ICP备12045867号-1