if mode=='.id':
id = int(id)
obj_model = self.pool.get(model_name)
- ids = obj_model.search(cr, uid, [('id', '=', int(id))], context=context)
+ dom = [('id', '=', id)]
+ if obj_model._columns.get('active'):
+ dom.append(('active', 'in', ['True','False']))
+ ids = obj_model.search(cr, uid, dom, context=context)
if not len(ids):
raise Exception(_("Database ID doesn't exist: %s : %s") %(model_name, id))
elif mode=='id':
done = {}
for i in range(len(fields)):
res = False
- if not line[i]:
- continue
if i >= len(line):
raise Exception(_('Please check that all your lines have %d columns.') % (len(fields),))
mode = False
else:
mode = field[len(prefix)+1]
- res = _get_id(relation, line[i], current_module, mode)
+ res = line[i] and _get_id(relation, line[i], current_module, mode) or False
elif fields_def[field[len(prefix)]]['type']=='many2many':
relation = fields_def[field[len(prefix)]]['relation']
# TODO: improve this by using csv.csv_reader
res = []
- for db_id in line[i].split(config.get('csv_internal_sep')):
- res.append( _get_id(relation, db_id, current_module, mode) )
+ if line[i]:
+ for db_id in line[i].split(config.get('csv_internal_sep')):
+ res.append( _get_id(relation, db_id, current_module, mode) )
res = [(6,0,res)]
elif fields_def[field[len(prefix)]]['type'] == 'integer':
return self.datas.keys()
res = []
- counter = 0
+ counter = 1
#Find the value of dict
f = False
if result:
for id, data in self.datas.items():
- counter = counter + 1
data['id'] = id
- if limit and (counter > int(limit)):
+ if limit and (counter > int(limit) + int(offset)):
break
f = True
for arg in result:
val = eval('data[arg[0]]'+arg[1] +' arg[2]', locals())
elif arg[1] in ['ilike']:
val = (str(data[arg[0]]).find(str(arg[2]))!=-1)
-
f = f and val
-
if f:
- res.append(id)
+ if counter > offset:
+ res.append(id)
+ counter += 1
if count:
return len(res)
return res or []
class orm(orm_template):
_sql_constraints = []
_table = None
- _all_columns = {}
_protected = ['read', 'write', 'create', 'default_get', 'perm_read', 'unlink', 'fields_get', 'fields_view_get', 'search', 'name_get', 'distinct_field_get', 'name_search', 'copy', 'import_data', 'search_count', 'exists']
__logger = logging.getLogger('orm')
__schema = logging.getLogger('orm.schema')
group_count = group_by = groupby
if groupby:
if fget.get(groupby):
- if fget[groupby]['type'] in ('date', 'datetime'):
- flist = "to_char(%s,'yyyy-mm') as %s " % (qualified_groupby_field, groupby)
- groupby = "to_char(%s,'yyyy-mm')" % (qualified_groupby_field)
- qualified_groupby_field = groupby
+ groupby_type = fget[groupby]['type']
+ if groupby_type in ('date', 'datetime'):
+ qualified_groupby_field = "to_char(%s,'yyyy-mm')" % qualified_groupby_field
+ flist = "%s as %s " % (qualified_groupby_field, groupby)
+ elif groupby_type == 'boolean':
+ qualified_groupby_field = "coalesce(%s,false)" % qualified_groupby_field
+ flist = "%s as %s " % (qualified_groupby_field, groupby)
else:
flist = qualified_groupby_field
else:
while field in current_table._inherit_fields and not field in current_table._columns:
parent_model_name = current_table._inherit_fields[field][0]
parent_table = self.pool.get(parent_model_name)
- current_table._inherits_join_add(parent_model_name, query)
+ self._inherits_join_add(parent_model_name, query)
current_table = parent_table
return '"%s".%s' % (current_table._table, field)
f = self._columns[store_field]
if hasattr(f, 'digits_change'):
f.digits_change(cr)
+ def not_this_field(stored_func):
+ x, y, z, e, f, l = stored_func
+ return x != self._name or y != store_field
+ self.pool._store_function[self._name] = filter(not_this_field, self.pool._store_function.get(self._name, []))
if not isinstance(f, fields.function):
continue
if not f.store:
continue
- if self._columns[store_field].store is True:
+ sm = f.store
+ if sm is True:
sm = {self._name: (lambda self, cr, uid, ids, c={}: ids, None, 10, None)}
- else:
- sm = self._columns[store_field].store
for object, aa in sm.items():
if len(aa) == 4:
(fnct, fields2, order, length) = aa
raise except_orm('Error',
('Invalid function definition %s in object %s !\nYou must use the definition: store={object:(fnct, fields, priority, time length)}.' % (store_field, self._name)))
self.pool._store_function.setdefault(object, [])
- ok = True
- for x, y, z, e, f, l in self.pool._store_function[object]:
- if (x==self._name) and (y==store_field) and (e==fields2):
- if f == order:
- ok = False
- if ok:
- self.pool._store_function[object].append( (self._name, store_field, fnct, fields2, order, length))
- self.pool._store_function[object].sort(lambda x, y: cmp(x[4], y[4]))
+ self.pool._store_function[object].append((self._name, store_field, fnct, tuple(fields2) if fields2 else None, order, length))
+ self.pool._store_function[object].sort(lambda x, y: cmp(x[4], y[4]))
for (key, _, msg) in self._sql_constraints:
self.pool._sql_error[self._table+'_'+key] = msg
for table in self._inherits:
res.update(self.pool.get(table)._inherit_fields)
for col in self.pool.get(table)._columns.keys():
- res[col] = (table, self._inherits[table], self.pool.get(table)._columns[col], table)
+ res[col] = (table, self._inherits[table], self.pool.get(table)._columns[col])
for col in self.pool.get(table)._inherit_fields.keys():
- res[col] = (table, self._inherits[table], self.pool.get(table)._inherit_fields[col][2], self.pool.get(table)._inherit_fields[col][3])
+ res[col] = (table, self._inherits[table], self.pool.get(table)._inherit_fields[col][2])
self._inherit_fields = res
- self._all_columns = self._get_column_infos()
self._inherits_reload_src()
- def _get_column_infos(self):
- """Returns a dict mapping all fields names (direct fields and
- inherited field via _inherits) to a ``column_info`` struct
- giving detailed columns """
- result = {}
- for k, (parent, m2o, col, original_parent) in self._inherit_fields.iteritems():
- result[k] = fields.column_info(k, col, parent, m2o, original_parent)
- for k, col in self._columns.iteritems():
- result[k] = fields.column_info(k, col)
- return result
-
def _inherits_check(self):
for table, field_name in self._inherits.items():
if field_name not in self._columns:
upd_todo = []
for v in vals.keys():
if v in self._inherit_fields:
- (table, col, col_detail, original_parent) = self._inherit_fields[v]
+ (table, col, col_detail) = self._inherit_fields[v]
tocreate[table][v] = vals[v]
del vals[v]
else:
else:
continue # ignore non-readable or "non-joinable" fields
elif order_field in self._inherit_fields:
- parent_obj = self.pool.get(self._inherit_fields[order_field][3])
+ parent_obj = self.pool.get(self._inherit_fields[order_field][0])
order_column = parent_obj._columns[order_field]
if order_column._classic_read:
inner_clause = self._inherits_join_calc(order_field, query)
for parent_column in ['parent_left', 'parent_right']:
data.pop(parent_column, None)
- # remove _inherits field's from data recursively, missing parents will
- # be created by create() (so that copy() copy everything).
- def remove_ids(inherits_dict):
- for parent_table in inherits_dict:
- del data[inherits_dict[parent_table]]
- remove_ids(self.pool.get(parent_table)._inherits)
- remove_ids(self._inherits)
+ for v in self._inherits:
+ del data[self._inherits[v]]
return data
def copy_translations(self, cr, uid, old_id, new_id, context=None):