From 9e92b1368ecab0dff0ba30d8927d08068f56d5ee Mon Sep 17 00:00:00 2001 From: pengyuthon Date: Sun, 30 Jun 2024 20:56:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=20?= =?UTF-8?q?=E9=80=9A=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_wechat/models/wecom_api.py | 2 +- yuthon_wechat/models/wecom_apps.py | 4 ++-- yuthon_wechat/models/wecom_apps_config.py | 2 +- yuthon_wechat/wizard/wecom_api_sync_wizard.py | 7 +++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/yuthon_wechat/models/wecom_api.py b/yuthon_wechat/models/wecom_api.py index 99614f8f6..12cdf3fb2 100644 --- a/yuthon_wechat/models/wecom_api.py +++ b/yuthon_wechat/models/wecom_api.py @@ -101,6 +101,6 @@ class WeComApi(models.Model): """ wecom_api = self.search([('function', '=', function)], limit=1) response = wecom_api.http_request_url(data, access_token) - response = json.loads(response) + response = json.loads(response.content) return response diff --git a/yuthon_wechat/models/wecom_apps.py b/yuthon_wechat/models/wecom_apps.py index 52572377e..ac7051c66 100644 --- a/yuthon_wechat/models/wecom_apps.py +++ b/yuthon_wechat/models/wecom_apps.py @@ -35,8 +35,8 @@ class WeComApps(models.Model): def sync_function_api(self, apps_type, api_function, data): wecom_app = self.sudo().env["wecom.apps.config"].search([("wecom_apps_type", "=", apps_type)], limit=1).wecom_apps_id result_data = self.sudo().env['wecom.api'].function_http_request(api_function, data, wecom_app.access_token) - if result_data.get("errcode", 0) in ["40014"]: - self.sync_access_token() + if result_data.get("errcode", 0) in [40014]: + wecom_app.sync_access_token() wecom_app = self.sudo().env["wecom.apps.config"].search([("wecom_apps_type", "=", apps_type)],limit=1).wecom_apps_id result_data = self.sudo().env['wecom.api'].function_http_request(api_function, data, wecom_app.access_token) return result_data diff --git a/yuthon_wechat/models/wecom_apps_config.py b/yuthon_wechat/models/wecom_apps_config.py index c03cb864d..67d0ed0be 100644 --- a/yuthon_wechat/models/wecom_apps_config.py +++ b/yuthon_wechat/models/wecom_apps_config.py @@ -13,7 +13,7 @@ class WecomAppsConfig(models.Model): wecom_apps_type = fields.Selection( string='应用分类', selection=[('default', '暂未启用功能'), - ('USER_LIST', '通讯录同步应用'), + ('USER_LIST', '员工同步应用'), ('DEPARTMENT_LIST', '部门同步应用'), ('login', '登录验证应用'), ('SEND_MESSAGE', '发送消息应用'), diff --git a/yuthon_wechat/wizard/wecom_api_sync_wizard.py b/yuthon_wechat/wizard/wecom_api_sync_wizard.py index 77015d51b..639ab6aab 100644 --- a/yuthon_wechat/wizard/wecom_api_sync_wizard.py +++ b/yuthon_wechat/wizard/wecom_api_sync_wizard.py @@ -28,8 +28,8 @@ class WeComApiSyncWizard(models.Model): wecom_name_en = department.get("name_en", "") wecom_department_leader = department.get("department_leader", "") wecom_order = department.get("order", "") - wecom_parent_id = department.get("parent_id", 0) - hr_departments = self.sudo().env["hr.department"].with_context(active_test=False).search([("name", '=', name)]) + wecom_parent_id = department.get("parentid", 0) + hr_departments = self.sudo().env["hr.department"].with_context(active_test=False).search([("wecom_id", '=', wecom_id)]) data = { "name": name, "wecom_id": wecom_id, @@ -56,8 +56,7 @@ class WeComApiSyncWizard(models.Model): # 开始按照部门逐步获取员工 hr_departments = self.sudo().env["hr.department"].search([("wecom_id", "!=", False)]) for hr_department in hr_departments: - wecom_departments = self.sudo().env["wecom.apps"].sync_department_list() - user_list = wecom_departments.sync_user_list(hr_department.wecom_id) + user_list = self.sudo().env["wecom.apps"].sync_user_list(hr_department.wecom_id) for user in user_list: biz_mail = user.get("biz_mail", "") userid = user.get("userid", "")