import logging import requests from odoo import models, fields, api, _ _logger = logging.getLogger(__name__) class JkmPracticeEmployee(models.Model): _inherit = 'hr.employee' _description = '员工信息' we_id = fields.Char(string='企微ID', index=True) def _employee_info_sync(self): url = '/api/get/organization' config = self.env['res.config.settings'].get_values() ret = requests.post((config['ims_url'] + url), json={}, data={}) result = ret.json()['result'] if result['code'] == 200: if result['employee_list']: for employee_info in result['employee_list']: if employee_info['work_email']: hr_employee = self.sudo().search([('work_email', '=', employee_info['work_email'])]) hr_employee.write({'we_id': employee_info['we_id']}) if hr_employee.user_id: hr_employee.user_id.write({'we_employee_id': employee_info['we_id']}) else: logging.info('_employee_info_sync error:%s' % result['message'])