Example #1
0
 def create_ent_weixin_department(self):
     """
     创建企业微信部门
     :return:
     """
     url, token = self.env['weixin.ent.parameter'].get_token_and_value(
         'department_create', 'ent_wx_ab_token')
     for res in self:
         self._check_parent_id(res)
         data = {
             'name': res.name,
             'parentid': res.parent_id.ent_wx_id,
         }
         result = request_post(url, token, data)
         if result['errcode'] != 0:
             raise UserError(result['errmsg'])
         res.write({'ent_wx_id': result['id']})
         res.message_post(body=u"已成功同步至企业微信部门", message_type='notification')
Example #2
0
 def write_ent_weixin_department(self):
     """
     修改企业微信部门
     :return:
     """
     url, token = self.env['weixin.ent.parameter'].get_token_and_value(
         'department_update', 'ent_wx_ab_token')
     for res in self:
         if not res.ent_wx_id:
             raise UserError("'%s'不是企业微信部门,请先创建或同步到企业微信!" % res.name)
         self._check_parent_id(res)
         data = {
             'id': res.ent_wx_id,
             'name': res.name,
             'parentid': res.parent_id.ent_wx_id,
         }
         result = request_post(url, token, data)
         if result['errcode'] != 0:
             raise UserError(result['errmsg'])
         res.message_post(body=u"已更新至企业微信部门", message_type='notification')
Example #3
0
 def create_ent_weixin_employee(self):
     """
     创建企业微信员工
     :return:
     """
     url, token = self.env['weixin.ent.parameter'].get_token_and_value(
         'user_create', 'ent_wx_ab_token')
     for res in self:
         if not res.department_id:
             raise UserError("员工'%s'必须选择部门!" % res.name)
         if not res.department_id.ent_wx_id:
             raise UserError("员工'%s'选择的部门'%s'必须已在企业微信中存在!" %
                             (res.name, res.department_id.name))
         user_id = self.env['ir.sequence'].next_by_code(
             'winxin.ent.employee.code')
         data = {
             'userid': user_id,
             'name': res.name,
             'alias': res.ent_ex_alias if res.ent_ex_alias else '',
             'mobile': res.mobile_phone if res.mobile_phone else '',
             'department': [res.department_id.ent_wx_id],
             'position': res.job_id.name if res.job_id else '',
             'email': res.work_email if res.work_email else '',
             'telephone': res.work_phone if res.work_phone else '',
             'enable': res.ent_ex_open_state,
             'external_position': res.job_title if res.job_title else '',
             'address': res.work_location if res.work_location else '',
         }
         # 性别
         if res.gender == 'male':
             data['gender'] = '1'
         elif res.gender == 'female':
             data['gender'] = '2'
         else:
             data['gender'] = '0'
         result = request_post(url, token, data)
         if result['errcode'] != 0:
             raise UserError(result['errmsg'])
         res.write({'ent_wx_id': user_id})
         res.message_post(body=u"员工信息已上传至企业微信", message_type='notification')