Odoo Help


This community 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.


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

on 3/4/16, 1:38 AM 322 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

--Axel Mendoza--
| 6 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


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