Odoo Help


How to set domains (filter) for second location based on first location

on 3/4/16, 1:38 AM 599 views

I have a model with two attribute of Many2one stock.location.

First is parent, second is child. I was trying to set second location based on first. It always return 

class store_location(models.Model):
_name = 'store'
national_store = fields.Many2one('stock.location', "National", domain=[('type', '=', 'national')])
regional_store = fields.Many2one('stock.location', "Regional", domain=[('location_id', '=', national_store)]
It result error
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 581, in dispatch
    return self._json_response(result)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 519, in _json_response
    body = simplejson.dumps(response)
  File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 366, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 269, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 348, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 246, in default
    raise TypeError(repr(o) + " is not JSON serializable")
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 442, in __repr__
    return "%s.%s" % (self.model_name, self.name)
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 329, in __getattr__
    raise AttributeError(name)
AttributeError: model_name

I'm not sure but I use 'domain' without s

Thanh Loyal
on 3/4/16, 2:30 AM

My mistake, attribute is domain (corrected)

on 3/4/16, 4:18 AM
On 3/4/16, 9:51 AM

try modifying  the model name to  -->   _name= 'store.store_location'.

Axel Mendoza
On 3/4/16, 9:32 AM

You need to specify that domain in a view, not in the field definition, like:

<field name="national_store"/>
<field name="regional_store" domain="[('location_id', '=', national_store)]"/>

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

1 follower(s)


Asked: 3/4/16, 1:38 AM
Seen: 599 times
Last updated: 3/4/16, 9:51 AM