Understand the situation I 've 2 model below. I have added a onchange function based on 'requirement_id' . I want to add a domain filter in panel_id field from requirement_id . is it possible to do? my onchange function in this way it's not working
class PanelVendorAssignment(models.Model):
_name = "panel.vendor.assignment"
requirement_id = fields.Many2one('hr.job', string='Requirement')
panel_vendor_assignments_ids = fields.One2many(
string='Vendor', comodel_name='panel.vendor.assignment.line',
inverse_name='panel_vendor_assignment_id', tracking=True)
@api.onchange('requirement_id')
def _onchange_panel_stage(self):
if self.requirement_id:
panel_stage_ids = self.env['panel.time.slot.availability'].sudo().search(
[('requirement_id', '=', self.requirement_id.id),('status', '=', 'open')])
for rec in panel_stage_ids:
domain = [('id', '=', rec.panel_user_id.id)]
return {'domain': {'panel_vendor_assignments_ids.panel_id': domain}}
class PanelVendorAssignmentLine(models.Model):
_name = 'panel.vendor.assignment.line'
panel_vendor_assignment_id = fields.Many2one(comodel_name='panel.vendor.assignment', ondelete='cascade')
panel_id = fields.Many2one(comodel_name='res.partner',required=True,)
No you can't do that.
Your code also have some errors overwriting the value of the domain so you will be returning the last domain not per record domain
What you can do it's to calculate and save the domain for every record in the o2m in another field to be used locally by the panel_id field
To save the domain you could use a binary field or use this module: