This question has been flagged
4 Replies
3374 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


Avatar
Discard

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

Author

My mistake, attribute is domain (corrected)

Best Answer

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

Avatar
Discard
Best Answer

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)]"/>
Avatar
Discard