Exemple #1
0
 def delete_user(self):
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     for user in self:
         ding_obj.delete_user(user.ding_id)
     return True
Exemple #2
0
 def send_message(self, message, user_id):
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     dinguser_row = self.search([('ding_user_id', '=', user_id)])
     ding_obj.send_text_message(message, dinguser_row.ding_id, '')
     return True
Exemple #3
0
 def update_department(self, vals):
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     for deparment in self:
         vals.update({'id': deparment.name})
         ding_obj.update_dept(vals)
     return True
Exemple #4
0
 def delete_department(self):
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     for deparment in self:
         ding_obj.delete_dept(deparment.name)
     return True
Exemple #5
0
 def get_ding_department(self):
     department_obj = self.env['ding.department']
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     department_dict = ding_obj.get_dept_list()
     if not department_dict:
         raise UserError(u'企业号中还没创建部门')
     cr = self.env.cr
     department_row_parent = False
     for department in department_dict:
         if department.get('parentid'):
             department_row_parent = department_obj.search([
                 ('department_id', '=', department.get('parentid'))
             ])
         if department.get('id') and department.get('name'):
             department_row = department_obj.search([
                 ('department_id', '=', department.get('id'))
             ])
             if not department_row:
                 cr.execute(
                     """INSERT INTO ding_department 
                               (department_id, name, parent_id) VALUES 
                               (%s,'%s', %s)""" %
                     (department.get('id'), department.get('name'),
                      department_row_parent and department_row_parent.id
                      or 'NULL'))
     return True
Exemple #6
0
 def create_department(self):
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     for deparment in self:
         ding_id = ding_obj.create_dept(deparment.name,
                                        deparment.ding_id, deparment.parent_order)
         deparment.department_id = ding_id
     return True
Exemple #7
0
 def delete_call_back_interface(self):
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     return_vals = ding_obj.delete_call_back_interface()
     if return_vals == '0':
         return True
     else:
         print "error"
Exemple #8
0
 def create_new_approver(self):
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     vals = {
         'agent_id':
         agent_id,
         'process_code':
         'PROC-TXEKLZ3V-EJKNZY8FRS05FSWKCBOW1-6CGS3J6J-R',
         'originator_user_id':
         '11613705613522631',
         'dept_id':
         '44507267',
         'approvers':
         '03155020331048990,manager1461,08372149511213545',
         'cc_list':
         'manager1461',
         'cc_position':
         'START_FINISH',
         'form_component_values':
         simplejson.dumps([{
             "name": u"采购备注",
             "value": u"买个西瓜 甜瓜"
         }, {
             'name':
             u'明细',
             "value": [[{
                 "name": "产品",
                 "value": "西瓜"
             }, {
                 "name": "数量",
                 "value": "10"
             }, {
                 "name": "价格",
                 "value": "100"
             }],
                       [
                           {
                               "name": "产品",
                               "value": "甜瓜"
                           },
                           {
                               "name": "数量",
                               "value": "5"
                           },
                           {
                               "name": "价格",
                               "value": "2"
                           },
                       ]]
         }])
     }
     return_vals = ding_obj.create_new_approver(vals)
     if return_vals == '0':
         return True
     else:
         print "error"
Exemple #9
0
 def get_dingdinguser(self):
     department_rows = self.env['ding.department'].search([])
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     for department_row in department_rows:
         user_dicts = ding_obj.get_depatment_user_list(department_row.department_id)
         for user in user_dicts:
             if not self.env['ding.user'].search([('ding_id', '=', user.get('userid'))]):
                 self.create_ding_user(user)
Exemple #10
0
 def checkout_call_back_interface(self):
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     return_vals = ding_obj.checkout_call_back_interface()
     if return_vals == 0:
         self.is_ok_call_back_url = True
         return True
     else:
         print "error"
Exemple #11
0
 def create_ding_user(self):
      corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
      ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
      for user in self:
         user_vals = dict(name=user.name, department=[user.department_id.department_id] or [1],
                          mobile=user.mobile_num, tel=user.tel, email=user.email,
                          workPlace=user.work_place)
         user_id = ding_obj.create_user(user_vals)
         user.ding_id = user_id
      return True
Exemple #12
0
 def update_call_back_interface(self):
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     return_vals = ding_obj.update_call_back_interface(
         str(self.random_token), str(self.aes_key1), self.call_back_url,
         eval(self.call_back_tags))
     if return_vals == '0':
         return True
     else:
         print "error"
Exemple #13
0
 def update_user(self, vals):
     change_keys = {'name': 'name', 'department_id': 'department_id',
                    'mobile_num': 'mobile', 'tel': 'tel',
                    'work_place': 'workPlace', 'email': 'email'}
     vals = {change_keys.get(key): vals.get(key) for key in change_keys.keys()
             if key in vals}
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     for user in self:
         vals.update({'userid': user.ding_id, 'name': user.name})
         ding_obj.update_user(vals)
     return True
Exemple #14
0
 def get_ding_common_message(self):
     dingding_row = self.env.ref('dingding.ding_ding_xml')
     if not dingding_row.token or float(
             dingding_row.expired_in) <= time.time():
         ding_obj = Dingtalk(dingding_row.corpid, dingding_row.corpsecret,
                             dingding_row.agent_ids[0].agent_id, {})
         token_dcit = ding_obj.get_token()
         dingding_row.token = token_dcit.get('access_token')
         dingding_row.expired_in = token_dcit.get('expired_in')
     return (dingding_row.corpid, dingding_row.corpsecret,
             dingding_row.agent_ids[0].agent_id, {
                 'access_token': dingding_row.token,
                 'expired_in': dingding_row.expired_in
             })
Exemple #15
0
 def get_call_fail_record(self):
     corpid, corpsecret, agent_id, token_dict = self.env[
         'ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid, corpsecret, agent_id, token_dict)
     return_vals = ding_obj.get_call_fail_record()
     raise UserError(str(return_vals))