The light experience of OpenERP's Xml-rpc +many2many,one2many,many2one creation method

Source: Internet
Author: User

Whenever summer and autumn, we have exhibitions, after the show, there are a lot of new potential customers to add, we received a large number of business cards, want to enter openerp or need a certain time, and the picture of the business card import there is no concise method, So I would like to write a script to import these business cards and related customer information.

XML-RPC is a distributed computing protocol for Remote Procedure calls (Remotes procedure Call,rpc) that encapsulates the calling function through XML and uses the HTTP protocol as the delivery mechanism.

The requirement is that you want to use a script to import the partner of an Excel table along with their contacts.

#-*-encoding:utf-8-*- ImportXmlrpclibImportxlrdImportBase64 DB=′testdb′#Account set nameUSERNAME =′admin′#User nameUserpass =′1′#Passwordimagelocation=′e:\img′#the root directory address of the picture#reading Excel Filesfname = " e:test.xls"#Excel table AddressBK =Xlrd.open_workbook (fname)#take sheet by nameSH = bk.sheet_by_name (" joshua&Amp;quot;)#Login to take UIDSock_common = Xmlrpclib. Serverproxy (′http://localhost:8069/xmlrpc/common′) UID=Sock_common.login (DB, USERNAME, userpass) sock= Xmlrpclib. Serverproxy (′http://%s:%s/xmlrpc/object′% (′localhost′,8069))  forIinchRange (1, sh.nrows): Row_data=sh.row_values (i)#find the country ID by country namecountry_id = Sock.execute (DB, UID, userpass,′res.country′,′search′,[(′name′,′=′,row_data[8]]) value={′name′:row_data[0],#The first is the partner name, and so on.′lang′:row_data[1],′address′:[(0,0,{′title′:row_data[2],′name′:row_data[3],′email′:row_data[4],′phone′:row_data[5],′mobile′:row_data[6],′street′:row_data[7],′country_id′:country_id[0],′city′:row_data[9],′zip′:row_data[10],                              })],               }    ifRow_data[11]:        #in OpenERP inside the picture is binary to archive, so to use Base64 conversion, ROW_DATA[11] is the file name of the picture. Value[′logo′]=base64.encodestring (Open (imagelocation+row_data[11],′rb′). Read ())PrintValue IDs=Sock.execute (DB, uid, userpass,′res.partner′,′create′,value)PrintIds
Sock.execute (DB, UID, userpass,′res.partner′,′create′,value)

This is the method of executing create to Res.partner, and value is the corresponding parameter

Because the relationship between partner and address is One2many, in OpenERP's ORM can be added directly, modify these one2many,many2many and Many2one values have a special format.

Many2many

(0,0,{values}) create a new record based on the information in the values.

(1,id,{values}) Update Id=id record (writes data inside values)

(2,id) Delete id=id data (call unlink method, delete data and entire master-slave data link relationship)

(3,id) cut off the link between master and slave data but do not delete this data

(4,id) adds a master-slave link to the Id=id data.

(5) Delete all links from the data is called to all from the data call (3,id)

(6,0,[ids]) replace the original record with the record in IDs (5) and execute the Loop IDs execution (4,id).

Example [(6, 0, [8, 5, 6, 4])] set Many2many to IDs [8, 5, 6, 4]

One2many

(0, 0,{values}) creates a new record based on the information in the values.

(1,id,{values}) Update Id=id record (execution of Id=id writes to data in values)

(2,id) Delete id=id data (call unlink method, delete data and entire master-slave data link relationship)

Example:

[(0,0,{' field_name ': Field_value_record1,...}), (0,0,{' field_name ': Field_value_record})]

many2one fields are simple, fill in the ID of the existing data directly or fill in false to delete the original record.

The light experience of OpenERP's Xml-rpc +many2many,one2many,many2one creation method

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.