Openerplib Connector Example

openerp-client-lib 1.0.0

Probuse Admin

Install openerplib library from:

https://pypi.python.org/pypi/openerp-client-lib/1.0.0

 

The OpenERP Client Library is a Python library to communicate with an OpenERP Server using its web services in an user-friendly way. It was created for those that doesn’t want to code XML-RPC calls on the bare metal. It handles XML-RPC as well as JSON-RPC protocol and provides a bunch of syntaxic sugar to make things a lot easier.

sudo easy_install openerp-client-lib

 

# -*- coding: utf-8 -*-

##############################################################################

#

# OpenERP, Open Source Management Solution

# Copyright (C) 2015-Today Probuse Consutling Service Pvt. Ltd. (<http://probuse.com>).

#

# This program is free software: you can redistribute it and/or modify

# it under the terms of the GNU Affero General Public License as

# published by the Free Software Foundation, either version 3 of the

# License, or (at your option) any later version.

#

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

# GNU Affero General Public License for more details.

#

# You should have received a copy of the GNU Affero General Public License

# along with this program. If not, see <http://www.gnu.org/licenses/>.

#

##############################################################################

import openerplib

#Below script will read image from one db and write to second db.

# source database

SOURCE_USER = 'admin'

SOURCE_PASSWORD = 'a'

SOURCE_HOSTNAME = 'localhost'

SOURCE_DATABASE = 'odoo_7_data'

SOURCE_PORT = 8888

connection = openerplib.get_connection(hostname=SOURCE_HOSTNAME, database=SOURCE_DATABASE, \

login=SOURCE_USER, password=SOURCE_PASSWORD, port=SOURCE_PORT)

# destination database

DEST_USER = 'admin'

DEST_PASSWORD = 'a'

DEST_HOSTNAME = 'localhost'

DEST_DATABASE = 'openerp_7'

DEST_PORT = 8000

new_connection = openerplib.get_connection(hostname=DEST_HOSTNAME, database=DEST_DATABASE, \

login=DEST_USER, password=DEST_PASSWORD, port=DEST_PORT)

#product.product

source_product_model = connection.get_model("product.product") # source database product model

product_ids = source_product_model.search([]) # source product ids

destination_product_model = new_connection.get_model("product.product") # destination database product template model

for product_id in product_ids:

     old_product = source_product_model.read(product_id, ['image', 'ean13'])

     new_product_ids = destination_product_model.search([('ean13', '=', old_product['ean13'])])

     if new_product_ids:

         new_product = destination_product_model.read(new_product_ids[0], ['name', 'image'])

         if not new_product['image']:

             print "Product is updated with image...........",new_product['name']

             destination_product_model.write(new_product_ids[0], {'image': old_product['image']})

print "Succesfully updated all products in database..........."

For more details: You may Contact us....

Contact us