Skip to content

Commit

Permalink
[IMP] report_async: Change schedule_time to Datetime field
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardCForgeFlow committed Jul 1, 2024
1 parent 9a0f99f commit 235305e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions report_async/models/report_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion report_async/views/report_async.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<field name="allow_async"/>
<field name="email_notify"
attrs="{'invisible': [('allow_async', '=', False)]}"/>
<field name="schedule_time" placeholder="23:30"
<field name="schedule_time" widget="datetime" placeholder="YYYY-MM-DD HH:MM"
attrs="{'invisible': [('allow_async', '=', False)]}"/>
</group>
<group>
Expand Down

0 comments on commit 235305e

Please sign in to comment.