添加功能
This commit is contained in:
@@ -21,7 +21,7 @@ MENU_BADGE_MODEL_FUNC_ENUM = {
|
||||
'yuthon_property.yuthon_property_rent_list': {'model': 'property.rent.list', 'func': 'get_no_read_count'},
|
||||
'yuthon_property.yuthon_property_management_list': {'model': 'property.management.list', 'func': 'get_no_read_count'},
|
||||
'yuthon_property.yuthon_property_deposit_list': {'model': 'property.deposit.list', 'func': 'get_no_read_count'},
|
||||
'soong_workflow.menu_workflow_approval_request_my_start': {'model': 'soong.workflow.record', 'func': 'get_no_read_count'},
|
||||
'soong_workflow.menu_soong_workflow_todo_record': {'model': 'soong.workflow.record', 'func': 'get_no_read_count'},
|
||||
'soong_workflow.menu_workflow_approval_request_copy': {'model': 'soong.workflow.record.copy', 'func': 'get_no_read_count'},
|
||||
'yuthon_will_task.menu_yuthon_will_task_root': {'model': 'yuthon.will.task', 'func': 'read_number'},
|
||||
'issue_library.yuthon_library_my_menu': {'model': 'issue.library', 'func': 'read_number'},
|
||||
|
||||
@@ -16,7 +16,7 @@ class SoongWorkflowRecord(models.Model):
|
||||
|
||||
def get_no_read_count(self):
|
||||
domain = [
|
||||
('approve_state', '=', 'pending'),
|
||||
('soong_state', '=', 'to_do'),
|
||||
('employee_ids.user_id', '=', self.env.user.id),
|
||||
('users_ids', 'in', self.env.user.id),
|
||||
('reclaim_state', '=', False)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
'security/yuthon_will_task_security.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'views/yuthon_will_task_views.xml',
|
||||
'views/yuthon_dates_task_views.xml',
|
||||
'views/yuthon_task_time_views.xml',
|
||||
'views/yuthon_task_menu.xml',
|
||||
],
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from . import yuthon_will_task
|
||||
from . import yuthon_task_time
|
||||
from . import inherit_room_booking
|
||||
from . import yuthon_dates_task
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
import qrcode
|
||||
import base64
|
||||
from io import BytesIO
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
class YuthonDatesTask(models.Model):
|
||||
_name = "yuthon.dates.task"
|
||||
_description = "日程任务"
|
||||
|
||||
reminder_time = fields.Datetime(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='状态')
|
||||
|
||||
@@ -204,9 +204,14 @@ class YuthonWillTask(models.Model):
|
||||
|
||||
def add_comment(self):
|
||||
self.ensure_one()
|
||||
admin = self.env['hr.employee'].search([('name', '=', 'Administrator')])
|
||||
employee_list = [i.id for i in self.employee_ids] + [i.id for i in self.employee_ids2] + admin.id
|
||||
for employee_id in self.env['hr.employee'].search([('id', 'in', employee_list)]):
|
||||
employee_list = []
|
||||
for task in self.env['yuthon.dates.task'].search([('task_state', '=', 'to_do')]):
|
||||
now = datetime.now()
|
||||
if task.reminder_time == now:
|
||||
task.task_state = 'done'
|
||||
for task_time in task.employee_ids:
|
||||
employee_list.append(task_time.employee_id)
|
||||
for employee_id in employee_list:
|
||||
if not employee_id.wecom_userid:
|
||||
raise UserError("请同步{}的企业微信".format(employee_id.name))
|
||||
url = f'https://oa.thtzjt.com/webh5#/journey?id={self.id}'
|
||||
@@ -252,4 +257,68 @@ class YuthonWillTask(models.Model):
|
||||
'message': '已发送取消提醒消息',
|
||||
'sticky': False,
|
||||
}
|
||||
}
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
"""创建日程时,同步创建提醒任务"""
|
||||
will_task = super(YuthonWillTask, self).create(vals)
|
||||
will_task._sync_dates_task()
|
||||
return will_task
|
||||
|
||||
def write(self, vals):
|
||||
"""修改日程时,先删除旧提醒任务,再创建新的"""
|
||||
res = super(YuthonWillTask, self).write(vals)
|
||||
key_fields = ['start_date', 'request_hour_from', 'task_time_ids', 'employee_ids', 'employee_ids2']
|
||||
if any(field in vals for field in key_fields):
|
||||
self._sync_dates_task()
|
||||
return res
|
||||
|
||||
def _sync_dates_task(self):
|
||||
reminder_employees = self.employee_ids | self.employee_ids2
|
||||
if not reminder_employees:
|
||||
return
|
||||
old_tasks = self.env['yuthon.dates.task'].search([('yuthon_will_task_id', '=', self.id)])
|
||||
if old_tasks:
|
||||
old_tasks.unlink()
|
||||
start_hour = float(self.request_hour_from)
|
||||
hours = int(start_hour)
|
||||
minutes = int((start_hour - hours) * 60)
|
||||
task_start_datetime = datetime.combine(self.start_date,time(hour=hours, minute=minutes))
|
||||
for task_time in self.task_time_ids:
|
||||
reminder_time_str = task_time.name
|
||||
reminder_hours = 0.0
|
||||
import re
|
||||
match = re.match(r'(\d+)(分钟|小时|天)', reminder_time_str.strip())
|
||||
num = int(match.group(1))
|
||||
unit = match.group(2)
|
||||
if unit == '小时':
|
||||
reminder_hours = num
|
||||
elif unit == '分钟':
|
||||
reminder_hours = num / 60.0
|
||||
elif unit == '天':
|
||||
reminder_hours = num * 24.0
|
||||
reminder_datetime = task_start_datetime - timedelta(hours=reminder_hours)
|
||||
existing_dates_task = self.env['yuthon.dates.task'].search([
|
||||
('yuthon_will_task_id', '=', self.id),
|
||||
('reminder_time', '=', reminder_datetime)
|
||||
])
|
||||
task_vals = {
|
||||
'reminder_time': reminder_datetime - timedelta(hours=8),
|
||||
'employee_ids': [(6, 0, reminder_employees.ids)],
|
||||
'task_state': 'to_do',
|
||||
}
|
||||
if existing_dates_task:
|
||||
existing_dates_task.write(task_vals)
|
||||
else:
|
||||
task_vals['yuthon_will_task_id'] = self.id
|
||||
self.env['yuthon.dates.task'].create(task_vals)
|
||||
|
||||
def schedule_reminders(self):
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': '提醒任务详情',
|
||||
'view_mode': 'tree',
|
||||
'res_model': 'yuthon.dates.task',
|
||||
'domain': [('yuthon_will_task_id', '=', self.id)],
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_yuthon_task_time,yuthon_task_time,model_yuthon_task_time,yuthon_will_task.group_yuthon_will_task_user,1,1,1,1
|
||||
access_yuthon_will_task,yuthon_will_task,model_yuthon_will_task,yuthon_will_task.group_yuthon_will_task_user,1,1,1,1
|
||||
|
||||
access_yuthon_dates_task,yuthon_dates_task,model_yuthon_dates_task,yuthon_will_task.group_yuthon_will_task_user,1,1,1,1
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_yuthon_dates_task_tree" model="ir.ui.view">
|
||||
<field name="name">yuthon.dates.task.tree</field>
|
||||
<field name="model">yuthon.dates.task</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="日程任务" editable="bottom">
|
||||
<field name="reminder_time"/>
|
||||
<field name="employee_ids" widget="many2many_tags" options="{'no_create': True}"/>
|
||||
<field name="yuthon_will_task_id" column_invisible="1"/>
|
||||
<field name="task_state"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_yuthon_dates_task_action" model="ir.actions.act_window">
|
||||
<field name="name">日程任务</field>
|
||||
<field name="res_model">yuthon.dates.task</field>
|
||||
<field name="view_mode">tree</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -48,4 +48,9 @@
|
||||
parent="task_type_menu"
|
||||
action="yuthon_task_time_setting_action"
|
||||
sequence="5"/>
|
||||
<menuitem id="yuthon_dates_task_menu"
|
||||
name="日程任务"
|
||||
parent="task_type_menu"
|
||||
action="view_yuthon_dates_task_action"
|
||||
sequence="5"/>
|
||||
</odoo>
|
||||
@@ -26,6 +26,7 @@
|
||||
<field name='creation_time' optional="hide"/>
|
||||
<button name="button_add_comment" string="提醒" type="object" class="oe_highlight" invisible="task_state == 'cancel'"/>
|
||||
<button name="button_add_comment_cancel" string="取消" type="object" class="oe_highlight" invisible="task_state == 'cancel'"/>
|
||||
<button name="schedule_reminders" string="提醒详情" type="object" class="oe_highlight" groups="base.group_system"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -254,7 +255,7 @@
|
||||
<field name='name'>领导日程</field>
|
||||
<field name='res_model'>yuthon.will.task</field>
|
||||
<field name='view_mode'>tree,calendar,form</field>
|
||||
<field name='domain'>[('user_role_ids.name', 'in', ['董事长', '分管领导', '总经理', '部门副经理', '部门经理', '副总经理', '司机'])]</field>
|
||||
<field name='domain'>[('user_role_ids.name', 'in', ['董事长', '分管领导', '总经理', '部门副经理', '副总经理'])]</field>
|
||||
<field name="context">{'search_default_next_seven_days': 1}</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user