The mild experience of openerp XML-RPC + many2133, one2133, many2one Creation Method

Source: Internet
Author: User

At the summer and autumn ends, we have exhibitions. After the exhibition, there are many new potential customers to add. We accept a lot of business cards and it will take some time to enter openerp, in addition, there is no simple way to import business card images, so I want to write a script to import these business cards and related customer information.

XML-RPC is a distributed computing protocol for Remote Procedure Call (RPC), which encapsulates call functions through XML and uses HTTP as a transfer 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 -*- import xmlrpclibimport xlrdimport base64 DB = ´TESTDB´# Set of accountsUSERNAME = ´admin´# UsernameUSERPASS = ´1´# Password IMAGELOCATION=´E:\IMG´ # Root directory address of the image# Reading Excel filesfname = "E:TEST.xls" # Excel table addressbk = xlrd.open_workbook(fname)# Sheet by namesh = bk.sheet_by_name("JOSHUA")# Login 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)) for i in range(1,sh.nrows):    row_data = sh.row_values(i)    # Locate the country ID by country name    country_id = sock.execute(DB, uid, USERPASS, ´res.country´,´search´,[(´name´,´=´,row_data[8])])    value = {             ´name´:row_data[0],# The first line is the name of the partner, 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],                              })],               }    if row_data[11]:        # In openerp, images are archived in binary format. Therefore, base64 is used for conversion. row_data [11] is the image file name.        value[´logo´]=base64.encodestring(open(IMAGELOCATION+row_data[11], ´rb´).read())    print value    ids = sock.execute(DB, uid, USERPASS, ´res.partner´,´create´,value)    print ids
sock.execute(DB, uid, USERPASS, ´res.partner´,´create´,value)

This statement is used to execute the create method to res. Partner. value is the corresponding parameter.

Because the relationship between partner and address is one2second, you can add them directly in the openerp ORM to modify the values of one2second, many2second, and many2one in a special format.

Many2many

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

(1, ID, {values}) Update id = ID record (write data in values)

(2, ID) delete data with ID = ID (call the unlink method to delete data and the entire master-slave Data Link)

(3, ID) disconnect the connection between the master and slave data, but do not delete the data.

(4, ID) Add a master-slave link for data with ID = ID.

(5) deleting the link between all slave data is to call all Slave Data (3, ID)

(6, 0, [IDs]) replace the original record with the record in IDS (that is, execute (5) first and then execute the cyclic IDS (4, ID ))

Example [(6, 0, [8, 5, 6, 4])] Set many2pointer to IDS [8, 5, 6, 4]

One2workflow

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

(1, ID, {values}) Update the id = ID record (write the execution of ID = ID into the data in values)

(2, ID) delete data with ID = ID (call the unlink method to delete data and the entire master-slave Data Link)

Example:

[(0, 0, {'field _ name': field_value_record1,...}), (0, {'field _ name': field_value_record})]

Many2oneThe field is relatively simple. Enter the ID of the existing data or enter false to delete the original record.

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.