python/ odoo/ odoo-10/ many-to-one

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)

added the following code

    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.

Related Question Odoo 8 domain filter on Many2one field Domain for Many2One field not working in odoo How to change many2one value field name in odoo 12? How to change the domain of the Many2one field by inheritance? Odoo : How to clear a many2many field when a many2one field change? Set domain on Many2one field value in Odoo Odoo, Many2One field domain not working when editing a record How to apply domain filter on Many2One field Using Odoo JS? How to apply domain to Many2One field in Odoo using a list of records Domain in Many2one Odoo 11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM