Skip to Content
Menu
This question has been flagged
1 Reply
916 Views

hello,

I  am working on validation for leaves, my condition is if the start date of the leave less than the end of the trial period should raise a validation error, so I add a boolean field after the trial period 

here is code:


@api.constrains('request_date_from')
def _check_trial_period(self):
print("jjjjjjjjjjjjj")
for record in self:
v = record.request_date_from > self.env['hr.contract'].search(
[('trial_date_end', ', record.request_date_from)])
if record.holiday_status_id.after_trial_period and v:
print("yyyyyyyyy")


Avatar
Discard
Best Answer

Hi  jenan soliman,

Try,

@api.constrains('date_from','employee_id')
def _check_date_start(self)
:
for rec in self:
if rec.request_date_from and rec.employee_id:
if not rec.employee_id.contract_id or not rec.employee_id.contract_id.trial_date_end:
raise ValidationError(_("Contract or Trial Period not set"))
if
rec.request_date_from < rec.employee_id.contract_id.trial_date_end:
raise ValidationError(_("You can't take leave during Trial Period "))


Hope it helps,
Kiran K

Avatar
Discard
Author

Thank you, it worked

Related Posts Replies Views Activity
3
Oct 23
5973
1
Sep 23
1963
1
May 23
1001
2
Apr 23
1374
1
Mar 23
996