首页 > 其他分享 >How Does RPC & ORM Calls Works in Odoo 16

How Does RPC & ORM Calls Works in Odoo 16

时间:2023-10-01 13:45:25浏览次数:58  
标签:function Calls 16 rpc RPC Does call Odoo kw

How RPC Works in Odoo Framework:

*Odoo is an open-source ERP (Enterprise Resource Planning) framework that provides a vast range of business application functionalities. It follows a client-server architecture, where the client interacts with the server to perform various operations like reading data, creating records, updating records, and more.

1. Odoo ORM (Object-Relational Mapping)

*The heart of Odoo's data manipulation and communication with the database is the Odoo ORM, which stands for Object-Relational Mapping. The ORM acts as an abstraction layer between the Python code and the underlying database, allowing developers to interact with data in a more Pythonic way. It helps manage the data models and map them to the database tables.

this.orm = useService('orm')
const resPartner = await 
this.orm.call('res.partner','search_read',[[]])

  

This ORM call triggers the call function in the orm_service.js file    
call(model, method, args = [], kwargs = {}) {
    validateModel(model);
    const url = `/web/dataset/call_kw/${model}/${method}`;
    const fullContext = Object.assign({}, this.user.context, kwargs.context || {});
    const fullKwargs = Object.assign({}, kwargs, { context: fullContext });
    const params = {
        model,
        method,
        args,
        kwargs: fullKwargs,
    };
    return this.rpc(url, params, { silent: this._silent });
}

  

The rpc function in the rpc_service.js ultimately starts the jsonrpc function     
export const rpcService = {
    async: true,
    start(env) {
        let rpcId = 0;
        return function rpc(route, params = {}, settings) {
            return jsonrpc(env, rpcId++, route, params, settings);
        };
    },
};

  

The Data is returned to the source of the call.

2.XML-RPC and JSON-RPC

  *Odoo provides two main RPC protocols for client-server communication: XML-RPC and JSON-RPC. XML-RPC uses XML to encode the request and response data, while JSON-RPC uses JSON (JavaScript Object Notation). Both protocols are lightweight and platform-independent, making them suitable for communication between different systems. Refer this  XML-RPC

3.API Endpoints

  *Odoo exposes a set of API endpoints that can be accessed by clients to perform various operations. These endpoints represent different Odoo services, such as objects, methods, workflows, and more. Clients can make RPC requests to these API endpoints to interact with the Odoo server. This is one example of the api endpoint.
@http.route(['/web/dataset/call_kw', '/web/dataset/call_kw/<path:path>'], type='json', auth="user")
    def call_kw(self, model, method, args, kwargs, path=None):
        return self._call_kw(model, method, args, kwargs)

  

4.RPC Methods

*Odoo's API provides several RPC methods that clients can use to perform CRUD (Create, Read, Update, Delete) operations on Odoo models. Some commonly used RPC methods include: search_read: To search and read records from the Odoo database. create: To create new records in the Odoo database. write: To update existing records in the Odoo database. unlink: To delete records from the Odoo database.

5.Security

*Odoo ensures security during RPC calls by enforcing access controls based on user roles and permissions. It prevents unauthorized access to sensitive data and operations.

6.Session Management

*When a client initiates an RPC call, Odoo maintains a session for that client, keeping track of their context and rights during subsequent requests. This session management helps in maintaining the state of the client-server interaction. In conclusion, RPC in the Odoo framework enables seamless communication between the client and server components. The use of XML-RPC or JSON-RPC allows clients to make requests to Odoo's API endpoints, perform various operations on the database, and retrieve the desired results. This RPC mechanism, combined with Odoo's powerful ORM and security features, makes it a robust and efficient framework for building enterprise-grade applications. RPC *RPC, short for Remote Procedure Call, is a communication protocol used in distributed systems to enable different software components or processes to communicate with each other across a network. It allows programs running on different devices or machines to invoke functions or procedures on remote systems as if they were local, making it easier to build complex and interconnected applications. *In simple terms, RPC allows a client application to request services or functions from a server application located on a different machine over a network. The client and server interact as if they were on the same system, abstracting the complexity of network communication and providing a seamless way to distribute tasks and processing across multiple nodes. There are several different ways you call an rpc call ;
const rpc = require('web.rpc')
await rpc.query({
        model: 'res.partner',
        method: 'search_read',
        args : []
      }).then(data => {
         // The data will have the called objects in an array
      })

  

The flow of this rpc call is as follows: *The query function in web/core/rpc.js file get triggered and the buildQuery function builds the query which has the url for the api endpoint
query: function (params, options) {
    var query = rpc.buildQuery(params);
    return ajax.rpc(query.route, query.params, options);
    },

  

