debugging functions in the OpenERP module using XML-RPC

Source: Internet
Author: User
Tags pprint

There are many ways to run a function in the OpenERP module, you can add a button to the view and click it, or you can enforce it in the integrated development environment. However, writing a small script in Python, the XML-RPC call to execute it directly, is undoubtedly the easiest way to

A Call method

Example:

ImportXmlrpclib fromPprintImportPprint UID=1#ID number for user name AdminPwd="Admin"   #Password for adminDbname="Demo"Tcp_port="8069"sock=xmlrpclib. Serverproxy ("Http://127.0.0.1:%s/xmlrpc/object"%tcp_port) Model="hr.employee.category"  ##要运行哪个类中的函数? Method="Read"      ##要运行的函数 ##def Read (self, CR, UID, IDS, Fields=none, Context=none) #函数签名ids=[1,2,3]##参数一,fields=['name','Complete_name','parent_id','Child_ids']##参数二result =Sock.execute (dbname, uid, pwd, Model,method, IDs, fields)Print "\n====%s of%s = ="%(model, method) Pprint (Result)

As you can see, the arguments we use in Sock.execute are not exactly the same as those given in the function signature, and their corresponding relationships are:

---the first three parameters in the function signature are self, CR, UID

The first five parameters in the--socke.exec are dbname, UID, Pwd,model,method

Subsequent parameters are the same.

Two call logs

In OpenERP 7.0, the actions we do in the browser are converted to XML-RPC calls, and we can see XML-RPC's call log to find out what arguments OpenERP uses to invoke XML-RPC. We can generate the log by adding the following statement under the function Disptach

params = params[3:]##加在这一行下面 fromPprintImportPformat##这一行最后加在文件顶部if(Params[0][0:2] = ='op.' orParams[0][1:3] = ='op.'):#modules of greatest concernS=method+'!'+pformat (Params[0]) +pformat (params[1:],depth=9) elif(Params[1] = ='Get_needaction_data'):#least-cared callS=method+'!'+pformat (Params[0]) +pformat (params[1:],depth=1)Else:#Other ModulesS=method+'!'+pformat (Params[0]) +pformat (params[1:],depth=3

In 7.0, this statement needs to be added to the class objects_proxy of the file service\web_services.py

In 8.0, this statement needs to be added to the file service\model.py. It should be noted that, by default, Oe8 's browser operation is no longer using XML-RPC.

OpenERP provides--log-request, but it does not record the parameter information in detail, and in Oe7, the number of log bars generated is too many, so we do not use it.

Three functions that call the following underscore

For security reasons, OPENERP does not allow functions that begin with an underscore from outside the module. In the test environment, this is an obstacle to our exploration of the mysteries of OpenERP, we note the following two lines of the source code (oe8 in the file model.py, Oe7 in the file osv.py

If Method.startswith ('_'):

# Raise Except_orm (' Access Denied ', ' Private methods (such as%s) cannot be called remotely. '% (method,) ')

Run these functions (as well as the Browse function) that begin with the underscore, and the returned results may not be packaged in XML format, and this will cause the following error.

Xmlrpclib. Fault:objects:

We have slightly modified the dump_struct function in the Python library file xmlrpclib.py to run almost all functions except Broswe.

 forKvinchvalue.items (): Write ("\ n")            ifType (k) isInttype:##添加此行和下一行K ="%d"% K##将diction的键值由数字转为字符            ifType (k) is  notStringType:ifUnicode andType (k) isunicodetype:k=K.encode (self.encoding)Else:                    RaiseTypeError,"Dictionary key must be string"

debugging functions in the OpenERP module using XML-RPC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.