Skip to Content
Menu
This question has been flagged
3 Replies
1585 Views

hi i have a form named "Teachers" for the school project that i am developing,,,i have a tab named class/subject in which there is a tree view for "standard" and "subject" which are coming from other models by many2one relation,,,what i want is that when one standard and subject are selected they should not  be repeated,,,that is the records in that tab should be unique..i have tried sql constraint but its not working,,,

kindle help

Avatar
Discard

Please provide more details like what is the structure of your module and also post the code what you tried.

Best Answer

Hi,

If the sql constrains are not working you can give the api.constrains for those two fields, so the function will get executed on clicking the save button and you can restrict the saving of the record, it is not met with your criteria.

You check this and see how to give constrains for the field: How To Add Constrains For A Field in Odoo12

Sample:

@api.constrains('patient_age')
def check_age(self):
for rec in self:
if rec.patient_age < 5:
raise ValidationError(_('The Age Must be Greater Than 5..!'))


Thanks

Avatar
Discard
Author Best Answer

@niyas raphy sir actually those two fields are many2one so i dont know if to give the name of those fields there or like this

standard_id.standard_id.name??

if u can understand me??

Avatar
Discard
Author

i men=an just standard_id or standard_id.standard_id.name bcz its coming from another model via many2one.

standard_id.standard_id.id