90 lines
4.1 KiB
Python
90 lines
4.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models, tools
|
|
from odoo.exceptions import ValidationError, UserError
|
|
|
|
|
|
class YuthonNotice(models.Model):
|
|
_name = "yuthon.notice"
|
|
_description = '通知公告'
|
|
_inherit = ['mail.thread.main.attachment', 'mail.activity.mixin', 'soong.workflow.mixin']
|
|
_rec_name = 'name'
|
|
_order = "sequence desc"
|
|
|
|
name = fields.Char(string='通知公告标题')
|
|
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('notice_code'))
|
|
user_id = fields.Many2one('res.users', string="发布人", default=lambda self: self.env.user)
|
|
department_ids = fields.Many2many('hr.department', string='部门范围')
|
|
employee_ids = fields.Many2many('hr.employee', string='人员范围')
|
|
users_role_ids = fields.Many2many('soong.user.role', string='角色范围')
|
|
notice_type_id = fields.Many2one('yuthon.notice.type', string="公告类型")
|
|
create_date = fields.Date(string="发布日期")
|
|
start_date = fields.Date(string="生效日期")
|
|
end_date = fields.Date(string="终止日期")
|
|
sequence = fields.Integer(string="顺序", default=1)
|
|
statu = fields.Selection(
|
|
[('new', '草稿'), ('approval', '审批中'), ('no', '未发布'), ('done', '已发布'), ('stop', '已终止')],
|
|
default='new', string="公告状态")
|
|
notice_documents_ids = fields.Many2many('documents.document', string="通知公告文件")
|
|
is_notice_roger = fields.Selection([('yes', '已读'), ('no', '未读')], default='no', string="确认状态")
|
|
notice_text = fields.Html(string="正文")
|
|
|
|
@api.onchange('is_notice_roger')
|
|
def onchange_is_notice_roger(self):
|
|
roger_id = self.env['yuthon.confirm.users'].search(
|
|
[('notice_id', '=', self.id), ('user_id', '=', self.env.user.id)])
|
|
if not roger_id:
|
|
self.is_notice_roger = 'yes'
|
|
|
|
def on_sequence(self):
|
|
self.sequence = 1
|
|
|
|
def no_sequence(self):
|
|
self.sequence = 0
|
|
|
|
def notice_publish(self):
|
|
users_role_list = department_users_list = []
|
|
for depart in self.department_ids:
|
|
department_users_data = self.env['hr.employee'].search([('department_id', '=', depart.id)])
|
|
department_users_list = [de.id for de in department_users_data]
|
|
employee_users_list = [em.user_id.id for em in self.employee_ids]
|
|
for user_id in self.users_role_ids:
|
|
department_users_data = self.env['soong.user.role'].search([('user_role_id', '=', user_id.id)])
|
|
users_role_list = [ro.id for ro in department_users_data]
|
|
publish_user_list = department_users_list + employee_users_list + users_role_list
|
|
if publish_user_list:
|
|
for user in list(set(publish_user_list)):
|
|
self.env['yuthon.confirm.users'].create({
|
|
'notice_id': self.id,
|
|
'user_id': user,
|
|
'notice_code': self.code,
|
|
'notice_name': self.name,
|
|
'state': 'yes',
|
|
})
|
|
# todo 普通用户权限是否打开,可能需要配置权限
|
|
partner_ids = self.sudo().env['res.users'].search([('id', 'in', publish_user_list)]).mapped(
|
|
'partner_id').ids
|
|
self.sudo().with_context(lang=self.env.lang)._message_auto_subscribe_notify(partner_ids,
|
|
'yuthon_notice.message_yuthon_confirm_users_data')
|
|
self.write({"statu": 'done'})
|
|
|
|
def confirm_notice(self):
|
|
self.write({'is_notice_roger': 'yes'})
|
|
|
|
def look_up_notice_users(self):
|
|
return {
|
|
"type": "ir.actions.act_window",
|
|
"name": "通知公告确认信息",
|
|
"domain": [("notice_id", "=", self.id)],
|
|
"res_model": "yuthon.confirm.users",
|
|
"view_mode": "tree",
|
|
"context": {
|
|
"search_default_group_state": True,
|
|
},
|
|
}
|
|
|
|
def stop_notice(self):
|
|
self.write({
|
|
'statu': 'stop',
|
|
'end_date': fields.Datetime.now(),
|
|
})
|