This question has been flagged
2 Replies
5459 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



Avatar
Discard

@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.

Best Answer

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!!!!!

Avatar
Discard