Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
1 Svar
2201 Visninger

I need to set @api.constraints for people under 18. they shall not pass. pls help me

Avatar
Kassér
Bedste svar

Hi,

Below is a sample code by which you can get age from date of birth:

today = date.today()
if rec.date_of_birth:
rec.age = today.year - rec.date_of_birth.year
else:
rec.age = 1

Video: https://youtu.be/NlbdnA6WMd8?t=632

then you can check the age is less than 18 or not and return the validation using constrains:

See: https://www.youtube.com/watch?v=8Lz4Fy7ozfY

Thanks

Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
0
feb. 22
4
1
mar. 15
4876
1
mar. 15
8378
3
jun. 25
1197
1
jan. 25
18028