odoo14中rpc调用分为两种。

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

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

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

上代码:

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

    1 查询当地供应商所有AS号和IP地址段,如下 可以手动复制也可以爬下来,此次测试地址不多,手动复制下来再做下格式话 61.99.128.0/17 61.99.0.0/16 61.98.96.0/20 ...

  2. IDEA快捷生成循环♻️

    itar 生成array for代码块 //itar for (int i = 0; i < array.length; i++) { = array[i]; } itco 生成Collecti ...

  3. JS倒计时(刷新页面不影响)的实现思路

    最近在做一个项目,用到了点击按钮实现倒计时,这个用js来实现很简单.但是遇到了一个问题 页面刷新后js重新加载导致 倒计时重新开始,或者直接初始化了 后来通过 cookie 保存来实现了js倒计时,关 ...

  4. 【Unity Shader学习笔记】Unity基础纹理-渐变纹理

    纹理可以用来存储任何表面属性. 可以通过使用渐变纹理来实现插画风格的渲染效果. 这项技术是由Valve公司提出的.Valve使用它来渲染游戏中具有插画风格的角色. 我们使用半兰伯特模型计算漫反射. 因 ...

  5. 一些基本的jar包

    jackson与前端传送数据 <dependency> <groupId>com.fasterxml.jackson.core</groupId> <arti ...

  6. CentOS 7.0 使用 yum 安装 MariaDB

    CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置   1.安装MariaDB 安装命令 yum -y install mariadb mariadb-serve ...

  7. 线上问题定位利器 jprofiler

    1.导出dump windows: jps -l   查看Java进行 jmap -dump:format=b,file=webapi.hprof 20840 查看进程,根据进程号导出hprof文件 ...

  8. 『忘了再学』Shell流程控制 — 39、特殊流程控制语句

    目录 1.特殊流程控制语句介绍 2.exit语句 3.break语句 4.continue语句 1.特殊流程控制语句介绍 Shell程序或者说其他的程序,都是顺序执行的,也就是第一行执行完再执行第二行 ...

  9. 重学ES系列之新型数据结构Map应用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言:一个Bug 没想到一个Bug,竟然搞我两次! 我大抵是卷上瘾了,横竖都睡不着,坐起来 ...