Files
gzth/yuthon_will_task/models/yuthon_will_task.py
T
2024-11-19 19:09:29 +08:00

46 lines
2.3 KiB
Python

from odoo import api, fields, models, modules
import datetime
from datetime import datetime, timedelta
class YuthonWillTask(models.Model):
_name = 'yuthon.will.task'
_description = '待办'
_rec_name = 'task_content'
priority = fields.Selection([('general', '不紧急不重要'), ('important', '重要不紧急'),
('urgent', '紧急不重要'), ('very_urgent', '重要且紧急')], string='优先级')
task_type = fields.Many2one('task.type.setting', string='任务类型')
task_content = fields.Text(string='任务内容')
remarks = fields.Text(string='备注')
creation_time = fields.Date(string='创建时间')
employee_ids = fields.Many2many('hr.employee', string='人员', default=lambda self: self.env.user.employee_id)
remind = fields.Selection([('fifteen', '提醒-15分钟'), ('thirty', '提醒-30分钟'), ('one_hour', '提醒-1小时'),
('two_hour', '提醒-2小时'), ('one_day', '提醒-1天')], string='提醒')
start_time = fields.Datetime(string='开始时间')
end_time = fields.Datetime(string='结束时间')
remind_mapping = {
'fifteen': timedelta(minutes=15),
'thirty': timedelta(minutes=30),
'one_hour': timedelta(hours=1),
'two_hour': timedelta(hours=2),
'one_day': timedelta(days=1),
}
def will_task_time(self):
for task in self.env['yuthon.will.task'].search([]):
time_difference = task.end_time - datetime.now()
for remind, duration in self.remind_mapping.items():
if task.remind == remind and time_difference <= duration:
task.add_comment()
def add_comment(self):
self.ensure_one()
if not self.wecom_userid:
raise ("请同步{}的企业微信".format(self.name))
for employee_id in self.employee_ids:
url = "https://oa.thtzjt.com/mail/view?model={}&res_id={}".format(self.yuthon_will_task,employee_id.id)
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='attendance', user_id=self.wecom_userid,
title="待办事项", description="测试消息请忽略",
url=url, btntxt="详细信息")