177 lines
6.8 KiB
Python
177 lines
6.8 KiB
Python
import io
|
|
import base64
|
|
from odoo import models, fields, api
|
|
|
|
|
|
class ContractReviewApproval(models.Model):
|
|
_name = 'contract.review.approval'
|
|
_description = '汇审意见表'
|
|
_inherit = ['soong.workflow.mixin', 'mail.thread.main.attachment', 'mail.activity.mixin']
|
|
|
|
code = fields.Char(string="编号",
|
|
default=lambda self: self.env['ir.sequence'].next_by_code('contract_review_approval_code'))
|
|
name = fields.Char(string='标题')
|
|
user_id = fields.Many2one('res.users', string='合同经办人', default=lambda self: self.env.user)
|
|
is_issues = fields.Boolean(string='是否上会')
|
|
information_categories_ids = fields.Many2many('yuthon.information.categories', string='业务类型')
|
|
approval_type = fields.Selection([('contract', '合同'), ('charter', '章程')], string='审批类型')
|
|
issues_result = fields.Html(string="会议结果")
|
|
related_issues_id = fields.Many2one('issue.library', string="关联议题")
|
|
department_id = fields.Many2one('hr.department', string='送审部门')
|
|
amount = fields.Float(string='合同金额')
|
|
remarks = fields.Text(string='情况说明')
|
|
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
|
|
default='normal')
|
|
active = fields.Boolean('Active', default=True, tracking=True)
|
|
work_end = fields.Boolean(string="结束")
|
|
contract_type = fields.Many2one('yuthon.contract.type', string="合同类型")
|
|
formation_method = fields.Many2one('yuthon.contract.type', string="形成方式")
|
|
|
|
documents_ids = fields.Many2many(
|
|
'ir.attachment',
|
|
string="附件",
|
|
relation='soong_contract_ir_attachment_documents_rel',
|
|
column1='soong_contract_id',
|
|
column2='attachment_document_id',
|
|
)
|
|
lawyer_opinion_ids = fields.Many2many(
|
|
'ir.attachment',
|
|
string="律师意见",
|
|
relation='soong_contract_ir_attachment_lawyer_opinion_rel',
|
|
column1='soong_contract_id',
|
|
column2='attachment_lawyer_opinion_id',
|
|
)
|
|
|
|
def _get_default_name_title(self):
|
|
return self._description if self._description else self._name
|
|
|
|
name_title = fields.Char(default=_get_default_name_title)
|
|
|
|
|
|
def action_print_contract_review(self):
|
|
report_ref = self.env.ref('yuthon_hr_employee_approval.action_contract_review_report')
|
|
return report_ref.report_action(self.id)
|
|
|
|
def action_export_excel(self):
|
|
"""导出汇审意见表Excel"""
|
|
self.ensure_one()
|
|
|
|
# 导入Excel相关模块
|
|
try:
|
|
import xlsxwriter
|
|
except ImportError:
|
|
raise UserError(_('请安装xlsxwriter库: pip install xlsxwriter'))
|
|
|
|
# 创建Excel工作簿
|
|
output = io.BytesIO()
|
|
workbook = xlsxwriter.Workbook(output, {'in_memory': True})
|
|
worksheet = workbook.add_worksheet('汇审意见表')
|
|
|
|
# 设置格式
|
|
title_format = workbook.add_format({
|
|
'bold': True,
|
|
'font_size': 16,
|
|
'align': 'center',
|
|
'valign': 'vcenter',
|
|
'border': 1
|
|
})
|
|
header_format = workbook.add_format({
|
|
'bold': True,
|
|
'bg_color': '#d4e6f1',
|
|
'border': 1,
|
|
'align': 'center'
|
|
})
|
|
cell_format = workbook.add_format({'border': 1})
|
|
|
|
# 写入标题
|
|
worksheet.merge_range('A1:D1', '汇审意见表', title_format)
|
|
worksheet.set_row(0, 30)
|
|
|
|
# 写入基本信息行
|
|
row = 2
|
|
worksheet.write(row, 0, '承办部门:', header_format)
|
|
worksheet.write(row, 1, self.department_id.name if self.department_id else '', cell_format)
|
|
worksheet.write(row, 2, '流水号:', header_format)
|
|
worksheet.write(row, 3, self.code or '', cell_format)
|
|
|
|
# 写入表格标题
|
|
row += 2
|
|
headers = ['合同名称', '审批类型', '业务类型', '合同类型', '合同金额', '情况说明']
|
|
for col, header in enumerate(headers):
|
|
worksheet.write(row, col, header, header_format)
|
|
|
|
# 写入数据
|
|
row += 1
|
|
worksheet.write(row, 0, self.name or '', cell_format)
|
|
|
|
# 审批类型
|
|
if self.approval_type == 'contract':
|
|
worksheet.write(row, 1, '合同', cell_format)
|
|
elif self.approval_type == 'charter':
|
|
worksheet.write(row, 1, '章程', cell_format)
|
|
else:
|
|
worksheet.write(row, 1, '', cell_format)
|
|
|
|
# 业务类型
|
|
business_types = []
|
|
for category in self.information_categories_ids:
|
|
business_types.append(category.name)
|
|
worksheet.write(row, 2, ', '.join(business_types), cell_format)
|
|
|
|
# 合同类型
|
|
worksheet.write(row, 3, self.contract_type.name if self.contract_type else '', cell_format)
|
|
|
|
# 合同金额
|
|
worksheet.write(row, 4, f'{self.amount}元', cell_format)
|
|
|
|
# 情况说明
|
|
worksheet.write(row, 5, self.remarks or '', cell_format)
|
|
|
|
# 写入附件信息
|
|
row += 2
|
|
worksheet.write(row, 0, '附件清单:', header_format)
|
|
row += 1
|
|
for i, attachment in enumerate(self.documents_ids):
|
|
worksheet.write(row + i, 0, attachment.name, cell_format)
|
|
|
|
# 写入律师意见
|
|
row += len(self.documents_ids) + 2
|
|
worksheet.write(row, 0, '律师意见:', header_format)
|
|
row += 1
|
|
for i, attachment in enumerate(self.lawyer_opinion_ids):
|
|
worksheet.write(row + i, 0, attachment.name, cell_format)
|
|
|
|
# 调整列宽
|
|
worksheet.set_column('A:A', 20)
|
|
worksheet.set_column('B:B', 15)
|
|
worksheet.set_column('C:C', 25)
|
|
worksheet.set_column('D:D', 20)
|
|
worksheet.set_column('E:E', 15)
|
|
worksheet.set_column('F:F', 30)
|
|
|
|
workbook.close()
|
|
output.seek(0)
|
|
|
|
# 返回Excel文件
|
|
return {
|
|
'type': 'ir.actions.act_url',
|
|
'url': '/web/content/?model=ir.attachment&id=%s&filename_field=name&field=datas&download=true&filename=%s.xlsx' % (
|
|
self.env['ir.attachment'].create({
|
|
'name': f'汇审意见表_{self.code or "模板"}.xlsx',
|
|
'type': 'binary',
|
|
'datas': base64.b64encode(output.read()).decode(),
|
|
'res_model': self._name,
|
|
'res_id': self.id,
|
|
}).id,
|
|
f'汇审意见表_{self.code or "模板"}'
|
|
),
|
|
'target': 'new',
|
|
}
|
|
|
|
|
|
@api.onchange('user_id')
|
|
def _onchange_user_id(self):
|
|
if self.user_id:
|
|
self.department_id = self.user_id.employee_id.department_id.id
|
|
|