From cf39729bc25efb93876c0a2f020ac447eb471204 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?=
<9664676+pengyuthon@user.noreply.gitee.com>
Date: Fri, 6 Feb 2026 11:58:30 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
yuthon_notice/models/yuthon_confirm_users.py | 64 +++++++++--
yuthon_notice/models/yuthon_notice.py | 101 ++++++++++++------
.../views/yuthon_confirm_users_views.xml | 6 ++
yuthon_notice/views/yuthon_notice_views.xml | 2 +-
yuthon_wechat/models/wecom_apps.py | 2 +
yuthon_will_task/models/yuthon_will_task.py | 2 +-
6 files changed, 136 insertions(+), 41 deletions(-)
diff --git a/yuthon_notice/models/yuthon_confirm_users.py b/yuthon_notice/models/yuthon_confirm_users.py
index a1e013c7d..2ae219994 100644
--- a/yuthon_notice/models/yuthon_confirm_users.py
+++ b/yuthon_notice/models/yuthon_confirm_users.py
@@ -11,7 +11,22 @@ class YuthonConfirmUsers(models.Model):
notice_id = fields.Many2one('yuthon.notice', string="公告名称")
notice_code = fields.Char(string="公告编号")
notice_name = fields.Char(string="公告名称")
- state = fields.Selection([('no', '未确认'), ('yes', '已确认')], string="状态")
+ state = fields.Selection([('to_sent', '待发送'), ('no', '待确认'), ('yes', '已确认')], string="状态")
+ create_time = fields.Datetime(string='创建时间', default=fields.Datetime.now)
+ release_date = fields.Date(string="发布日期")
+ msg_id = fields.Char(string="Msg_id")
+
+ def withdrawn(self):
+ if self.msg_id:
+ self.sudo().env["wecom.apps"].back_message(self.msg_id, category='approval')
+ self.unlink()
+
+ def all_withdrawn(self):
+ confirm_noice_ids = self.env["yuthon.confirm.users"].browse(self._context.get('active_ids', self._context.get('active_id')))
+ for record in confirm_noice_ids:
+ if record.state == 'state':
+ raise UserError(f'{record.notice_name}通知还未发送,无法撤回')
+ record.withdrawn()
def sync_confirm_users_notices(self):
menu_id = self.env['ir.ui.menu'].search([('name', '=', '通知公告')])
@@ -23,16 +38,47 @@ class YuthonConfirmUsers(models.Model):
description="您有待确认的通知公告请尽快确认", url=url, btntxt="详细信息")
def reminders_notice(self):
- for rem in self:
- if rem.state == 'yes':
- raise UserError('已确认不可催办')
confirm_noice_ids = self.env["yuthon.confirm.users"].browse(self._context.get('active_ids', self._context.get('active_id')))
for rec in confirm_noice_ids:
- menu_id = self.env['ir.ui.menu'].search([('name', '=', '通知公告')])
- url = f'https://oa.thtzjt.com/web#id={self.id}&cids=2&action={menu_id.action.id}&model=yuthon.notice&view_type=list&menu_id={menu_id.id}'
+ if rec.state in ['yes', 'to_sent']:
+ raise UserError('该通知已确认或未发送,不可催办')
+ # menu_id = self.env['ir.ui.menu'].search([('name', '=', '通知公告')])
+ url = f'http://oa.thtzjt.com/webh5#/notice?id={rec.notice_id.id}'
self.sudo().env["wecom.apps"].sync_send_message_textcard(category='notice', user_id=rec.employee_id.wecom_userid,
title="通知公告(催办)", description="您有待确认的通知公告请尽快确认",
url=url, btntxt="详细信息")
- partner_ids = rec.employee_id.user_id.partner_id.id
- rec.with_context(lang=rec.env.lang)._message_auto_subscribe_notify(partner_ids,
- 'yuthon_notice.message_yuthon_confirm_users_data')
+ self.sudo().env["wecom.apps"].sync_send_message_textcard(category='notice',
+ user_id='18562027762',
+ title="通知公告(催办)",
+ description="您有待确认的通知公告请尽快确认",
+ url=url, btntxt="详细信息")
+ # partner_ids = rec.employee_id.user_id.partner_id.id
+ # rec.with_context(lang=rec.env.lang)._message_auto_subscribe_notify(partner_ids,'yuthon_notice.message_yuthon_confirm_users_data')
+
+ def notice_publish(self):
+ confirm_noice_ids = self.env["yuthon.confirm.users"].browse(
+ self._context.get('active_ids', self._context.get('active_id')))
+ we_id_list = []
+ for rec in confirm_noice_ids:
+ if rec.state != 'to_sent':
+ raise UserError(f'该通知已发送,请选择催办')
+ rec.write({'state': 'no'})
+ if rec.employee_id.wecom_userid:
+ we_id_list.append(rec.employee_id.wecom_userid)
+ touser = "|".join(we_id_list) if we_id_list else ""
+ url = f'http://oa.thtzjt.com/webh5#/notice?id={rec.notice_id.id}'
+ self.sudo().env["wecom.apps"].sync_send_message_textcard(category='notice', touser=touser, title="通知公告",
+ description=self.name + '发布人:' + self.users_id.name,
+ url=url, btntxt="详细信息")
+ self.sudo().env["wecom.apps"].sync_send_message_textcard(category='notice', touser='18562027762', title="通知公告",
+ description=self.name + '发布人:' + self.users_id.name,
+ url=url, btntxt="详细信息")
+ return {
+ 'type': 'ir.actions.client',
+ 'tag': 'display_notification',
+ 'params': {
+ 'type': 'success',
+ 'message': '通知公告已经发布',
+ 'sticky': False,
+ }
+ }
\ No newline at end of file
diff --git a/yuthon_notice/models/yuthon_notice.py b/yuthon_notice/models/yuthon_notice.py
index 10d5647aa..b9687463a 100644
--- a/yuthon_notice/models/yuthon_notice.py
+++ b/yuthon_notice/models/yuthon_notice.py
@@ -134,6 +134,31 @@ class YuthonNotice(models.Model):
)
notice.with_context(skip_constrains=True).users_ids = [(6, 0, list(all_users))]
+ if notice.users_ids and notice.is_change_notice:
+ conf_old = self.env['yuthon.confirm.users'].search([('notice_id', '=', notice.id)])
+ old_employee_ids = conf_old.mapped('employee_id.id')
+ new_employee_ids = notice.users_ids.mapped('employee_ids.id')
+
+ add_employee_ids = list(set(new_employee_ids) - set(old_employee_ids))
+ del_employee_ids = list(set(old_employee_ids) - set(new_employee_ids))
+
+ # 3. 处理删除:
+ if del_employee_ids:
+ del_conf = conf_old.filtered(lambda c: c.employee_id.id in del_employee_ids)
+ del_conf.unlink()
+
+ if add_employee_ids:
+ add_users = self.users_ids.filtered(lambda u: u.employee_ids[0].id in add_employee_ids)
+ for user in add_users:
+ self.env['yuthon.confirm.users'].create({
+ 'notice_id': self.id,
+ 'employee_id': user.employee_ids[0].id,
+ 'notice_code': self.code,
+ 'notice_name': self.name,
+ 'release_date': self.create_date1,
+ 'state': 'to_sent',
+ })
+
def get_no_read_count(self):
return self.search_count([('is_notice_roger', '=', 'no'), ('notice_state', '=', 'yes')])
@@ -171,43 +196,59 @@ class YuthonNotice(models.Model):
def notice_publish(self):
if self.is_change_notice:
- conf_old = self.env['yuthon.confirm.users'].search([('notice_id', '=', self.id), ('employee_id', 'in', self.users_ids.ids)])
- for user_id in self.users_ids:
- if conf_old:
- for co in conf_old:
- co.write({'state': 'no'})
- else:
- self.env['yuthon.confirm.users'].create({
- 'notice_id': self.id,
- 'employee_id': user_id.employee_ids.id,
- 'notice_code': self.code,
- 'notice_name': self.name,
- 'state': 'no',
- })
+ self.notice_state = 'yes'
+ conf_old = self.env['yuthon.confirm.users'].search(
+ [('notice_id', '=', self.id), ('employee_id', 'in', self.users_ids.mapped('employee_ids.id'))]
+ )
+ if conf_old:
+ conf_old.write({'state': 'no'})
+
+ user_wecom_mapping = []
we_id_list = []
for user_id in self.users_ids:
employee = user_id.employee_ids
- if employee and employee.wecom_userid:
- we_id_list.append(employee.wecom_userid)
+ if not employee:
+ continue
+ emp_id = employee.id
+ wecom_id = employee.wecom_userid
+ user_wecom_mapping.append({'emp_id': emp_id, 'user_id': user_id})
+ if wecom_id:
+ we_id_list.append(wecom_id)
+
+ msg_id = False
touser = "|".join(we_id_list) if we_id_list else ""
- url = f'http://oa.thtzjt.com/webh5#/notice?id={self.id}'
- self.sudo().env["wecom.apps"].sync_send_message_textcard(category='notice', touser=touser, title="通知公告",
- description=self.name + '发布人:' + self.users_id.name,
- url=url, btntxt="详细信息")
- self.write({"notice_state": 'yes'})
- return {
- 'type': 'ir.actions.client',
- 'tag': 'display_notification',
- 'params': {
- 'type': 'success',
- 'message': '通知公告已经发布',
- 'sticky': False,
- }
- }
+ if touser:
+ url = f'http://oa.thtzjt.com/webh5#/notice?id={self.id}'
+ result_data = self.sudo().env["wecom.apps"].sync_send_message_textcard(
+ category='notice',
+ touser=touser,
+ title="通知公告",
+ description=self.name + '发布人:' + self.users_id.name,
+ url=url,
+ btntxt="详细信息"
+ )
+ if result_data and isinstance(result_data, list) and 'msgid' in result_data[-1]:
+ msg_id = result_data[-1]['msgid']
+
+ for mapping in user_wecom_mapping:
+ emp_id = mapping['emp_id']
+ is_exist = self.env['yuthon.confirm.users'].search(
+ [('notice_id', '=', self.id), ('employee_id', '=', emp_id)],
+ limit=1
+ )
+ if not is_exist:
+ self.env['yuthon.confirm.users'].create({
+ 'notice_id': self.id,
+ 'employee_id': emp_id,
+ 'notice_code': self.code,
+ 'notice_name': self.name,
+ 'release_date': self.create_date1,
+ 'state': 'no',
+ 'msg_id': msg_id,
+ })
else:
raise UserError('该公告不允许通知,请勾选通知')
-
def look_up_notice_users(self):
return {
"type": "ir.actions.act_window",
diff --git a/yuthon_notice/views/yuthon_confirm_users_views.xml b/yuthon_notice/views/yuthon_confirm_users_views.xml
index 07e16f0b1..fc6d87b56 100644
--- a/yuthon_notice/views/yuthon_confirm_users_views.xml
+++ b/yuthon_notice/views/yuthon_confirm_users_views.xml
@@ -8,11 +8,17 @@
string="公告确认信息" js_class="custom_notice_tree_button" editable="bottom">
+
+
+
+
diff --git a/yuthon_notice/views/yuthon_notice_views.xml b/yuthon_notice/views/yuthon_notice_views.xml
index dc01fc0f4..cb7a70713 100644
--- a/yuthon_notice/views/yuthon_notice_views.xml
+++ b/yuthon_notice/views/yuthon_notice_views.xml
@@ -191,7 +191,7 @@
通知公告
- [('is_company', '=', True)]
+ [('is_company', '=', True),('users_ids','in',uid),('notice_state','=','yes')]
yuthon.notice
tree,form
diff --git a/yuthon_wechat/models/wecom_apps.py b/yuthon_wechat/models/wecom_apps.py
index 9ae5caa0d..030533acc 100644
--- a/yuthon_wechat/models/wecom_apps.py
+++ b/yuthon_wechat/models/wecom_apps.py
@@ -102,6 +102,8 @@ class WeComApps(models.Model):
token = ''
if category == 'task':
token = self.env['wecom.apps'].search([('name', '=', '日程消息通知')])['access_token']
+ if category == 'notice':
+ token = self.env['wecom.apps'].search([('name', '=', '通知公告消息通知')])['access_token']
if category == 'approval':
token = self.env['wecom.apps'].search([('name', '=', '审批消息通知')])['access_token']
data = {'msgid': msg_id}
diff --git a/yuthon_will_task/models/yuthon_will_task.py b/yuthon_will_task/models/yuthon_will_task.py
index bbf5a74f5..15711dbcd 100644
--- a/yuthon_will_task/models/yuthon_will_task.py
+++ b/yuthon_will_task/models/yuthon_will_task.py
@@ -242,7 +242,7 @@ class YuthonWillTask(models.Model):
return res
def _sync_dates_task(self):
- reminder_employees = self.employee_ids | self.employee_ids2
+ reminder_employees = self.employee_ids | self.employee_ids2 | self.employee_id
if not reminder_employees:
return
old_tasks = self.env['yuthon.dates.task'].search([('yuthon_will_task_id', '=', self.id), ('task_state', '=', 'to_do')])