def create_agent_token(self, db_name):
     # redis 生产者消费者模式中的消费者部分的代码
     registry = odoo.registry(db_name)
     with api.Environment.manage(), registry.cursor() as cr:
         env = api.Environment(cr, odoo.SUPERUSER_ID, {})
         expired_in = 10
         while True:
             ding_config_row = env.ref('dingding.ding_ding_xml')
             if ding_config_row:
                 if float(ding_config_row.expired_in or 0) <= time.time():
                     ding_obj = Dingtalk(corpid=ding_config_row.corpid, corpsecret=ding_config_row.corpsecret)
                     token_dcit = ding_obj.get_token()
                     if token_dcit.get('errcode') == 0 and token_dcit.get('access_token'):
                         ding_config_row.token = token_dcit.get('access_token')
                         ding_config_row.expired_in = int(token_dcit.get('expired_in'))
                         env.cr.commit()
                 else:
                     expired_in = int(float(ding_config_row.expired_in) - time.time())
                 for app in ding_config_row.app_ids:
                     if float(app.expired_in or 0) <= time.time():
                         ding_obj = Dingtalk(appkey=app.agent_id, appsecret=app.app_secret)
                         token_dcit = ding_obj.app_get_token()
                         if token_dcit.get('errcode') == 0 and token_dcit.get('access_token'):
                             app.token = token_dcit.get('access_token')
                             app.expired_in = int(token_dcit.get('expired_in'))
                             env.cr.commit()
                     else:
                         expired_in = min(int(float(ding_config_row.expired_in) - time.time()), expired_in)
             time.sleep(expired_in)
Example #2
0
 def create_new_approver(self):
     agent_row = self.env.ref("dingding.ding_agent_xml")
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message(agent_row.agent_id)
     ding_obj = Dingtalk(corpid=corpid, corpsecret=corpsecret, token=token_dict)
     vals = {
         'agent_id': agent_id,
         'process_code': 'PROC-TXEKLZ3V-EJKNZY8FRS05FSWKCBOW1-6CGS3J6J-R',
         'originator_user_id': 'manager1461',
         'dept_id': '44507267',
         'approvers': 'manager1461',
         '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")
Example #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=corpid, corpsecret=corpsecret, token=token_dict)
     for deparment in self:
         vals.update({'id': deparment.name})
         ding_obj.update_dept(vals)
     return True
Example #4
0
 def send_message(self, message, user_id, agent_id):
     """发送消息必须指定agent_id"""
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message(agent_id)
     ding_obj = Dingtalk(corpid=corpid, corpsecret=corpsecret, token=token_dict, agent_id=agent_id)
     dinguser_row = self.search([('ding_user_id', '=', user_id)])
     ding_obj.send_text_message(message, dinguser_row.ding_id, '')
     return True
Example #5
0
 def create_department(self):
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid=corpid, corpsecret=corpsecret, token=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
Example #6
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=corpid, corpsecret=corpsecret, token=token_dict)
     return_vals = ding_obj.delete_call_back_interface()
     if return_vals == '0':
         return True
     else:
         print("error")
Example #7
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=corpid, corpsecret=corpsecret, token=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")
Example #8
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=corpid, corpsecret=corpsecret, token=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.get_ding_user(user)
Example #9
0
 def create_ding_user(self):
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid=corpid, corpsecret=corpsecret, token=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
         user.ding_user_id.oauth_access_token = user_id
     return True
Example #10
0
 def dingding_login(self, **kwargs):
     for app_agent in request.env['app.agent'].sudo().search([]):
         ding_obj = Dingtalk(token={'access_token': app_agent.token})
         persistent_code_dict = ding_obj.get_persistent_code(kwargs.get('code'))
         sns_token_dict = ding_obj.get_sns_token(persistent_code_dict.get('openid'),
                                                       persistent_code_dict.get('persistent_code'))
         user_info_dict = ding_obj.get_user_info_by_sns_token(sns_token_dict.get('sns_token'))
         for user in request.env['ding.user'].sudo().search([('unionid', '=', user_info_dict.get('user_info', {}).get('unionid'))]):
             request.session.authenticate(request.session.db, user.ding_user_id.login, user.ding_user_id.oauth_access_token)
             return http.local_redirect('/web/')
         return werkzeug.utils.redirect('/web')
Example #11
0
 def update_call_back_interface(self):
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(ccorpid=corpid, corpsecret=corpsecret, token=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")
Example #12
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=corpid, corpsecret=corpsecret, token=token_dict)
     for user in self:
         vals.update({'userid': user.ding_id, 'name': user.name})
         ding_obj.update_user(vals)
     return True
Example #13
0
 def getdingdingconfig(self, **args):
     corpid, corpsecret, agent_id, token_dict = request.env['ding.ding'].sudo().get_ding_common_message()
     ding_obj = Dingtalk(corpid=corpid, corpsecret=corpsecret, agent_id=agent_id, token=token_dict)
     signature, timestamp, nonceStr = ding_obj.get_js_api_params(str(request.httprequest.base_url), '1234')
     return {
         'corpId': corpid,
         'timeStamp': timestamp,
         'agentId': agent_id,
         'nonceStr': nonceStr,
         'accessToken': token_dict.get("access_token"),
         'title': u'钉钉测试',
         'signature': signature,
         # 'jsApiList': jsApiList
     }
Example #14
0
 def dingding_pulling(self, **args):
     template = env.get_template("apps.html")
     corpid, corpsecret, agent_id, token_dict = request.env['ding.ding'].sudo().get_ding_common_message()
     ding_obj = Dingtalk(corpid=corpid, corpsecret=corpsecret, agent_id=agent_id, token=token_dict)
     signature, timestamp, nonceStr = ding_obj.get_js_api_params(str(request.httprequest.base_url), '1234')
     return template.render({
         'corpId': corpid,
         'timeStamp': timestamp,
         'agentId': agent_id,
         'nonceStr': nonceStr,
         'accessToken': token_dict.get("access_token"),
         'title': u'钉钉测试',
         'signature': signature,
     })
Example #15
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=corpid, corpsecret=corpsecret, token=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
Example #16
0
 def delete_user(self):
     corpid, corpsecret, agent_id, token_dict = self.env['ding.ding'].get_ding_common_message()
     ding_obj = Dingtalk(corpid=corpid, corpsecret=corpsecret, token=token_dict)
     for user in self:
         ding_obj.delete_user(user.ding_id)
     return True
Example #17
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=corpid, corpsecret=corpsecret, token=token_dict)
     return_vals = ding_obj.get_call_fail_record()
     raise UserError(str(return_vals))