In this article, you will learn how to sync or integrate odoo13 from odoo8. The purpose of doing this, we are going to insert a record from odoo8 to odoo13. To achieve this functionality we have to use Odoo Web Services API.
Odoo Web Services API (XML-RPC)
Sync odoo8 to odoo13 odoo requires users of the API to be authenticated. Below are the steps to connect and insert records from odoo 8 to odoo 13.
Recommend:
Connecting to Odoo from third party apps using XML-RPC
Odoo Web Controller
- Make a Connection to authenticate API user
- Search records in Od0013 model (if records do not exist then insert the record)
- Insert or create a new record from odoo8 to odoo13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@api.multi | |
def connection(self): | |
url = 'https://odoo 13 url goes here' | |
db = 'database name goes here' | |
username = 'admin' | |
password = 'admin' | |
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) | |
uid = common.authenticate(db, username, password, {}) | |
if uid: | |
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) | |
return {'models': models, 'db': db, 'uid': uid, 'password': password} | |
else: | |
raise ValidationError('Authentication Failed!') | |
@api.multi | |
def search_in_odoo13(self, odoo13_model_name, filters): | |
get_auth = self.connection() | |
models, db, uid, password = get_auth['models'], get_auth['db'], get_auth['uid'], get_auth['password'] | |
data = models.execute_kw(db, uid, password, odoo13_model_name, 'search', [filters]) | |
return data | |
@api.one | |
def buttonn_to_create_record(self): | |
get_auth = self.connection() | |
models, db, uid, password = get_auth['models'], get_auth['db'], get_auth['uid'], get_auth['password'] | |
employee_id = self.search_in_odoo13('odoo13.model.name',filters=[['name', '=', 'Jhon'],['department_id', '=', 3]]) | |
if employee_id == []: | |
employee_values = { | |
'name': 'Test', | |
'company_id': 1, | |
'department_id': 3 | |
} | |
odoo13_employee_id = models.execute_kw(db, uid, password,'odoo13.model.name', 'create',[employee_values]) |
1 Comments
I'm trying to integrate a form from html website to odoo via GET/POST so that html file will send the data to odoo and save in odoo, displayed in odoo module. Can I achieve it?
ReplyDelete