Am 14.03.2014 12:14, schrieb Jean C:
>
> 2014-03-14 11:58 GMT+01:00 Cédric Krier <[email protected]
> <mailto:[email protected]>>:
>
> It makes no senses to have the getter method of Function field
> creating
> instances.
>
>
> Well I think Sergi's use case is valid. He does not create instances,
> he just
> wants to display computed data, which is precisely the point of Function
> fields.
I think you can do it in read of the ModelView returning a list of
dictionaries with key 'id' and values for all fields_names. Also I guess
you need to implement search by your own. The getter of the
function.field need to return a dictionary with the ids you want to
compute.
An exampe what we did once (in 2.4):
class BurningtimeComputed(ModelView):
_name = 'coating.timecomputed'
layer = fields.Char('Coating Layer')
oventime = fields.Integer('Oventime')
def search(self, args, offset=0, limit=None, order=None, count=False,
query_string=False):
return args[0][2]
defread(self,ids,fields_names=None):
pool = Pool()
rel_obj = pool.get('coating.spec2layer')
layer_obj = pool.get('coating.sl')
rel = rel_obj.browse(ids)
res = []
ids.reverse()
for ob in rel:
#do some computing
layer = computed
oventime = computed
dct = {'id':ob.id,
'layer': layer,
'oventime': oventime}
res.append(dct)
return res
class OtherModel(ModelSQL, ModelView):
burning_temp =
fields.Function(fields.One2Many('coating.computed', None, 'Burning Temp'),
'get_burningtemp')
def get_burningtemp(self, ids, name):
res = {}
rel_obj = Pool().get('coating.spec2layer')
for ob in self.browse(ids):
# here you need to pass some ids to the first model
for computing
# something - we are sending ids of a other model
which
# keeps informations we need
rel = rel_obj.search([('spec', '=', ob.id),
('layer', '!=', False)])
res[ob.id] = rel
return res