From ad5d715e4eaea7e27223ea777d493649f0c64650 Mon Sep 17 00:00:00 2001 From: "pawan.sharma" Date: Wed, 6 Oct 2021 23:32:43 +0530 Subject: [PATCH] solve hours validation for import record in timesheet --- cor_custom/models/analytic.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cor_custom/models/analytic.py b/cor_custom/models/analytic.py index 53479dc..c26816c 100755 --- a/cor_custom/models/analytic.py +++ b/cor_custom/models/analytic.py @@ -169,11 +169,6 @@ class AccountAnalyticLine(models.Model): raise ValidationError(_("End time cannot be earlier than Start time")) self.unit_amount = res""" - @api.onchange('start_datetime', 'end_datetime') - def _onchange_start_end_date_time(self): - if self.start_datetime and self.end_datetime: - total_hours = (self.end_datetime - self.start_datetime).total_seconds() / 3600 - self.unit_amount = total_hours # @api.onchange('start_time', 'end_time') # def _onchange_start_end_time(self): @@ -234,6 +229,12 @@ class AccountAnalyticLine(models.Model): # res['datas'][index][durationindex] = duration_time return res + @api.onchange('start_datetime', 'end_datetime') + def _onchange_start_end_date_time(self): + if self.start_datetime and self.end_datetime: + total_hours = (self.end_datetime - self.start_datetime).total_seconds() / 3600 + self.unit_amount = total_hours + @api.model def create(self, vals): # if vals.get('unit_amount') == 0.0: @@ -245,6 +246,10 @@ class AccountAnalyticLine(models.Model): value.project_id._onchange_calculate_timesheet_hours() value.project_id._compute_calc() value._onchange_start_end_date_time() + if value.unit_amount == 0.0: + raise ValidationError(_("Your can not fill 0.0 hour entry")) + if value.unit_amount >= 24.0: + raise ValidationError(_("Your can not fill more than 24.0 hour entry")) return value def write(self, vals):