diff --git a/bin/osv/orm.py b/bin/osv/orm.py index b93a715ceb0..47036787211 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -2130,7 +2130,10 @@ class orm(orm_template): for order, object, ids, fields in result_store: if object<>self._name: - self.pool.get(object)._store_set_values(cr, uid, ids, fields, context) + cr.execute('select id from '+self._table+' where id in ('+','.join(map(str, ids))+')') + ids = map(lambda x: x[0], cr.fetchall()) + if ids: + self.pool.get(object)._store_set_values(cr, uid, ids, fields, context) return True # @@ -2281,49 +2284,61 @@ class orm(orm_template): if self.pool._init: self.pool._init_parent[self._name]=True else: - if vals[self._parent_name]: - cr.execute('select parent_left,parent_right from '+self._table+' where id=%s', (vals[self._parent_name],)) - else: - cr.execute('SELECT parent_left,parent_right FROM '+self._table+' WHERE id IS NULL') - res = cr.fetchone() - if res: - pleft,pright = res - else: - cr.execute('select max(parent_right),max(parent_right)+1 from '+self._table) - pleft,pright = cr.fetchone() - cr.execute('select parent_left,parent_right,id from '+self._table+' where id in ('+','.join(map(lambda x:'%s',ids))+')', ids) - dest = pleft + 1 - for cleft,cright,cid in cr.fetchall(): - if cleft > pleft: - treeshift = pleft - cleft + 1 - leftbound = pleft+1 - rightbound = cleft-1 - cwidth = cright-cleft+1 - leftrange = cright - rightrange = pleft + for id in ids: + if vals[self._parent_name]: + cr.execute('select parent_left,parent_right,id from '+self._table+' where parent_id=%s order by '+(self._parent_order or self._order), (vals[self._parent_name],)) + pleft_old = pright_old = None + result_p = cr.fetchall() + for (pleft,pright,pid) in result_p: + if pid == id: + break + pleft_old = pleft + pright_old = pright + if not pleft_old: + cr.execute('select parent_left,parent_right from '+self._table+' where id=%s', (vals[self._parent_name],)) + pleft_old,pright_old = cr.fetchone() + res = (pleft_old, pright_old) else: - treeshift = pleft - cright - leftbound = cright + 1 - rightbound = pleft - cwidth = cleft-cright-1 - leftrange = pleft+1 - rightrange = cleft - cr.execute('UPDATE '+self._table+''' - SET - parent_left = CASE - WHEN parent_left BETWEEN %s AND %s THEN parent_left + %s - WHEN parent_left BETWEEN %s AND %s THEN parent_left + %s - ELSE parent_left - END, - parent_right = CASE - WHEN parent_right BETWEEN %s AND %s THEN parent_right + %s - WHEN parent_right BETWEEN %s AND %s THEN parent_right + %s - ELSE parent_right - END - WHERE - parent_left<%s OR parent_right>%s; - ''', (leftbound,rightbound,cwidth,cleft,cright,treeshift,leftbound,rightbound, - cwidth,cleft,cright,treeshift,leftrange,rightrange)) + cr.execute('SELECT parent_left,parent_right FROM '+self._table+' WHERE id IS NULL') + res = cr.fetchone() + if res: + pleft,pright = res + else: + cr.execute('select max(parent_right),max(parent_right)+1 from '+self._table) + pleft,pright = cr.fetchone() + cr.execute('select parent_left,parent_right,id from '+self._table+' where id in ('+','.join(map(lambda x:'%s',ids))+')', ids) + dest = pleft + 1 + for cleft,cright,cid in cr.fetchall(): + if cleft > pleft: + treeshift = pleft - cleft + 1 + leftbound = pleft+1 + rightbound = cleft-1 + cwidth = cright-cleft+1 + leftrange = cright + rightrange = pleft + else: + treeshift = pleft - cright + leftbound = cright + 1 + rightbound = pleft + cwidth = cleft-cright-1 + leftrange = pleft+1 + rightrange = cleft + cr.execute('UPDATE '+self._table+''' + SET + parent_left = CASE + WHEN parent_left BETWEEN %s AND %s THEN parent_left + %s + WHEN parent_left BETWEEN %s AND %s THEN parent_left + %s + ELSE parent_left + END, + parent_right = CASE + WHEN parent_right BETWEEN %s AND %s THEN parent_right + %s + WHEN parent_right BETWEEN %s AND %s THEN parent_right + %s + ELSE parent_right + END + WHERE + parent_left<%s OR parent_right>%s; + ''', (leftbound,rightbound,cwidth,cleft,cright,treeshift,leftbound,rightbound, + cwidth,cleft,cright,treeshift,leftrange,rightrange)) result = self._store_get_values(cr, user, ids, vals.keys(), context) for order, object, ids, fields in result: @@ -2441,8 +2456,17 @@ class orm(orm_template): else: parent = vals.get(self._parent_name, False) if parent: - cr.execute('select parent_left from '+self._table+' where id=%s', (parent,)) - pleft = cr.fetchone()[0] + cr.execute('select parent_right from '+self._table+' where parent_id=%s order by '+(self._parent_order or self._order), (parent,)) + pleft_old = None + result_p = cr.fetchall() + for (pleft,) in result_p: + if not pleft: + break + pleft_old = pleft + if not pleft_old: + cr.execute('select parent_left from '+self._table+' where id=%s', (parent,)) + pleft_old = cr.fetchone()[0] + pleft = pleft_old else: cr.execute('select max(parent_right) from '+self._table) pleft = cr.fetchone()[0] or 0 diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index 7e2aef7fd77..6c0b84fb69e 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -170,6 +170,7 @@ class _float_format(float, _format): def __init__(self,value): super(_float_format, self).__init__() self.val = value and str(value) or str(0.00) + def __str__(self): digits = 2 if hasattr(self,'_field') and hasattr(self._field, 'digits') and self._field.digits: @@ -200,12 +201,13 @@ class _int_format(int, _format): class _date_format(str, _format): def __init__(self,value): super(_date_format, self).__init__() - self.val = str(value) - + self.val = value and str(value) or '' + def __str__(self): - if hasattr(self,'name') and self.name: - date = mx.DateTime.strptime(self.name,DT_FORMAT) - return date.strftime(self.lang_obj.date_format) + if self.val: + if hasattr(self,'name') and (self.name): + date = mx.DateTime.strptime(self.name,DT_FORMAT) + return date.strftime(self.lang_obj.date_format) return self.val # if not self.object._context: # return self.name @@ -222,12 +224,13 @@ class _date_format(str, _format): class _dttime_format(str, _format): def __init__(self,value): super(_dttime_format, self).__init__() - self.val = str(value) + self.val = value and str(value) or '' def __str__(self): - if hasattr(self,'name') and self.name: - datetime = mx.DateTime.strptime(self.name,DHM_FORMAT) - return datetime.strftime(self.lang_obj.date_format+ " " + self.lang_obj.time_format) + if self.val: + if hasattr(self,'name') and self.name: + datetime = mx.DateTime.strptime(self.name,DHM_FORMAT) + return datetime.strftime(self.lang_obj.date_format+ " " + self.lang_obj.time_format) return self.val @@ -381,6 +384,8 @@ class rml_parse(object): lang = self.localcontext.get('lang', 'en_US') or 'en_US' lang_obj = pool_lang.browse(self.cr,self.uid,pool_lang.search(self.cr,self.uid,[('code','=',lang)])[0]) if date or date_time: + if not str(value): + return '' date_format = lang_obj.date_format if date_time: date_format = lang_obj.date_format + " " + lang_obj.time_format diff --git a/bin/tools/convert.py b/bin/tools/convert.py index dedc7abb858..71bbb800cf5 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -677,7 +677,12 @@ form: module.record_id""" % (xml_id,) if self.isnoupdate(data_node) and self.mode != 'init': # check if the xml record has an id string if rec_id: - id = self.pool.get('ir.model.data')._update_dummy(cr, self.uid, rec_model, self.module, rec_id) + if '.' in rec_id: + module,rec_id2 = rec_id.split('.') + else: + module = self.module + rec_id2 = rec_id + id = self.pool.get('ir.model.data')._update_dummy(cr, self.uid, rec_model, module, rec_id2) # check if the resource already existed at the last update if id: # if it existed, we don't update the data, but we need to