Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][IMP] report_async: add schedule_date field #904

Merged
merged 2 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions report_async/models/report_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions report_async/views/report_async.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
attrs="{'invisible': [('allow_async', '=', False)]}"/>
<field name="schedule_time" placeholder="23:30"
attrs="{'invisible': [('allow_async', '=', False)]}"/>
<field name="schedule_date" widget="date"
attrs="{'invisible': [('allow_async', '=', False)]}"/>
</group>
<group>
<field name="job_status"
Expand Down
Loading