Menu Close
    Hire us Request quote Reading list Switch to dark mode

    Domain of One2Many Child fields on the basis of parent fields

    Today I was working on a module In Odoo11 where I needed to change the domain of a field in the tree view of One2many field on change of the parent field. I searched many things then I found a solution which I am going to explain in this tutorial.  I will try to explain with an example how we are going to do so.

     First, let us create the python code.

    I am creating two models “parent.model” in which I am adding two fields. One field is M2O and the other is O2M. The other model is “child.model” in which I have added some fields. Let us see how we can change the domain of one of the fields in the child model(product_id) on the basis of parent module field(template_id). In this example, I haved added only those variants in the domain whose sale price is greater than 100. See the code below.


     Now let us create the XML part.


    That is it.!!!
    If you liked this post, It would be very grateful if you write your opinions, comments and suggestions to keep the post updated and interesting.
    Thank you!

    Current Product Version - 1.0.0

    Supported Framework Version - 9,10,11

    . . .

    Comments (4)

    Add Your Comment

  • coder
    above code getting error
    Traceback (most recent call last):
    File “/opt/odoo/openerp/modules/registry.py”, line 386, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
    File “/opt/odoo/openerp/modules/loading.py”, line 336, in load_modules
    force, status, report, loaded_modules, update_module)
    File “/opt/odoo/openerp/modules/loading.py”, line 239, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
    File “/opt/odoo/openerp/modules/loading.py”, line 132, in load_module_graph
    models = registry.load(cr, package)
    File “/opt/odoo/openerp/modules/registry.py”, line 169, in load
    model = cls._build_model(self, cr)
    File “/opt/odoo/openerp/models.py”, line 591, in _build_model
    original_module = pool[name]._original_module if name in parents else cls._module
    File “/opt/odoo/openerp/modules/registry.py”, line 84, in __getitem__
    return self.models[model_name]
    KeyError: ‘child.model’
    2020-02-06 11:22:43,645 29993 INFO littleflower_db werkzeug: 127.0.0.1 – – [06/Feb/2020 11:22:43] “GET /web? HTTP/1.1” 500 –
    2020-02-06 11:22:43,660 29993 ERROR littleflower_db werkzeug: Error on request:
    Traceback (most recent call last):
    File “/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py”, line 177, in run_wsgi
    execute(self.server.app)
    File “/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py”, line 165, in execute
    application_iter = app(environ, start_response)
    File “/opt/odoo/openerp/service/server.py”, line 249, in app
    return self.app(e, s)
    File “/opt/odoo/openerp/service/wsgi_server.py”, line 184, in application
    return application_unproxied(environ, start_response)
    File “/opt/odoo/openerp/service/wsgi_server.py”, line 170, in application_unproxied
    result = handler(environ, start_response)
    File “/opt/odoo/openerp/http.py”, line 1497, in __call__
    return self.dispatch(environ, start_response)
    File “/opt/odoo/openerp/http.py”, line 1653, in dispatch
    ir_http = request.registry[‘ir.http’]
    File “/opt/odoo/openerp/http.py”, line 367, in registry
    return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
    File “/opt/odoo/openerp/modules/registry.py”, line 355, in get
    update_module)
    File “/opt/odoo/openerp/modules/registry.py”, line 386, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
    File “/opt/odoo/openerp/modules/loading.py”, line 336, in load_modules
    force, status, report, loaded_modules, update_module)
    File “/opt/odoo/openerp/modules/loading.py”, line 239, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
    File “/opt/odoo/openerp/modules/loading.py”, line 132, in load_module_graph
    models = registry.load(cr, package)
    File “/opt/odoo/openerp/modules/registry.py”, line 169, in load
    model = cls._build_model(self, cr)
    File “/opt/odoo/openerp/models.py”, line 591, in _build_model
    original_module = pool[name]._original_module if name in parents else cls._module
    File “/opt/odoo/openerp/modules/registry.py”, line 84, in __getitem__
    return self.models[model_name]
    KeyError: ‘child.model’
    • Jahangir Naik
      Some changes have been done you can check it.
  • asmaa
    it is very helpfull post, I searched alot about it, thanks
    • Jahangir Naik
      Thank you very much asmaa.
  • Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just received your message and our expert will get back to you shortly.
    Send Again
    Close