Merge pull request !7124 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2025-12-18 05:59:06 +00:00
committed by Gitee
3 changed files with 22 additions and 24 deletions
@@ -5,7 +5,7 @@
<field name="name">定时任务:日程任务提醒</field>
<field name="model_id" ref="model_yuthon_will_task"/>
<field name="state">code</field>
<field name="code">model.will_task_time()</field>
<field name="code">model.add_comment()</field>
<field eval="False" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
+1 -1
View File
@@ -14,7 +14,7 @@ class YuthonDatesTask(models.Model):
_description = "日程任务"
reminder_time = fields.Datetime(string='提醒时间')
yuthon_will_task_id = fields.Many2one('yuthon.will.task', string='关联日程管理')
yuthon_will_task_id = fields.Many2one('yuthon.will.task', string='日程')
employee_ids = fields.Many2many('hr.employee', string='提醒人员')
task_state = fields.Selection([('to_do', '待提醒'), ('done', '已提醒')], string='状态')
+20 -22
View File
@@ -174,25 +174,26 @@ class YuthonWillTask(models.Model):
return timedelta.max
def add_comment(self):
employee_list = []
now = datetime.now() - timedelta(hours=8)
now_truncated = now.replace(second=0, microsecond=0)
for task in self.env['yuthon.dates.task'].search([('task_state', '=', 'to_do')]):
will_id = task.yuthon_will_task_id
reminder_truncated = task.reminder_time.replace(second=0, microsecond=0)
if reminder_truncated == now_truncated:
task.task_state = 'done'
for employee_id in task.employee_ids:
employee_list.append(employee_id)
for employee_id in employee_list:
url = f'https://oa.thtzjt.com/webh5#/journey?id={will_id.id}'
data_name = "事项名称: " + will_id.name + '\n'
data_user_ids = '参与人: ' + ', '.join(will_id.employee_ids.mapped('name')) + '\n'
data_employee_id = ('司机:' + ', '.join(will_id.employee_ids2.mapped('name')) + '\n') if will_id.employee_ids2 else ''
data_nota = ('备注:' + will_id.remarks) if will_id.remarks else ('') + '\n'
data = data_name + data_user_ids + data_nota + data_employee_id
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='task', user_id=employee_id.wecom_userid, title="日程事项提醒", description=data,
url=url, btntxt="详细信息")
"日程定时任务提醒"
now = fields.datetime.now() + timedelta(hours=8)
_logger.info(f'定时任务已执行:当前提醒时间:{now}')
dates_task_ids = self.env['yuthon.dates.task'].search([('task_state', '=', 'to_do'), ('reminder_time', '<', fields.datetime.now() + timedelta(days=1))])
for task in dates_task_ids:
_logger.info(f'任务实际小时:{task.reminder_time.hour}:{task.reminder_time.minute}\n 当前提醒小时:{now.hour}:{now.minute}')
if task.reminder_time.minute == now.minute and task.reminder_time.hour == now.hour:
will_id = task.yuthon_will_task_id
for employee_id in will_id.employee_ids:
url = f'https://oa.thtzjt.com/webh5#/journey?id={will_id.id}'
data_name = "事项名称: " + task.yuthon_will_task_id.name + '\n'
data_user_ids = '参与人: ' + ', '.join(will_id.employee_ids.mapped('name')) + '\n'
data_employee_id = ('司机:' + ', '.join(will_id.employee_ids2.mapped('name')) + '\n') if will_id.employee_ids2 else ''
data_nota = ('备注:' + will_id.remarks) if will_id.remarks else ('') + '\n'
data = data_name + data_user_ids + data_nota + data_employee_id
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='task', user_id=employee_id.wecom_userid, title="日程事项提醒", description=data,
url=url, btntxt="详细信息")
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='task', user_id="18562027762", title="日程事项提醒", description=data,
url=url, btntxt="详细信息")
return True
def button_add_comment(self):
self.add_comment()
@@ -216,9 +217,6 @@ class YuthonWillTask(models.Model):
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='task', user_id=employee_id.wecom_userid,
title="日程事项提醒", description="事项名称: " + self.name + '\t' + '该事项已取消',
url=url, btntxt="详细信息")
# for record in self:
# partner_ids = record.employee_ids.user_id.partner_id.ids
# record.with_context(lang=record.env.lang)._message_auto_subscribe_notify(partner_ids, 'yuthon_will_task.mail_action_yuthon_will_task_add_comment')
return {
'type': 'ir.actions.client',
'tag': 'display_notification',