i want to use a function's return as a domain filter.
'product_id' : fields.many2one('product.product', 'products', domain=[('id', 'in',lambda self,cr,uid,ids, context: self._get_technic_warehause(cr,uid,ids,context))])
like that but it sadly wont work.... this is the error i get
2013-12-07 09:59:49,686 16226 ERROR test werkzeug: Error on request:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 159, in run_wsgi
execute(app)
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 146, in execute
application_iter = app(environ, start_response)
File "/opt/openerp/server/openerp/service/wsgi_server.py", line 417, in application
return application_unproxied(environ, start_response)
File "/opt/openerp/server/openerp/service/wsgi_server.py", line 403, in application_unproxied
result = handler(environ, start_response)
File "/opt/openerp/web/addons/web/http.py", line 528, in __call__
return self.dispatch(environ, start_response)
File "/opt/openerp/web/addons/web/http.py", line 487, in __call__
return self.app(environ, start_wrapped)
File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 411, in __call__
return self.app(environ, start_response)
File "/opt/openerp/web/addons/web/http.py", line 553, in dispatch
result = handler(request)
File "/opt/openerp/web/addons/web/http.py", line 618, in <lambda>
return lambda request: JsonRequest(request).dispatch(method)
File "/opt/openerp/web/addons/web/http.py", line 251, in dispatch
body = simplejson.dumps(response)
File "/usr/share/pyshared/simplejson/__init__.py", line 321, in dumps
return _default_encoder.encode(obj)
File "/usr/share/pyshared/simplejson/encoder.py", line 237, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/share/pyshared/simplejson/encoder.py", line 311, in iterencode
return _iterencode(o, 0)
File "/usr/share/pyshared/simplejson/encoder.py", line 213, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <function <lambda> at 0x535c230> is not JSON serializable
the function returns a list of Ids, but here is the function itself:
def _get_technic_warehause(self, cr, uid,ids, context=None):
data = self.browse(cr, uid, ids, context=context)[0]
pdb.set_trace()
if data.technic_id.id:
location_obj = self.pool.get('stock.location')
lines_ids = location_obj.search(cr, uid, [('user_id', '=', data.technic_id.id)])
#res = {data['id'] : []}
res = []
for line_id in lines_ids:
prod_info = location_obj._product_get(cr, uid, line_id, context=context)
for prod_id in prod_info.keys():
if prod_info[prod_id] != 0.0:
#res[data['id']].append(prod_id)
res.append(prod_id)
return res
#return {}
is there anyway in openerp to make this work? I know that openerp doesn't allow function fields in domain filter sadly, but anyway to get around it?