From 235305e43e011a7fca02be03affb3fa0056f7b3f Mon Sep 17 00:00:00 2001 From: RicardCForgeFlow Date: Mon, 1 Jul 2024 11:10:23 +0200 Subject: [PATCH] [IMP] report_async: Change schedule_time to Datetime field --- report_async/models/report_async.py | 12 ++---------- report_async/views/report_async.xml | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/report_async/models/report_async.py b/report_async/models/report_async.py index b5925abc53..17aa8fcbc2 100644 --- a/report_async/models/report_async.py +++ b/report_async/models/report_async.py @@ -71,7 +71,7 @@ class ReportAsync(models.Model): help="List all files created by this report background process", ) - schedule_time = fields.Char(string='Schedule time') + schedule_time = fields.Datetime(string='Schedule Time') @api.multi def _compute_job(self): @@ -114,7 +114,7 @@ def run_async(self): ctx = safe_eval(result.get('context', {})) ctx.update({'async_process': True}) if self.schedule_time: - ctx.update({'eta': self._get_next_schedule_time()}) + ctx.update({'eta': self.schedule_time}) result['context'] = ctx return result @@ -165,11 +165,3 @@ def _send_email(self, attachment): template.send_mail(attachment.id, notif_layout='mail.mail_notification_light', force_send=False) - - def _get_next_schedule_time(self): - target_time = datetime.strptime(self.schedule_time, "%H:%M").time() - now = fields.Datetime.now() - target_datetime = datetime.combine(now.date(), target_time) - if now.time() > target_time: - target_datetime += timedelta(days=1) - return target_datetime diff --git a/report_async/views/report_async.xml b/report_async/views/report_async.xml index cbf6deaff0..21808683a4 100644 --- a/report_async/views/report_async.xml +++ b/report_async/views/report_async.xml @@ -73,7 +73,7 @@ -