diff --git a/yuthon_notice/models/yuthon_notice.py b/yuthon_notice/models/yuthon_notice.py index 37291ec45..77936e581 100644 --- a/yuthon_notice/models/yuthon_notice.py +++ b/yuthon_notice/models/yuthon_notice.py @@ -171,15 +171,35 @@ class YuthonNotice(models.Model): }) def get_no_read_count(self): - return self.search_count([('is_notice_roger', '=', 'no'), ('notice_state', '=', 'yes')]) + # 只统计当前用户发布范围内的未读公告,与列表 domain 保持一致 + return self.search_count([ + ('users_ids', 'in', self.env.uid), + ('is_notice_roger', '=', 'no'), + ('notice_state', '=', 'yes'), + ]) def read(self, fields=None, load='_classic_read'): + # 标记是否真的有未读变已读,避免没变化也触发菜单刷新 + changed = False for con in self: - con_id = self.env['yuthon.confirm.users'].search([('notice_id', '=', con.id), ('employee_id', '=', con.env.user.employee_id.id)]) - if con_id.employee_id == con.env.user.employee_id: - con.is_notice_roger = 'yes' - con_id.write({'state': 'yes'}) - return super(YuthonNotice, self).read(fields=fields, load=load) + # 只有全局状态仍是未读时才处理 + if con.is_notice_roger == 'no': + # 查找当前用户对应的公告确认记录 + con_id = self.env['yuthon.confirm.users'].search([ + ('notice_id', '=', con.id), + ('employee_id', '=', con.env.user.employee_id.id) + ]) + # 确认是当前员工本人,再标记为已读 + if con_id.employee_id == con.env.user.employee_id: + con.is_notice_roger = 'yes' + con_id.write({'state': 'yes'}) + changed = True + res = super(YuthonNotice, self).read(fields=fields, load=load) + # 如果有记录从 未读 变为 已读,清除菜单缓存并通知前端刷新角标 + if changed: + self.env['ir.ui.menu'].load_menus.clear_cache() + self.env['sun.badge.menu.mixin'].sudo().trigger_menu_reload() + return res @api.depends('read_number') def _compute_read_number(self):