I want to dynamic change the domain of many2one field every time the value of dul changes #dul is Boolean
in the first case so that domain="[('parent_id', '!=', False), ('parent_id', '=', imeReona)]"
, and in another case domain="[('parent_id', '!=', False)]"
I tried:
my_many2one_field = fields.Many2one(..., domain=lambda self: self.env['ir.config_parameter'].sudo().get_param('domen_mm2o'))
@api.onchange('dul') def _onchange_dul(self): if (self.dul == True): res = "[('parent_id','!=',False),('parent_id','=',imeReona)]" else: res = "[('parent_id','!=',False)]" self.env['ir.config_parameter'].sudo().set_param('domen_mm2o',res)
If I was not clear enough or did not formulate the question well, please let me know
@api.onchange('partner_id')
def apply_domain_customer(self):
vehicles = self.env['fleet.vehicle'].search([('driver_id', '=',
self.partner_id.id)]).ids
return {
'domain': {
'vehicle': [('id', 'in', vehicles)]
}}
I fixed the code. From my_many2one_field
I removed , domain=lambda self: self.env['ir.config_parameter'].sudo().get_param('domen_mm2o')
and updated
@api.onchange('dul')
def _onchange_dul(self):
if (self.dul == True):
res = "[('parent_id','!=',False),('parent_id','=',imeReona)]"
else:
res = "[('parent_id','!=',False)]"
self.env['ir.config_parameter'].sudo().set_param('domen_mm2o',res)
return{
'domain': {'my_many2one_field': self.env['ir.config_parameter'].sudo().get_param('domen_mm2o')}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.