通过使用PostMan调用Odoo - POST
{
"jsonrpc":"2.0",
"params":{
"db":"factory",
"login":"[email protected]",
"password":"1"
}
}
通过上面Josn格式调用系统查看相关信息 - GET
{
"jsonrpc":"2.0",
"params":{}
}
##################################################################
#在Header中追加参数名为 X-Odoo 参数值为 上面POST查询出来的 session_id
#在模块中新增Controllers具体目录解构如下
#初始__init__.py 中 引入 imports controllers
#在Controllers文件中创建__init__.py和main.py文件
#在__init__.py文件中引入main imports main
#在main文件中创建调方法
#-*- coding: utf-8 -*-
#Part of Odoo. See LICENSE file for full copyright and licensing details.
#-*- coding: utf-8 -*-
#Part of Odoo. See LICENSE file for full copyright and licensing details.
##################################################################
from odoo.http import request
import odoo.http as http
class WebFormController(http.Controller):
########################################
# 该功能为GET通过接口调用获取Odoo内部数据
#######################################
@http.route('/get_partners', type='json', auth="user")
def get_partners(self):
print ("接口调用成功")
partners = request.env['stirred.yogurt'].search([])
partners_ids = []
for rec in partners:
vals = {
'id': rec.fill_date,
'name': rec.name
}
partners_ids.append(vals)
print ("PartnersList-----", partners_ids)
data = {'status': 200, 'response': partners_ids, 'message': 'Sucess'}
return data
########################################
# 该功能为POST通过接口调用提交数据到Odoo
#######################################
@http.route('/create_partners', type='json', auth="user")
def create_partners(self, **rec):
print ("创建接口调用成功")
if request.jsonrequest:
print ("rec", rec)
if rec['fill_date']:
vals = {
# 'name': rec['name'],
'fill_date': rec['fill_date'],
'check_user': rec['check_user']
}
new_partners = request.env['stirred.yogurt'].sudo().create(vals)
args = {'Sucess': True, 'message': 'Sucess', 'ID': new_partners.id}
return args