diff --git a/report_async/models/report_async.py b/report_async/models/report_async.py
index b5925abc53..a119197f9d 100644
--- a/report_async/models/report_async.py
+++ b/report_async/models/report_async.py
@@ -70,8 +70,14 @@ class ReportAsync(models.Model):
compute='_compute_file',
help="List all files created by this report background process",
)
-
- schedule_time = fields.Char(string='Schedule time')
+ schedule_time = fields.Char(
+ string='Schedule Time',
+ help="Time when the job will be executed",
+ )
+ schedule_date = fields.Date(
+ string='Schedule Date',
+ help="Date when the job will be executed",
+ )
@api.multi
def _compute_job(self):
@@ -167,9 +173,17 @@ def _send_email(self, attachment):
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)
+ target_time = datetime.strptime(self.schedule_time, "%H:%M").time() \
+ if self.schedule_time else now.time()
+
+ if self.schedule_date:
+ target_datetime = datetime.combine(self.schedule_date, target_time)
+ if now > target_datetime:
+ raise UserError(_('The scheduled time must be in the future.'))
+ else:
+ target_datetime = datetime.combine(now.date(), target_time)
+ if now > target_datetime:
+ 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..f3589e13ba 100644
--- a/report_async/views/report_async.xml
+++ b/report_async/views/report_async.xml
@@ -75,6 +75,8 @@
attrs="{'invisible': [('allow_async', '=', False)]}"/>
+