def _build_odoo_env(self, odoo_args): odoo.tools.config.parse_config(odoo_args) dbname = odoo.tools.config['db_name'] odoo.tools.config['workers'] = 0 odoo.tools.config['xmlrpc'] = False if not dbname: argparse.ArgumentParser().error( "please provide a database name though Odoo options (either " "-d or an Odoo configuration file)") logging.getLogger(odoo_logger).setLevel(logging.ERROR) odoo.service.server.start(preload=[], stop=True) # odoo.service.server.start() modifies the SIGINT signal by its own # one which in fact prevents us to stop anthem with Ctrl-c. # Restore the default one. signal.signal(signal.SIGINT, signal.default_int_handler) odoo_version = odoo.release.version_info[0] # On saas versions this will be "saas-XX" where XX is the odoo version if not isinstance(odoo_version, int): odoo_version = int(odoo_version.lstrip(string.ascii_letters + '-~')) if odoo_version > 9: registry = odoo.modules.registry.Registry(dbname) else: registry = odoo.modules.registry.RegistryManager.get(dbname) cr = registry.cursor() uid = odoo.SUPERUSER_ID Environment.reset() context = Environment(cr, uid, {})['res.users'].context_get() return Environment(cr, uid, context)
def _build_odoo_env(self, odoo_args): odoo.tools.config.parse_config(odoo_args) dbname = odoo.tools.config['db_name'] odoo.tools.config['workers'] = 0 odoo.tools.config['xmlrpc'] = False if not dbname: argparse.ArgumentParser().error( "please provide a database name though Odoo options (either " "-d or an Odoo configuration file)" ) logging.getLogger(odoo_logger).setLevel(logging.ERROR) odoo.service.server.start(preload=[], stop=True) # odoo.service.server.start() modifies the SIGINT signal by its own # one which in fact prevents us to stop anthem with Ctrl-c. # Restore the default one. signal.signal(signal.SIGINT, signal.default_int_handler) if odoo.release.version_info[0] > 9: registry = odoo.modules.registry.Registry(dbname) else: registry = odoo.modules.registry.RegistryManager.get(dbname) cr = registry.cursor() uid = odoo.SUPERUSER_ID Environment.reset() context = Environment(cr, uid, {})['res.users'].context_get() return Environment(cr, uid, context)
def connect(dbname='trunk', uid=1, context=None): from odoo.modules.registry import RegistryManager from odoo.api import Environment r = RegistryManager.get(dbname) cr = r.cursor() Environment.reset() env = Environment(cr, uid, context or {}) print('Connected to %s with user %s %s' % (dbname, env.uid, env.user.name)) return env
def get_employee_records(): env = connect(config.get('db_name')) cursor = env.cr cursor.execute(EMPLOYEES_QUERY) while True: try: rec = cursor.next() yield rec except StopIteration: break cursor.close() Environment.reset()
def _build_odoo_env(self, odoo_args): odoo.tools.config.parse_config(odoo_args) dbname = odoo.tools.config['db_name'] if not dbname: argparse.ArgumentParser().error( "please provide a database name though Odoo options (either " "-d or an Odoo configuration file)") logging.getLogger(odoo_logger).setLevel(logging.ERROR) odoo.service.server.start(preload=[], stop=True) # odoo.service.server.start() modifies the SIGINT signal by its own # one which in fact prevents us to stop anthem with Ctrl-c. # Restore the default one. signal.signal(signal.SIGINT, signal.default_int_handler) registry = odoo.modules.registry.RegistryManager.get(dbname) cr = registry.cursor() uid = odoo.SUPERUSER_ID Environment.reset() context = Environment(cr, uid, {})['res.users'].context_get() return Environment(cr, uid, context)
def connect(uid=1, context=None): reg = RegistryManager.get(config.get('db_name')) cr = reg.cursor() Environment.reset() env = Environment(cr, uid, context or {}) return env