bzr revid: nch@tinyerp.com-20090701070300-ms8w4ly7fmaxnzfl
This commit is contained in:
Naresh Choksy 2009-07-01 12:33:00 +05:30
commit e0ee70c39a
3 changed files with 16 additions and 5 deletions

View File

@ -408,6 +408,9 @@ class ir_model_data(osv.osv):
'date_update': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'noupdate': lambda *a: False
}
_sql_constraints = [
('module_name_uniq', 'unique(name, module)', 'You can not have multiple records with the same id for the same module'),
]
def __init__(self, pool, cr):
osv.osv.__init__(self, pool, cr)
@ -415,11 +418,13 @@ class ir_model_data(osv.osv):
self.doinit = True
self.unlink_mark = {}
def _get_id(self,cr, uid, module, xml_id):
@tools.cache()
def _get_id(self, cr, uid, module, xml_id):
ids = self.search(cr, uid, [('module','=',module),('name','=', xml_id)])
assert len(ids)==1, '%d reference(s) to %s.%s. You should have one and only one !' % (len(ids), module, xml_id)
if not ids:
raise Exception('No references to %s.%s' % (module, xml_id))
# the sql constraints ensure us we have only one result
return ids[0]
_get_id = tools.cache(skiparg=2)(_get_id)
def _update_dummy(self,cr, uid, model, module, xml_id=False, store=True):
if not xml_id:

View File

@ -1633,7 +1633,9 @@ class orm(orm_template):
('int4', 'float', get_pg_type(f)[1], '::'+get_pg_type(f)[1]),
('date', 'datetime', 'TIMESTAMP', '::TIMESTAMP'),
]
if f_pg_type == 'varchar' and f._type == 'char' and f_pg_size != f.size:
# !!! Avoid reduction of varchar field !!!
if f_pg_type == 'varchar' and f._type == 'char' and f_pg_size < f.size:
# if f_pg_type == 'varchar' and f._type == 'char' and f_pg_size != f.size:
logger.notifyChannel('orm', netsvc.LOG_INFO, "column '%s' in table '%s' changed size" % (k, self._table))
cr.execute('ALTER TABLE "%s" RENAME COLUMN "%s" TO temp_change_size' % (self._table, k))
cr.execute('ALTER TABLE "%s" ADD COLUMN "%s" VARCHAR(%d)' % (self._table, k, f.size))

View File

@ -256,7 +256,11 @@ form: module.record_id""" % (xml_id,)
if len(d_search):
ids = self.pool.get(d_model).search(cr,self.uid,eval(d_search))
if len(d_id):
ids.append(self.id_get(cr, d_model, d_id))
try:
ids.append(self.id_get(cr, d_model, d_id))
except:
# d_id cannot be found. doesn't matter in this case
pass
if len(ids):
self.pool.get(d_model).unlink(cr, self.uid, ids)
self.pool.get('ir.model.data')._unlink(cr, self.uid, d_model, ids, direct=True)