Odoo Help

0

[Odoo 11] How to return multiple domains in a single function

By
Nicolás Mena
on 12/5/17, 12:13 PM 817 views

Hi, I'm trying to figure out how to return domains for various fields in a single function, with @onchange decorator. Is this possible or I have to do cascade functions like after the first onchange function I have to use another one for the other domain? can I use 2 times the @onchange decorators? I've tried that before but without positive results.


Regards




0
Nicolás Mena
On 12/18/17, 1:34 PM

@Niyas

That code seems good but when I tried in Odoo 11 didn't worked for my custom model, Also i have to return 2 or more domains. so the workaround i've used is a chain onchange-decorated functions. like 


@api.onchange(a_field)

def domainB(self)

  #build the domain string

   return domainB


@api.onchange(b_field)

def domainC(self)

  #build the domain string

  return domainC


Assuming I have to change the A and B fields to trigger the functions, I've used the form to guide the user through the proccess, making the B and C fields invisible if they don't choose a value for A field(required) first. 



0

Niyas Raphy

--Niyas Raphy--
11736
| 5 6 9
Calicut, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to contact :  niyasraphyk@gmail.com

Niyas Raphy
On 12/5/17, 9:59 PM

Hi,

I think in the onchange itself it is possible. See the function named _change_model_id in the gamification module.


@api.onchange('model_id')
def _change_model_id(self):
"""Force domain for the `field_id` and `field_date_id` fields"""
if not self.model_id:
return {'domain': {'field_id': expression.FALSE_DOMAIN, 'field_date_id': expression.FALSE_DOMAIN}}
model_fields_domain = [
('store', '=', True),
'|', ('model_id', '=', self.model_id.id),
('model_id', 'in', self.model_id.inherited_model_ids.ids)]
model_date_fields_domain = expression.AND([[('ttype', 'in', ('date', 'datetime'))], model_fields_domain])
return {'domain': {'field_id': model_fields_domain, 'field_date_id': model_date_fields_domain}}

Thanks

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.

Register

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)

Stats

Asked: 12/5/17, 12:13 PM
Seen: 817 times
Last updated: 12/18/17, 1:36 PM