constraints - Odoo restrict delete of record that is still referenced (m2m) -
i have field:
range_application_ids = fields.many2many('insurance.commission.rule.range.application', 'application_rule_range_rel', 'rule_range_id', 'application_id', 'applications', ondelete='restrict', required=true)
i need restricts delete of models (insurance.commission.rule.range.application
) records if referenced through many2many relation. if go models records list , delete of it, odoo won't throw warning , lets me it. when got models record has relation insurance.commission.rule.range.application
through many2many field, see removed (and field required). setting ondelete='restrict'
did not anything.
is there way restrict such deletes odoo standard functionality or need implement such checking myself?
now implemented such constraint myself, if know how using standard methods, please post answer. here code (it goes in insurance.commission.rule.range.application
model (or class in other words):
@api.multi def unlink(self): range_obj = self.env['insurance.commission.rule.range'] rule_ranges = range_obj.search([('range_application_ids', 'in', self.ids)]) if rule_ranges: raise warning(_("you trying delete record still referenced!")) return super(insurance_commission_rule_range_application, self).unlink()