odoo14中rpc调用分为两种。

一种是外部调用rpc来访问odoo数据,这个时候你需要登录授权。

另一种是我们自己编写的widget小部件或者自定义视图时候通过js通过rpc去获取数据。

这里说的是第二种rpc的使用。

上代码:

    //调用res.users中的自定义的get_userform_action方法
this._rpc({
model: 'res.users',
method: 'get_userform_action',
args: [[data.val]]//这里就是python函数声明里的*args,当你的方法不是model方法也不是model_create方法的时候,这里一个参数传的是当前model(res.users)的记录id,它会查询id结果作为self去调用get_userform_action
}).then(function (result){
self.do_action(result);
}); //查询数据的方法
this._rpc({
model: this.model,
method: 'read_group',
domain: [],
fields: ['color'],
groupBy: ['color'],
}).then(function (result) {
_.each(result, function (r) {
self.colorGroupData[r.color] = r.color_count;
});
});
//自定义的方法
class Users(models.AbstractModel):
_inherit = 'res.users' def get_userform_action(self):
action = self.env.ref('ship_manage.res_company_user_form_action').read()[0]
action['res_id'] = self.id
return action
 1 //Python   rpc参数传递源码
2 def _call_kw_model(method, self, args, kwargs):
3 context, args, kwargs = split_context(method, args, kwargs)
4 recs = self.with_context(context or {})
5 _logger.debug("call %s.%s(%s)", recs, method.__name__, Params(args, kwargs))
6 result = method(recs, *args, **kwargs)
7 return downgrade(method, result, recs, args, kwargs)
8
9
10 def _call_kw_model_create(method, self, args, kwargs):
11 # special case for method 'create'
12 context, args, kwargs = split_context(method, args, kwargs)
13 recs = self.with_context(context or {})
14 _logger.debug("call %s.%s(%s)", recs, method.__name__, Params(args, kwargs))
15 result = method(recs, *args, **kwargs)
16 return result.id if isinstance(args[0], Mapping) else result.ids
17
18
19 def _call_kw_multi(method, self, args, kwargs):
20 ids, args = args[0], args[1:]
21 context, args, kwargs = split_context(method, args, kwargs)
22 recs = self.with_context(context or {}).browse(ids)
23 _logger.debug("call %s.%s(%s)", recs, method.__name__, Params(args, kwargs))
24 result = method(recs, *args, **kwargs)
25 return downgrade(method, result, recs, args, kwargs)
26
27
28 def call_kw(model, name, args, kwargs):
29 """ Invoke the given method ``name`` on the recordset ``model``. """
30 method = getattr(type(model), name)
31 api = getattr(method, '_api', None)
32 if api == 'model'://这里将模型分成了三种走向,三种走向对参数的处理不一样
33 result = _call_kw_model(method, model, args, kwargs)
34 elif api == 'model_create':
35 result = _call_kw_model_create(method, model, args, kwargs)
36 else:
37 result = _call_kw_multi(method, model, args, kwargs)
38 model.flush()
39 return result

