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.


Set dynamic domain on fields based on other fields value

Mathieu Laflamme
on 2/26/16, 4:41 PM 470 views

I need to set a specific domain on a fields B (sale_order.carrier_id in my case) base on another field A (sale_order.partner_id in my case).

How can I do that so that it works in all use cases, especially when EDITING an existing record. I made bunch of code on the @api.onchange('partner_id') to realize the code isn't triggered when the record is edited! I try to find a way to set this domain when the record gets edited as well with no success. Not fun :(

I really hope there is a solution to that problem!!

post your code to have a closer look

Axel Mendoza
on 2/26/16, 9:11 PM

Just pasted my code...

Mathieu Laflamme
on 2/29/16, 5:32 PM
Wilbert Tan
On 3/1/16, 4:54 AM

Hi there,

To put domain on field "carried_id", you need this code:

    domain['carrier_id'] = #yourdomain
    return {'domain': domain}

Also, please print this domain so we could see : 

        domain = option_default_obj.get_domain_set_values_for_onchange_partner_id(self)       


Mathieu Laflamme
On 2/29/16, 5:31 PM

Here is my code:

@api.onchange('partner_id') def onchange_partner_id_dtype(self):

super(SaleOrder, self).onchange_partner_id_dtype()

option_default_obj = self.env['delivery.option.default']

domain = option_default_obj.get_domain_set_values_for_onchange_partner_id(self)

return {'domain': domain}

After having coded this function, I realized that this is not executed when editing existing records. Therefore the domain restriction returned by option_default_obj.get_domain_set_values_for_onchange_partner_id(self) isn't applied. How can I apply it on record edit? Or at form load??

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: 2/26/16, 4:41 PM
Seen: 470 times
Last updated: 3/1/16, 4:54 AM