Hello there,
I am using latest version 1.7 of Tryton (as of today) and have a lot
of problems with a simple Functions field. I don't see what I could be
doing wrong, but maybe some of you can spot an error.
I have a model which contain various fields. For one Many2One field I
need an ID for its Domain to evaluate, but this ID is not in the
current model. I thought I could make an Integer function field in the
same model, that would simply search and return the ID I need, and
then Evaluate this field in the Many2One field. Not sure if this would
work, but worth trying.
However, I have major problems creating the Function field.
In essence I have something like:
class CRMProject(ModelSQL, ModelView):
""" CRM Project """
_name = "crm.project"
_description = __doc__
#Many fields (which should be unrelated to this problem) removed
to save space
id_listtype_projectstatus = fields.Function(fields.Integer('ID
listtype ProjectStatus'), 'get_id_listtype_projectstatus')
def get_id_listtype_projectstatus(self, ids, names):
listype_obj = self.pool.get('crm.list.type')
listtype_ids = listype_obj.search([('code', '=',
'project_status')])
if len(listtype_ids) > 0:
listtype_id = listtype_ids[0]
else:
listtype_id = 0
print listtype_id
res = {}
for id in ids:
res[id] = listtype_id
print res
return res
As you can see I have debugged the code and see the expected values
being returned. I only reference the id_listtype_projectstatus in the
view to display it and do not use the field anywhere else yet.
The two print results give the following results:
4
{3: 4}
The error that the client shows is:
Traceback (most recent call last):
File "/trytond/protocols/netrpc.py", line 47, in run
res = dispatch(host, port, 'NetRPC', *msg)
File "/trytond/protocols/dispatcher.py", line 136, in dispatch
res = getattr(obj, method)(*args, **kargs)
File "/trytond/model/modelsql.py", line 617, in read
record[field] = res2[field][record['id']]
TypeError: 'int' object is unsubscriptable
In a desperate move I have changed the "for id in ids:" line to "for
rec in self.browse(ids):" line and changed the references to id to
rec.id, but this did produce the same result.
Can anyone spot my error?
Best regards,
Vincent
--
[email protected] mailing list