*Then rpc function in the ajax.js file is triggered and jsonRpc function is returned *The url in jsonRpc would look something like this ‘/web/dataset/call_kw/res.partner/search_read *Then jsonRpc ultimately calls ajax function in the jquery.js file then the remote procedure call triggers the Controller function call_kw
@http.route(['/web/dataset/call_kw', '/web/dataset/call_kw/<path:path>'], type='json', auth="user")
    def call_kw(self, model, method, args, kwargs, path=None):
        return self._call_kw(model, method, args, kwargs)

  

*And after that call_kw function in the api.py file is triggered and the function 'search_read' in the model 'res.partner' is executed.  

标签:function,Calls,16,rpc,RPC,Does,call,Odoo,kw
From: https://www.cnblogs.com/pythonClub/p/17738788.html

相关文章

  • SP16113 SUBTLEBA - Trucks Transportation 题解
    题目传送门前言本题样例有问题,如果想要样例可以去vjudge上。本题提交后可能会出现UKE,建议前往link提交,而且本篇题解中所提供的代码也为link代码。前置知识Kruskal重构树|最近公共祖先简化题意给定一个\(N\)个点\(M\)条边的有向图,共有\(S\)次询问,每次询问......
  • Go每日一库之166:go-version(语义化版本)
    今天给大家推荐的是一个版本比较工具。该工具基于语义化标准的版本号进行比较、约束以及校验。以下是go-version的基本情况:安装通过goget进行安装:gogetgithub.com/hashicorp/go-version解析和比较版本号v1,err:=version.NewVersion("1.2")给版本号增加约束并校验v1......
  • Go每日一库之165:go-callvis(可视化调用链)
    本文介绍一款工具go-callvis,它能够将Go代码的调用关系可视化出来,并提供了可交互式的web服务。go-callvis使用依赖Go1.17+Graphviz(可选,当工具指定了-graphviz时需要)工具安装goget-ugithub.com/ofabry/go-callvis#orgitclonehttps://github.com/ofabry/......
  • Go每日一库之164:uiprogress(终端进度条)
    今天给大家推荐的是在终端(terminal)下能够显示进度条的工具:uiprogress。先看下使用该包的效果图:相信大家在linux或mac终端上都下载过东西,然后会出现下载的进度条。今天我们就给大家分析下实现原理并演示其效果。安装$goget-vgithub.com/gosuri/uiprogress实现原理分析实......
  • Go每日一库之162:throttled(轻量级限流工具)
    throttled是一个非常轻量且易扩展的限流组件,我们可以将它轻松地集成到应用程序中,以实现限流和配额管理的能力。简介throttled(https://github.com/throttled/throttled)基于通用信元速率算法实现了对资源的访问速率限制,资源可以是特定的URL、用户或者任何自定义的形式,可以很......
  • Go每日一库之161:grm(Redis Web管理工具)
    GRM是基于go+vue的web版redis管理工具,部署简单便捷,支持SSH连接,用户校验,操作日志、命令行模式、LUA脚本执行等功能。介绍基于go+vue的web版redis管理工具【Webredismanagementtoolbasedongolangandvue】功能清单管理连接(直连和SSH)、切换DB支持string/lis......
  • Go每日一库之160:gvm(Go版本管理)
    **gvm**用于go版本的管理,主要的功能为go版本的查看,下载安装和切换。安装$bash<<(curl-s-S-Lhttps://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)Cloningfromhttps://github.com/moovweb/gvm.gitto/Users/admin/.gvmCreatedprofilef......
  • [CF1654F] Minimal String Xoration
    MinimalStringXoration有点智慧但不是特别智慧反正是我达不到的智慧。打表可以看出长度为\(2^x\)的\(i\oplusk\)出现次数为\(2^{n-k}\)。进一步发现,设\(f(k,x)\)当前选取k时,数列前\(2^k\)的下标。则\(f(k,x)=f(k,x-1)+f(k\oplus{2^{x-1}},x-1)\)因为对于\(......
  • 《看了受制了》第三十一天,7道题,合计164道题
    2023年9月30日Acwing5266队列题目大意问你,n加在三个数上,看最后三个数能不能相等。题目理解先把三个数都变成最大的,然后最后的n如果是3的倍数且大于等于0即可代码实现voidsolve(){lln,a,b,c;cin>>a>>b>>c>>n;llk=max(a,max(b,c));......
  • Ubuntu 16.04 上安装 OrientDB!
    这两种模型在如何处理(存储)数据的方面存在着巨大的差异。关系数据库管理系统在关系模型中(如MySQL,或者其分支MariaDB),一个数据库是一个表的集合,其中每个表包含一个或多个以列组织的数据分类。数据库的每行包含一个唯一的数据实例,其分类由列定义。举个例子,想象一个包含客户的表。......