Skip to Content
Menu
This question has been flagged
1 Reply
4141 Views

I installed odoo 10 in Ubuntu 16.04, I have 2 databases at the same server, I like to create a module that access data from table in another database, how I can do that? Thanks for your help.

Avatar
Discard
Best Answer

You can do it by creating a new environment for another database.

Refer following sample code:

from odoo import api, models, registry, SUPERUSER_ID

class my_class(models.Model):

@api.multi
def get_data_from_database(self):
with registry('another_database_name') as new_cr:
env = api.Environment(new_cr, SUPERUSER_ID, {})
partner = env['res.partner'].search([('name', '=', 'ERP HARBOR CONSULTING SERVICES')], limit=1)
print partner.name, partner.phone

Hope this will help you.

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com  website: http://www.erpharbor.com
Avatar
Discard