from odoo.exceptions import UserError import requests from odoo.http import request
def action_commit_approval(self,action_type='commit_approval'): """ action_type : commit_approval/cancel_approval """ self.ensure_one() base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url', default='http://localhost:8069') data = { 'model_name': self._name, 'res_id': self.id, 'action_type': action_type } session = request.session opener = requests.Session() opener.cookies['session_id'] = session.sid res = opener.post(url=base_url + '/web/dataset/control_approval', json={'params': data}) resp = json.loads(res.content) if resp.get('result') and resp['result'].get('state') == 1: print('提交审批成功1') res = opener.post(url=base_url+'/web/dataset/instance_get_info',json={'params': data}) resp = json.loads(res.content) if resp.get('result'): print('提交审批成功2',resp.get('result').get('approval_state')) else: error = resp.get('error').get('data').get('message') raise UserError(error)
标签:get,url,res,resp,接口,odoo,approval,self,路由 From: https://www.cnblogs.com/pythonClub/p/17418972.html