تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
3781 أدوات العرض

I am using odoo14 . i made a custom module .now i want to make a condition where the date of birth should be less than today date. 

thanks in advance

my code

class StudentDetails(models.Model):
_name = 'std.record'
_description = 'Student'

name = fields.Char(string='Name')
middle_name = fields.Char(string='Middle Name')
last_name = fields.Char(string='Last Name')
roll_no = fields.Integer(string='Roll Number')

_sql_constraints = [
('unique_roll_number','unique(roll_no)','This roll number is already used on another student.'), ]
std_dob = fields.Date(string='Date of Birth')

image = fields.Binary(string='Image')
introduction = fields.Text(string="Introduction")
std_class = fields.Many2one(comodel_name='std.class', string='Student Class')
subj = fields.Many2many(comodel_name='std.subject', string='Subject')
std_id = fields.Many2one('std.class', string='Studentid')


الصورة الرمزية
إهمال
أفضل إجابة

Hello,

Please try this code:-

@api.constrains('std_dob')
def validate_std_dob(self):
if self.std_dob and self.std_dob >= fields.Date.today():
raise UserError(_('DOB should be less then Today\'s Date.'))

Thanks


الصورة الرمزية
إهمال
الكاتب

Thanks a bunch shahbaz

أفضل إجابة

Hi,

You can use constrains decorator in odoo for this purpose: https://www.youtube.com/watch?v=50cecNF3OyQ

Thanks

الصورة الرمزية
إهمال
الكاتب

Thank you niyas

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
يوليو 24
7873
2
مايو 23
7397
0
مارس 22
101
0
يناير 24
1233
2
مايو 23
6120