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

63 lines
1.6KB

  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from odoo import api, fields, models, Command, _
  4. from odoo.addons.oec_im_wecom_api.api.wecom_abstract_api import ApiException
  5. _logger = logging.getLogger(__name__)
  6. class Partner(models.Model):
  7. _inherit = "res.partner"
  8. wecom_userid = fields.Char(
  9. string="WeCom User ID",
  10. readonly=True,
  11. )
  12. wecom_openid = fields.Char(
  13. string="WeCom OpenID",
  14. readonly=True,
  15. )
  16. is_wecom_user = fields.Boolean(
  17. "Is WeCom user",
  18. readonly=True,
  19. )
  20. qr_code = fields.Char(
  21. string="Personal QR code",
  22. readonly=True,
  23. )
  24. wecom_user_order = fields.Char(
  25. "WeCom User sequence",
  26. default="0",
  27. readonly=True,
  28. )
  29. def get_wecom_openid(self):
  30. """
  31. 获取企微OpenID
  32. """
  33. for partner in self:
  34. print(partner.company_id)
  35. try:
  36. wxapi = self.env["wecom.service_api"].InitServiceApi(
  37. partner.company_id.corpid,
  38. partner.company_id.contacts_app_id.secret,
  39. )
  40. response = wxapi.httpCall(
  41. self.env["wecom.service_api_list"].get_server_api_call(
  42. "USERID_TO_OPENID"
  43. ),
  44. {
  45. "userid": partner.wecom_userid,
  46. },
  47. )
  48. except ApiException as ex:
  49. self.env["wecomapi.tools.action"].ApiExceptionDialog(
  50. ex, raise_exception=True
  51. )
  52. else:
  53. partner.wecom_openid = response["openid"]
上海开阖软件有限公司 沪ICP备12045867号-1