From 80a00b8f0e14caa17faf148d5ad4d6af03f094c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Wed, 27 Nov 2024 20:46:40 +0800 Subject: [PATCH 1/3] pengyuthon wechat --- yuthon_will_task/models/yuthon_will_task.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/yuthon_will_task/models/yuthon_will_task.py b/yuthon_will_task/models/yuthon_will_task.py index 9a5960d85..5d3ff0c9b 100644 --- a/yuthon_will_task/models/yuthon_will_task.py +++ b/yuthon_will_task/models/yuthon_will_task.py @@ -28,24 +28,24 @@ class YuthonWillTask(models.Model): def will_task_time(self): tasks = self.env['yuthon.will.task'].search([]) for task in tasks: - # start_time = task.start_time + timedelta(hours=8) + start_time = task.start_time + timedelta(hours=8) _logger.info("定时任务执行中") - _logger.info("判断前now:{}---start:{}".format(now, task.start_time)) + _logger.info("判断前now:{}---start:{}".format(now, start_time)) if now <= task.start_time: - _logger.info("判断后now:{}---start:{}".format(now, task.start_time)) + _logger.info("判断后now:{}---start:{}".format(now, start_time)) if task.task_time_ids: for task_time in task.task_time_ids: duration = self._compute_duration(task_time) day_now = (now + duration).day - day_start = task.start_time.day + day_start = start_time.day hour_now = (now + duration).hour - hour_start = task.start_time.hour + hour_start = start_time.hour min_now = (now + duration).minute - min_start = task.start_time.minute + min_start = start_time.minute if day_now == day_start and hour_now == hour_start and min_now == min_start: task.add_comment() else: - if now.day == task.start_time.day and now.hour == task.start_time.hour and now.minute == task.start_time.minute: + if now.day == start_time.day and now.hour == start_time.hour and now.minute == start_time.minute: task.add_comment() def _compute_duration(self, task_time): @@ -60,6 +60,7 @@ class YuthonWillTask(models.Model): def add_comment(self): self.ensure_one() + self.will_task_time() for employee_id in self.employee_ids: if not employee_id.wecom_userid: raise UserError("请同步{}的企业微信".format(employee_id.name)) From c699a8844bd61626787bae277ac4e9edeab0b502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Wed, 27 Nov 2024 21:05:05 +0800 Subject: [PATCH 2/3] pengyuthon wechat --- yuthon_will_task/models/yuthon_will_task.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yuthon_will_task/models/yuthon_will_task.py b/yuthon_will_task/models/yuthon_will_task.py index 5d3ff0c9b..75af21121 100644 --- a/yuthon_will_task/models/yuthon_will_task.py +++ b/yuthon_will_task/models/yuthon_will_task.py @@ -5,7 +5,6 @@ from odoo.exceptions import UserError import logging _logger = logging.getLogger(__name__) -now = datetime.now() + timedelta(hours=8) class YuthonWillTask(models.Model): @@ -23,11 +22,12 @@ class YuthonWillTask(models.Model): employee_ids = fields.Many2many('hr.employee', string='人员', default=lambda self: self.env.user.employee_id) task_time_ids = fields.Many2many('yuthon.task.time', string='提醒') start_time = fields.Datetime(string='开始时间', default=fields.Date.today()) - end_time = fields.Datetime(string='结束时间', default=lambda self: datetime.combine(now.date(), time(11, 0, 0))) + end_time = fields.Datetime(string='结束时间', default=lambda self: datetime.combine(datetime.now().date(), time(11, 0, 0))) def will_task_time(self): tasks = self.env['yuthon.will.task'].search([]) for task in tasks: + now = datetime.now() + timedelta(hours=8) start_time = task.start_time + timedelta(hours=8) _logger.info("定时任务执行中") _logger.info("判断前now:{}---start:{}".format(now, start_time)) From 6be215c349775726d224542cac7a201c8fd59e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Wed, 27 Nov 2024 21:19:21 +0800 Subject: [PATCH 3/3] pengyuthon wechat --- yuthon_will_task/models/yuthon_will_task.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yuthon_will_task/models/yuthon_will_task.py b/yuthon_will_task/models/yuthon_will_task.py index 75af21121..cb4bb0607 100644 --- a/yuthon_will_task/models/yuthon_will_task.py +++ b/yuthon_will_task/models/yuthon_will_task.py @@ -31,7 +31,7 @@ class YuthonWillTask(models.Model): start_time = task.start_time + timedelta(hours=8) _logger.info("定时任务执行中") _logger.info("判断前now:{}---start:{}".format(now, start_time)) - if now <= task.start_time: + if now <= start_time: _logger.info("判断后now:{}---start:{}".format(now, start_time)) if task.task_time_ids: for task_time in task.task_time_ids: @@ -60,7 +60,6 @@ class YuthonWillTask(models.Model): def add_comment(self): self.ensure_one() - self.will_task_time() for employee_id in self.employee_ids: if not employee_id.wecom_userid: raise UserError("请同步{}的企业微信".format(employee_id.name))