Skip to Content
Menu
This question has been flagged
2 Replies
2252 Views

Hello, hope someone could help me, thanks.

I have a form view, with 2 fields:

field 1:   phone_model = fields.Many2one('product.product',required=True)

filed 2:    parts =fields.Many2many('rma.parts')

rma. parts is a class i built , with  a fields 

parts_model=fields.Char()

My question is how to add domain to field 2, to show only the parts with same phone_model name with field 1.

If i use below domain, i got erro message  "object has no attribute '_name'

"[('parts_model','like',phone_model._name)]"
Avatar
Discard
Author Best Answer

@Avinash Nk

thanks for your help, I have read some related articles, seems Onchange is not a good choice:

1. this will only works when "phone_model" filed is changed,  for those records with phone_model field set already, this domain not works.


2. somebody said this onchange will be applied to very other records even i have changed only 1 records.

   I m not sure about this, is this true?


why we can not just use phone_model.name indomain directly?

Avatar
Discard
Best Answer

Hi,

You can return the domain of one field in the onchange of another field.

In your case, you can return the domain in the onchange function of phone_model field

Eg:

def your_onchange_function(self):
name = self.phone_model.name
return {
'domain': {'parts': [('parts_model', 'like', name)]},
}

Thank you.

Avatar
Discard