84 lines
4.4 KiB
Python
84 lines
4.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models, tools
|
|
from odoo.exceptions import ValidationError, UserError
|
|
|
|
|
|
class YuthonOfficialIncomingParty(models.Model):
|
|
_name = 'yuthon.official.incoming.party'
|
|
_description = '党总支收文'
|
|
_inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
|
|
_rec_name = 'name'
|
|
|
|
name = fields.Char(string="名称")
|
|
code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('official_code'))
|
|
official_type_id = fields.Many2one('official.type', string="公文种类")
|
|
# official_type = fields.Selection([('go', '发文'), ('come', '收文')], string="公文类型")
|
|
reference_cold = fields.Integer(string="公文字号")
|
|
major_event_category = fields.Integer(string="重大事项所属类别")
|
|
official_partner_id = fields.Many2one('official.partner', string="来文单位")
|
|
remarks = fields.Char(string="备注事项")
|
|
main_text = fields.Text(string='正文')
|
|
come_file_id = fields.Char(string="来文编号")
|
|
incoming_file_id = fields.Char(string="收文编号")
|
|
main_flats = fields.Char(string="主送")
|
|
copy_flats = fields.Char(string="抄送")
|
|
servings_number = fields.Integer(string="份数")
|
|
urgency_level = fields.Selection([('normal', '一般'), ('urgent', '紧急'), ('extra_urgent', '特急')], string="紧急程度")
|
|
secret_level = fields.Selection([('normal', '一般'), ('urgent', '秘密'), ('secret', '机密'), ('so_secret', '绝密')],
|
|
string="密级")
|
|
date = fields.Datetime(string="日期", default=fields.Datetime.now)
|
|
statu = fields.Selection([('drft', '草稿'), ('going', '执行中'), ('cancel', '已取消'), ('done', '已完成')],
|
|
string="状态", default='drft')
|
|
deadline = fields.Datetime(string="办理期限")
|
|
red_suit = fields.Char(string="套红")
|
|
official_documents_ids = fields.Many2many('ir.attachment', string="附件")
|
|
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user)
|
|
department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门")
|
|
company_id = fields.Many2one(related="users_id.employee_id.company_id", string="公司", store=True)
|
|
is_issues = fields.Boolean(string="是否上会")
|
|
issues_result = fields.Html(string="会议结果")
|
|
related_issues_id = fields.Many2one('issue.library', string="关联议题")
|
|
is_company = fields.Boolean(string="本公司", default=True, compute='_compute_is_company',search='_search_part_of_company')
|
|
|
|
@api.depends_context('uid', 'company')
|
|
@api.depends('company_id')
|
|
def _compute_is_company(self):
|
|
active_company_ids = self.env.companies
|
|
for employee in self:
|
|
employee.is_company = employee.company_id in active_company_ids
|
|
|
|
def _search_part_of_company(self, operator, value):
|
|
company_ids = self.env.companies.ids
|
|
if not value:
|
|
operator = '!=' if operator == '=' else '='
|
|
if operator == '=':
|
|
return [('company_id', 'in', company_ids)]
|
|
else:
|
|
return [('company_id', 'not in', company_ids)]
|
|
|
|
def _get_default_name_title(self):
|
|
company = self.env.user.company_id
|
|
if company.id == 3 or any(name in company.name for name in ['天河粮储']):
|
|
return '党支部收文'
|
|
return self._description if self._description else self._name
|
|
|
|
name_title = fields.Char(default=_get_default_name_title)
|
|
|
|
active = fields.Boolean('Active', default=True, tracking=True)
|
|
work_end = fields.Boolean(string="结束")
|
|
self_users_ids = fields.Many2many('res.users', string="当前经办人", default=lambda self: [(6, 0, [self.env.user.id])])
|
|
|
|
@api.onchange('is_issues')
|
|
def _onchange_is_issues(self):
|
|
if self.is_issues:
|
|
issue_id = self.env['issue.library'].create({'name': self.name, 'is_invisible_workflow': True})
|
|
self.related_issues_id = issue_id.id
|
|
self.env['issue.library.approval.line'].create({
|
|
'issue_library_id': issue_id.id,
|
|
'workflow_name': self.name,
|
|
'approval_type': self.workflow_id.name,
|
|
'res_model': self._name,
|
|
'res_id': self.id,
|
|
'code': self.code,
|
|
'approval_date': fields.Datetime.now(),
|
|
}) |