Odoo14 rpc的更多相关文章

  1. 【odoo14】第十五章、网站客户端开发

    odoo的web客户端.后台是员工经常使用的地方.在第九章中,我们了解了如何使用后台提供的各种可能性.本章,我们将了解如何扩展这种可能性.其中web模块包含了我们在使用odoo中的各种交互行为. 本章 ...

  2. 【odoo14】第十六章、odoo web库(OWL)

    odoo14引入了名为OWL(Odoo Web Library)的JavaScript框架.OWL是以组件为基础的UI框架,通过QWeb模板作为架构.OWL与传统的组件系统相比更快,并引入了一些新的特 ...

  3. 【odoo14】odoo 14 Development Cookbook【目录篇】

    网上已经有大佬翻译过odoo12并且在翻译odoo14了.各位着急的可以自行搜索下... 这本书是为了让自己从odoo12转odoo14学习.也是为了锻炼下自己... odoo 14 Developm ...

  4. Odoo14 OWL 如何访问model方法和res_id

    首先OWL是Odoo14版本新加的功能. 因为是新加的所以并没有太多的说明文档,包括英文板文档也没有:所以你要用它再没有更详细的文档之前你得自己去看源码. 注意owl是没有do_action函数给你跳 ...

  5. 从RPC开始(一)

    这是一篇关于纯C++RPC框架的文章.所以,我们先看看,我们有什么? 1.一个什么都能干的C++.(前提是,你什么都干了) 2.原始的Socket接口,还是C API.还得自己去二次封装... 3.C ...

  6. RPC 使用中的一些注意点

    最近线上碰到一点小问题,分析其原因发现是出在对 RPC 使用上的一些细节掌握不够清晰导致.很多时候我们做业务开发会把 RPC 当作黑盒机制来使用,但若不对黑盒的工作原理有个基本掌握,也容易犯一些误用的 ...

  7. 谈谈如何使用Netty开发实现高性能的RPC服务器

    RPC(Remote Procedure Call Protocol)远程过程调用协议,它是一种通过网络,从远程计算机程序上请求服务,而不必了解底层网络技术的协议.说的再直白一点,就是客户端在不必知道 ...

  8. 游戏编程系列[1]--游戏编程中RPC协议的使用[3]--体验

    运行环境,客户端一般编译为.Net 3.5 Unity兼容,服务端因为用了一些库,所以一般为4.0 或往上.同一份代码,建立拥有2个项目.客户端引用: WindNet.Client服务端引用: OpL ...

  9. python通过protobuf实现rpc

    由于项目组现在用的rpc是基于google protobuf rpc协议实现的,所以花了点时间了解下protobuf rpc.rpc对于做分布式系统的人来说肯定不陌生,对于rpc不了解的童鞋可以自行g ...

随机推荐

  1. OSError: no library called "cairo-2" was found

    环境 Windows 11 python 3.8.13 (anaconda->envs) PyCharm 场景 我使用了GitHub上的第三方组件进行GUI开发,https://github.c ...

  2. 【多线程】可重入锁 ReentrantLock

    java除了使用关键字synchronized外,还可以使用ReentrantLock实现独占锁的功能.而且ReentrantLock相比synchronized而言功能更加丰富,使用起来更为灵活,也 ...

  3. Slab 分配器

    1.什么是Slab 分配器: 以下摘自维基百科:https://en.wikipedia.org/wiki/Slab_allocation Slab  firstly introduced in ke ...

  4. 804. Unique Morse Code Words - LeetCode

    Question 804. Unique Morse Code Words [".-","-...","-.-.","-..&qu ...

  5. 443. String Compression - LeetCode

    Question 443. String Compression Solution 题目大意:把一个有序数组压缩, 思路:遍历数组 Java实现: public int compress(char[] ...

  6. Vue2-Slot插槽使用

    Slot插槽 父组件向子组件传递 父组件将内容分发到子组件 slot插槽的值只读,不能在子组件中修改 slot插槽也可以作为组件之间的通信方式 默认插槽 父组件中:使用Son组件 <templa ...

  7. npm run serve修改为npm run dev

    找到package.json文件,打开文件找到  "serve": "vue-cli-service serve"  这一行,把前面的 serve 修改 dev ...

  8. 技术分享 | app自动化测试(Android)--App 控件定位

    原文链接 客户端的页面通过 XML 来实现 UI 的布局,页面的 UI 布局作为一个树形结构,而树叶被定义为节点.这里的节点也就对应了要定位的元素,节点的上级节点,定义了元素的布局结构.在 XML 布 ...

  9. JS:表达式

    js代码的形式: 1.直接量 2.表达式 3.语句 1; "a"; true; null; var a; function fn(){}; b; var c = 20; var f ...

  10. Python基础学习_03

    程序的流程控制 1.程序的组织结构 (1)顺序结构 (2)选择结构 (3)循环结构 2.对象的布尔值 以下对象的布尔值为False False,数值0,None,空字符串,空列表,空元组,空字典,空集 ...