Odoo Help

0

Odoo Cron Creating DB

By
Ashish Singh
on 5/27/15, 7:23 AM 1,552 views

I want to create new db once an automatic schedule is run


def db_creation_cron(self, cr, uid, context=None):

if context is None: context = {}

user = 'admin'

pwd = 'admin'

super_user_pwd = openerp.tools.config['admin_passwd']

db_created = request.session.proxy("db").create_database(

super_user_pwd,

'RJ_005',

False,

'en_US',

pwd)

return True


once secheduler is run my method call but once

db_created = request.session.proxy("db").create_database(super_user_pwd,'RJ_005',False,'en_US',pwd) called i get error


2015-05-27 10:05:38,484 2508 ERROR BLS_14 openerp.addons.module_price.module_price: In DB Creation rj_005

2015-05-27 10:05:38,485 2508 ERROR BLS_14 openerp.addons.base.ir.ir_cron: Call of self.pool.get('res.partner').db_creation_cron(cr, uid, *()) failed in Job 17

Traceback (most recent call last):

File "/opt/odoo/odoo/openerp/addons/base/ir/ir_cron.py", line 138, in _callback

getattr(model, method_name)(cr, uid, *args)

File "/opt/odoo/odoo/openerp/api.py", line 237, in wrapper

return old_api(self, *args, **kwargs)

File "/opt/odoo/odoo/addons/module_price/module_price.py", line 159, in create_db

db_created = request.session.proxy("db").create_database(

File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 338, in __getattr__

return getattr(self._get_current_object(), name)

File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 297, in _get_current_object

return self.__local()

File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 132, in _lookup

raise RuntimeError('object unbound')

RuntimeError: object unbound



@Ashish,

Good question, i'm also interested in this for demonstration databases. I will post back here if I find anything. If you could do likewise I would appreciate it also.

Luke Branch
on 5/28/15, 3:42 AM
0
manali(odoo developer)
On 9/19/15, 12:42 AM

hi ashish, 

             this code is giving err, at the time of when function is running in cron,coz its not getting object.but same is working fine on odoo button.i created db by postgress in my code lyk below.

con = connect(dbname='postgres',user='user', host = 'localhost', password='password')

dbname = db_name

con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)

cur = con.cursor()

_logger.error('db_name++++++++++++++++++++++++++++%s',dbname)

cur.execute('CREATE DATABASE ' + dbname)

cur.close()

its working!!!!!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/27/15, 7:23 AM
Seen: 1552 times
Last updated: 9/19/15, 12:42 AM