Odoo Help


domain filter

aci aisha
on 1/16/15, 5:24 AM 2,106 views


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?




| 5 3 6
Jakarta, Indonesia
On 1/16/15, 6:02 AM

Domain does not accept function.  What you can do is to make this function as a function field, include the function field in the view, and use the value of that function field in the domain in the view, not in the field definition.

Thanks Ivan.Bt sorry, i did'nt got u...

aci aisha
on 1/16/15, 6:16 AM

Thanks Ivan.Bt sorry, i did'nt got u...

aci aisha
on 1/16/15, 6:17 AM

@Aci, which part that you did not get?

on 1/20/15, 5:54 AM



| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 1/20/15, 9:51 AM

WHat ivan ment is that you cannot put function or method inside domain.. like you did... 
but you can call a method that will return domain as a result.. like:

def _get_domain(self):
    #has to be defined before you call it from field!
    return [('id', 'in',lambda self,cr,uid,ids, context: self._get_technic_warehause(cr,uid,ids,context))])

'product_id' : fields.many2one('product.product', 'products', domain=_get_domain)

try experimenting in this direction... 
hope it helps...

Also.. it might be easier to define domain on view instead of field... 

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 1/16/15, 5:24 AM
Seen: 2106 times
Last updated: 3/16/15, 8:10 AM