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

106 lines
2.7KB

  1. # -*- coding: utf-8 -*-
  2. from PIL import Image
  3. import os
  4. import base64
  5. import random
  6. import html2text
  7. import platform
  8. import hashlib
  9. from passlib.context import CryptContext
  10. from odoo import api, models, tools, _
  11. from odoo.modules.module import get_module_resource
  12. from datetime import datetime, timedelta
  13. import logging
  14. _logger = logging.getLogger(__name__)
  15. class WxTools(models.AbstractModel):
  16. _name = "wecom.tools"
  17. _description = "Wecom Tools"
  18. def recipients_split(text):
  19. """
  20. 使用 | 拆分企业微信消息的接收对象
  21. """
  22. if not text:
  23. return []
  24. def wecom_user_enable(self):
  25. """
  26. 企业微信用户是否启用
  27. :param value:
  28. :return:
  29. """
  30. if self.value == "0":
  31. self.result = False
  32. if self.value == "1":
  33. self.result = True
  34. return self.result
  35. def encode_avatar_image_as_base64(self, gender):
  36. if gender == "1":
  37. default_image = get_module_resource(
  38. "oec_im_wecom_api", "static/src/img", "default_male_image.png"
  39. )
  40. elif gender == "2":
  41. default_image = get_module_resource(
  42. "oec_im_wecom_api",
  43. "static/src/img",
  44. "default_female_image.png",
  45. )
  46. else:
  47. default_image = get_module_resource(
  48. "oec_im_wecom_api", "static/src/img", "default_image.png"
  49. )
  50. with open(default_image, "rb") as f:
  51. return base64.b64encode(f.read())
  52. def get_default_avatar_url(self, gender):
  53. params = self.env["ir.config_parameter"].sudo()
  54. base_url = params.get_param("web.base.url")
  55. if gender == "1":
  56. default_image_url = (
  57. base_url + "/oec_im_wecom_api/static/src/img/default_male_image.png"
  58. )
  59. elif gender == "2":
  60. default_image_url = (
  61. base_url + "/oec_im_wecom_api/static/src/img/default_female_image.png"
  62. )
  63. return default_image_url
  64. def encode_image_as_base64(self):
  65. if not self.value:
  66. pass
  67. else:
  68. with open(self.value, "rb") as f:
  69. encoded_string = base64.b64encode(f.read())
  70. return encoded_string
  71. def is_exists(self):
  72. """
  73. 判断是否存在值
  74. :return:
  75. """
  76. if not self.value:
  77. self.result = False
  78. else:
  79. self.result = True
  80. return self.result
  81. def mail_is_exists(self):
  82. """
  83. 判断是否存在值
  84. :return:
  85. """
  86. if not self.value:
  87. self.result = ""
  88. else:
  89. self.result = self.value
  90. return self.result
上海开阖软件有限公司 沪ICP备12045867号-1