parent
17fa5c7a07
commit
f565d96c77
|
@ -230,6 +230,7 @@ class binary(_column):
|
||||||
|
|
||||||
get = get_memory
|
get = get_memory
|
||||||
|
|
||||||
|
|
||||||
class selection(_column):
|
class selection(_column):
|
||||||
_type = 'selection'
|
_type = 'selection'
|
||||||
|
|
||||||
|
@ -331,7 +332,7 @@ class many2one(_column):
|
||||||
context = {}
|
context = {}
|
||||||
obj = obj_src.pool.get(self._obj)
|
obj = obj_src.pool.get(self._obj)
|
||||||
self._table = obj_src.pool.get(self._obj)._table
|
self._table = obj_src.pool.get(self._obj)._table
|
||||||
if type(values)==type([]):
|
if type(values) == type([]):
|
||||||
for act in values:
|
for act in values:
|
||||||
if act[0] == 0:
|
if act[0] == 0:
|
||||||
id_new = obj.create(cr, act[2])
|
id_new = obj.create(cr, act[2])
|
||||||
|
@ -495,7 +496,7 @@ class many2many(_column):
|
||||||
|
|
||||||
d1, d2 = obj.pool.get('ir.rule').domain_get(cr, user, obj._name)
|
d1, d2 = obj.pool.get('ir.rule').domain_get(cr, user, obj._name)
|
||||||
if d1:
|
if d1:
|
||||||
d1 = ' and '+d1
|
d1 = ' and ' + d1
|
||||||
|
|
||||||
cr.execute('SELECT '+self._rel+'.'+self._id2+','+self._rel+'.'+self._id1+' \
|
cr.execute('SELECT '+self._rel+'.'+self._id2+','+self._rel+'.'+self._id1+' \
|
||||||
FROM '+self._rel+' , '+obj._table+' \
|
FROM '+self._rel+' , '+obj._table+' \
|
||||||
|
@ -531,7 +532,7 @@ class many2many(_column):
|
||||||
|
|
||||||
d1, d2 = obj.pool.get('ir.rule').domain_get(cr, user, obj._name)
|
d1, d2 = obj.pool.get('ir.rule').domain_get(cr, user, obj._name)
|
||||||
if d1:
|
if d1:
|
||||||
d1 = ' and '+d1
|
d1 = ' and ' + d1
|
||||||
cr.execute('delete from '+self._rel+' where '+self._id1+'=%d AND '+self._id2+' IN (SELECT '+self._rel+'.'+self._id2+' FROM '+self._rel+', '+obj._table+' WHERE '+self._rel+'.'+self._id1+'=%d AND '+self._rel+'.'+self._id2+' = '+obj._table+'.id '+ d1 +')', [id, id]+d2)
|
cr.execute('delete from '+self._rel+' where '+self._id1+'=%d AND '+self._id2+' IN (SELECT '+self._rel+'.'+self._id2+' FROM '+self._rel+', '+obj._table+' WHERE '+self._rel+'.'+self._id1+'=%d AND '+self._rel+'.'+self._id2+' = '+obj._table+'.id '+ d1 +')', [id, id]+d2)
|
||||||
|
|
||||||
for act_nbr in act[2]:
|
for act_nbr in act[2]:
|
||||||
|
@ -638,92 +639,93 @@ class function(_column):
|
||||||
class related(function):
|
class related(function):
|
||||||
|
|
||||||
def _fnct_search(self, tobj, cr, uid, obj=None, name=None, context=None):
|
def _fnct_search(self, tobj, cr, uid, obj=None, name=None, context=None):
|
||||||
where_flag=0
|
where_flag = 0
|
||||||
where=" where"
|
where = " where"
|
||||||
query = "select %s.id from %s"%(obj._table,obj._table)
|
query = "select %s.id from %s" % (obj._table, obj._table)
|
||||||
relation_child=obj._name
|
relation_child = obj._name
|
||||||
relation=obj._name
|
relation = obj._name
|
||||||
for i in range(len(self._arg)):
|
for i in range(len(self._arg)):
|
||||||
field_detail=self._field_get(cr,uid,obj,relation,self._arg[i])
|
field_detail = self._field_get(cr, uid, obj, relation, self._arg[i])
|
||||||
relation=field_detail[0]
|
relation = field_detail[0]
|
||||||
if field_detail[1] in ('one2many','many2many'):
|
if field_detail[1] in ('one2many', 'many2many'):
|
||||||
obj_child=obj.pool.get(field_detail[2][self._arg[i]]['relation'])
|
obj_child = obj.pool.get(field_detail[2][self._arg[i]]['relation'])
|
||||||
field_detail_child=obj_child.fields_get(cr,uid,)
|
field_detail_child = obj_child.fields_get(cr, uid,)
|
||||||
|
|
||||||
fields_filter = dict(filter(lambda x:x[1].get('relation',False)
|
fields_filter = dict(filter(lambda x: x[1].get('relation', False)
|
||||||
and x[1].get('relation') == relation_child
|
and x[1].get('relation') == relation_child
|
||||||
and x[1].get('type')=='many2one',field_detail_child.items()))
|
and x[1].get('type')=='many2one', field_detail_child.items()))
|
||||||
query +=" inner join %s on %s.id = %s.%s"%(obj_child._table,obj._table,obj_child._table,fields_filter.keys()[0])
|
query += " inner join %s on %s.id = %s.%s" % (obj_child._table, obj._table, obj_child._table, fields_filter.keys()[0])
|
||||||
relation_child=relation
|
relation_child = relation
|
||||||
elif field_detail[1] in ('many2one'):
|
elif field_detail[1] in ('many2one'):
|
||||||
obj_child=obj.pool.get(field_detail[2][self._arg[i]]['relation'])
|
obj_child = obj.pool.get(field_detail[2][self._arg[i]]['relation'])
|
||||||
obj_child2=obj.pool.get(relation_child)
|
obj_child2 = obj.pool.get(relation_child)
|
||||||
if obj_child._name==obj_child2._name:
|
if obj_child._name == obj_child2._name:
|
||||||
# select res_partner.id from res_partner where res_partner.parent_id in(select id from res_partner where res_partner.date >= '2008-10-01');
|
# select res_partner.id from res_partner where res_partner.parent_id in(select id from res_partner where res_partner.date >= '2008-10-01');
|
||||||
# where +=" %s.id = %s.%s in (select id from %s where %s.%s %s %s"%(obj_child._table,obj_child2._table,self._arg[i])
|
# where +=" %s.id = %s.%s in (select id from %s where %s.%s %s %s"%(obj_child._table,obj_child2._table,self._arg[i])
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
query +=" inner join %s on %s.id = %s.%s"%(obj_child._table,obj_child._table,obj_child2._table,self._arg[i])
|
query += " inner join %s on %s.id = %s.%s" % (obj_child._table, obj_child._table, obj_child2._table, self._arg[i])
|
||||||
relation_child=field_detail[0]
|
relation_child = field_detail[0]
|
||||||
if i == (len(self._arg)-1):
|
if i == (len(self._arg)-1):
|
||||||
if obj_child._inherits:
|
if obj_child._inherits:
|
||||||
obj_child_inherits=obj.pool.get(obj_child._inherits.keys()[0])
|
obj_child_inherits = obj.pool.get(obj_child._inherits.keys()[0])
|
||||||
query +=" inner join %s on %s.id = %s.%s"%(obj_child_inherits._table,obj_child_inherits._table,obj_child._table,obj_child._inherits.values()[0])
|
query += " inner join %s on %s.id = %s.%s" % (obj_child_inherits._table, obj_child_inherits._table, obj_child._table, obj_child._inherits.values()[0])
|
||||||
obj_child=obj_child_inherits
|
obj_child = obj_child_inherits
|
||||||
where +=" %s.%s %s '%%%s%%' and"%(obj_child._table,obj_child._rec_name,context[0][1],context[0][2])
|
where += " %s.%s %s '%%%s%%' and" % (obj_child._table, obj_child._rec_name, context[0][1], context[0][2])
|
||||||
else:
|
else:
|
||||||
obj_child=obj.pool.get(relation_child)
|
obj_child = obj.pool.get(relation_child)
|
||||||
if field_detail[1] in ('char'):
|
if field_detail[1] in ('char'):
|
||||||
where +=" %s.%s %s '%%%s%%' and"%(obj_child._table,self._arg[i],context[0][1],context[0][2])
|
where += " %s.%s %s '%%%s%%' and" % (obj_child._table, self._arg[i], context[0][1], context[0][2])
|
||||||
if field_detail[1] in ('date'):
|
if field_detail[1] in ('date'):
|
||||||
where +=" %s.%s %s '%s' and"%(obj_child._table,self._arg[i],context[0][1],context[0][2])
|
where += " %s.%s %s '%s' and" % (obj_child._table, self._arg[i], context[0][1], context[0][2])
|
||||||
if field_detail[1] in ['integer','long','float']:
|
if field_detail[1] in ['integer', 'long', 'float']:
|
||||||
where +=" %s.%s %s '%d' and"%(obj_child._table,self._arg[i],context[0][1],context[0][2])
|
where += " %s.%s %s '%d' and" % (obj_child._table, self._arg[i], context[0][1], context[0][2])
|
||||||
query+=where.rstrip('and')
|
query += where.rstrip('and')
|
||||||
cr.execute(query)
|
cr.execute(query)
|
||||||
ids=[]
|
ids = []
|
||||||
for id in cr.fetchall():
|
for id in cr.fetchall():
|
||||||
ids.append(id[0])
|
ids.append(id[0])
|
||||||
return [('id','in',ids)]
|
return [('id', 'in', ids)]
|
||||||
|
|
||||||
# def _fnct_write(self,obj,cr, uid, ids,values, field_name, args, context=None):
|
# def _fnct_write(self,obj,cr, uid, ids,values, field_name, args, context=None):
|
||||||
# raise 'Not Implemented Yet'
|
# raise 'Not Implemented Yet'
|
||||||
|
|
||||||
def _fnct_read(self,obj,cr, uid, ids, field_name, args, context=None):
|
def _fnct_read(self, obj, cr, uid, ids, field_name, args, context=None):
|
||||||
if not ids: return {}
|
if not ids: return {}
|
||||||
relation=obj._name
|
relation = obj._name
|
||||||
res={}
|
res = {}
|
||||||
objlst = obj.browse(cr,uid,ids)
|
objlst = obj.browse(cr, uid, ids)
|
||||||
for data in objlst:
|
for data in objlst:
|
||||||
t_data=data
|
t_data = data
|
||||||
relation=obj._name
|
relation = obj._name
|
||||||
for i in range(len(self.arg)):
|
for i in range(len(self.arg)):
|
||||||
field_detail=self._field_get(cr,uid,obj,relation,self.arg[i])
|
field_detail = self._field_get(cr, uid, obj, relation, self.arg[i])
|
||||||
relation=field_detail[0]
|
relation = field_detail[0]
|
||||||
if not t_data[self.arg[i]]:
|
if not t_data[self.arg[i]]:
|
||||||
t_data = False
|
t_data = False
|
||||||
break
|
break
|
||||||
if field_detail[1] in ('one2many','many2many'):
|
if field_detail[1] in ('one2many', 'many2many'):
|
||||||
t_data=t_data[self.arg[i]][0]
|
t_data = t_data[self.arg[i]][0]
|
||||||
else:
|
else:
|
||||||
t_data=t_data[self.arg[i]]
|
t_data = t_data[self.arg[i]]
|
||||||
if type(t_data) == type(objlst[0]):
|
if type(t_data) == type(objlst[0]):
|
||||||
res[data.id]=t_data.id
|
res[data.id] = t_data.id
|
||||||
else:
|
else:
|
||||||
res[data.id]=t_data
|
res[data.id] = t_data
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def __init__(self,*arg,**args):
|
def __init__(self, *arg, **args):
|
||||||
self.arg = arg
|
self.arg = arg
|
||||||
super(related, self).__init__(self._fnct_read, arg, fnct_inv_arg=arg,method=True, fnct_search=self._fnct_search,**args)
|
super(related, self).__init__(self._fnct_read, arg, fnct_inv_arg=arg, method=True, fnct_search=self._fnct_search, **args)
|
||||||
|
|
||||||
# TODO: call field_get on the object, not in the DB
|
# TODO: call field_get on the object, not in the DB
|
||||||
def _field_get(self, cr, uid, obj, model_name, prop):
|
def _field_get(self, cr, uid, obj, model_name, prop):
|
||||||
fields=obj.pool.get(model_name).fields_get(cr,uid,)
|
fields = obj.pool.get(model_name).fields_get(cr, uid,)
|
||||||
if fields.get(prop,False):
|
if fields.get(prop, False):
|
||||||
return(fields[prop].get('relation',False),fields[prop].get('type',False),fields)
|
return(fields[prop].get('relation', False), fields[prop].get('type', False), fields)
|
||||||
else:
|
else:
|
||||||
raise 'Field %s not exist in %s'%(prop,model_name)
|
raise 'Field %s not exist in %s' % (prop, model_name)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Serialized fields
|
# Serialized fields
|
||||||
|
|
Loading…
Reference in New Issue