Hello,
Im trying to set Domain filter for one2many field of 'model_b.py' when showing base on the condition of another field of 'model_c.py' .
model_a.py :
name = fields.Many2one('hr.employee')
keya = fields.Many2one('model.b')
num_a = fields.Monetary()
model_b.py :
name = fields.Many2one('hr.employee')
o_2_m = fields.One2many('model.a', 'keya')
get_value_c = fields.Many2one('model.c', string='Get value of C', required= True)
model_c.py :
_rec_name = "code_c"
code_c = fields.Char('Code', required= True)
num_c = fields.Monetary()
So, the condition is if field num_c is == num_a, then it will show all the related records which have num_a's values in o_2_m field by a popup when the user clicks on the "Add a line" link. If not, it will show nothing.
Im trying to create onchange function in model_b.py to execute like this:
@api.onchange('get_value_c')
def onchange_get_value_c(self):
for rec in self:
return {'domain': {'o_2_m': [('get_value_c','=', rec.get_value_c)]}}
But I don't know how to compare values of num_c and num_a for getting the results.
Please help!
Thank you!
Hi,
I'd tried with onchange in model_b.py like this:
But it still not works.
Hi,
May i know how data is entered in one2many..??
Your onchange works only if you have data in get_value_c and o_2_m
Hi Karthikeyan,
The data already have in model_a.py . So the one2many field of model_b.py connected with many2one field in model_a.py. Then, when click on the "Add a line" link of one2many field, it will show all the already records of model_a.py. without filtering.
This means that, first, the data must be fill in model_a.py.
After that, when the user wants to filter the records which have relate value of num_a for selecting. Then they must be fill value in num_c. Of course, the scenario related to field 'num_c' will be built properly.
If the user don't want to filtering, then they don't need to select in many2one 'get_value_c', then when click on "Add a line" link. It will show all the records without filtering.
Domain Based on Another field: https://www.youtube.com/watch?v=IpXXYCsK2ow