From a0b7a8f4e6b9da9689a423f3de30e74ea7892ece Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Tue, 9 Dec 2008 15:10:34 +0100 Subject: [PATCH] modifs bzr revid: fp@tinyerp.com-20081209141034-cj0f9clfgkr1eorz --- bin/osv/orm.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index c9c813da720..165bc86e126 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -308,12 +308,16 @@ class orm_template(object): cr.execute('SELECT nextval(%s)', ('ir_model_id_seq',)) model_id = cr.fetchone()[0] cr.execute("INSERT INTO ir_model (id,model, name, info,state) VALUES (%s, %s, %s, %s,%s)", (model_id, self._name, self._description, self.__doc__, 'base')) - if 'module' in context: - cr.execute("INSERT INTO ir_model_data (name,date_init,date_update,module,model,res_id) VALUES (%s, now(), now(), %s, %s, %s)", \ - ('model_'+self._name.replace('.','_'), context['module'], 'ir.model', model_id) - ) else: model_id = cr.fetchone()[0] + if 'module' in context: + name_id = 'model_'+self._name.replace('.','_') + cr.execute('select * from ir_model_data where name=%s and res_id=%s', (name_id,model_id)) + if not cr.rowcount: + cr.execute("INSERT INTO ir_model_data (name,date_init,date_update,module,model,res_id) VALUES (%s, now(), now(), %s, %s, %s)", \ + (name_id, context['module'], 'ir.model', model_id) + ) + cr.commit() cr.execute("SELECT * FROM ir_model_fields WHERE model=%s", (self._name,))