通知公告打印

This commit is contained in:
李鹏宇
2026-02-21 15:54:03 +08:00
parent 55ac43a56c
commit 76ee318767
5 changed files with 178 additions and 0 deletions
+2
View File
@@ -16,6 +16,8 @@
'data/notice_code_data.xml',
'data/notice_cron_data.xml',
'data/notice_type_data.xml',
'report/notice_print_report.xml',
'report/notice_print_template.xml',
'views/yuthon_notice_views.xml',
'views/yuthon_notice_type_views.xml',
'views/yuthon_cs_tree_views.xml',
+6
View File
@@ -272,6 +272,12 @@ class YuthonNotice(models.Model):
'end_date': fields.Date.today(),
})
def action_print_notice(self):
"""打印通知公告"""
self.ensure_one()
report = self.env.ref('yuthon_notice.action_notice_print_report')
return report.report_action(self)
class YuthonCsTree(models.Model):
_name = 'yuthon.cs.tree'
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="paperformat_notice_small" model="report.paperformat">
<field name="name">Notice Small Top Margin</field>
<field name="format">A4</field>
<field name="margin_top">5</field>
<field name="orientation">Portrait</field>
</record>
<record id="action_notice_print_report" model="ir.actions.report">
<field name="name">通知公告</field>
<field name="paperformat_id" ref="yuthon_notice.paperformat_notice_small"/>
<field name="model">yuthon.notice</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">yuthon_notice.notice_print_template</field>
<field name="report_file">yuthon_notice.notice_print_template</field>
<field name="binding_model_id" ref="model_yuthon_notice"/>
<field name="binding_type">report</field>
<field name="print_report_name">'通知公告_%s_%s' % (object.name or '', object.code or '')</field>
</record>
</data>
</odoo>
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="notice_print_template">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="web.external_layout">
<style type="text/css">
/* 表格纵向版式:自适应,最大800px 居中 */
table { border-collapse: collapse; width: 100%; max-width: 800px; margin: 0 auto; table-layout: fixed; }
td { border: 1px solid #000; padding: 6px; text-align: center; vertical-align: middle; }
.title {
text-align: center;
font-weight: bold;
font-size: 18px;
padding: 8px 0;
}
.header-cell { font-weight: bold; background-color: #d4e6f1;}
/* 附件清单左对齐 */
.attachment-list { text-align: left; }
/* 隐藏意见和审批人之间的竖边框 */
.no-right-border { border-right: none !important; }
.no-left-border { border-left: none !important; }
</style>
<!-- 流水号:页面左上角,位于标题之上,浅灰色 -->
<div style="margin-bottom:8px; text-align:left; color:#999999;">
流水号:<span t-esc="doc.code or ''"/>
</div>
<!-- 通知公告标题 -->
<div class="title">
通知公告
</div>
<table>
<colgroup>
<col style="width:15%"/>
<col style="width:35%"/>
<col style="width:15%"/>
<col style="width:35%"/>
</colgroup>
<tr>
<td class="header-cell"><strong>标题</strong></td>
<td colspan="3"><span t-esc="doc.name or ''"/></td>
</tr>
<tr>
<td class="header-cell"><strong>类型</strong></td>
<td><span t-esc="doc.notice_type_id.name or ''"/></td>
<td class="header-cell"><strong>紧急程度</strong></td>
<td>
<span t-if="doc.urgency_level == 'normal'">普件</span>
<span t-if="doc.urgency_level == 'urgent'">急件</span>
<span t-if="doc.urgency_level == 'emergency'">特急件</span>
</td>
</tr>
<tr>
<td class="header-cell"><strong>发布人</strong></td>
<td><span t-esc="doc.users_id.name or ''"/></td>
<td class="header-cell"><strong>发布部门</strong></td>
<td><span t-esc="doc.department_id.name or ''"/></td>
</tr>
<tr>
<td class="header-cell"><strong>发布日期</strong></td>
<td><span t-esc="doc.create_date1 and doc.create_date1.strftime('%Y-%m-%d') or ''"/></td>
<td class="header-cell"><strong>生效日期</strong></td>
<td><span t-esc="doc.start_date and doc.start_date.strftime('%Y-%m-%d') or ''"/></td>
</tr>
<tr>
<td class="header-cell"><strong>正文</strong></td>
<td colspan="3" class="attachment-list"><span t-field="doc.notice_text1"/></td>
</tr>
<tr>
<td class="header-cell"><strong>附件</strong></td>
<td colspan="3" class="attachment-list">
<t t-foreach="doc.documents_ids" t-as="att">
<div><span t-esc="att.name or ''"/></div>
</t>
</td>
</tr>
<!-- 发布范围 -->
<tr>
<td colspan="4" style="background-color: #d4e6f1; text-align: center;"><strong>发布范围</strong></td>
</tr>
<tr>
<td class="header-cell"><strong>部门范围</strong></td>
<td colspan="3" class="attachment-list">
<t t-foreach="doc.department_ids" t-as="dept">
<span t-esc="dept.name"/>
<t t-if="not dept_last">、</t>
</t>
</td>
</tr>
<tr>
<td class="header-cell"><strong>角色组</strong></td>
<td colspan="3" class="attachment-list">
<t t-foreach="doc.users_role_group_ids" t-as="role_group">
<span t-esc="role_group.name"/>
<t t-if="not role_group_last">、</t>
</t>
</td>
</tr>
<tr>
<td class="header-cell"><strong>角色范围</strong></td>
<td colspan="3" class="attachment-list">
<t t-foreach="doc.users_role_ids" t-as="role">
<span t-esc="role.name"/>
<t t-if="not role_last">、</t>
</t>
</td>
</tr>
<tr>
<td class="header-cell"><strong>人员范围</strong></td>
<td colspan="3" class="attachment-list">
<t t-foreach="doc.employee_ids" t-as="emp">
<span t-esc="emp.name"/>
<t t-if="not emp_last">、</t>
</t>
</td>
</tr>
<!-- 审批详情 -->
<tr>
<td colspan="4" style="background-color: #d4e6f1; text-align: center;"><strong>审批详情</strong></td>
</tr>
<t t-set="logs_ordered" t-value="doc.log_ids.sorted(lambda x: x.date_create or '')"/>
<t t-foreach="logs_ordered" t-as="log">
<tr>
<td colspan="1"><span t-esc="log.name or '节点'"/></td>
<td class="no-right-border" colspan="2"><span t-esc="log.comment or ''"/></td>
<td class="no-left-border" colspan="1">
<t t-if="log.done_by">
<span t-esc="log.done_by.name"/> <span t-esc="log.lase_click_date and log.lase_click_date.strftime('%Y-%m-%d') or ''"/>
</t>
</td>
</tr>
</t>
</table>
</t>
</t>
</t>
</template>
</odoo>
@@ -29,6 +29,9 @@
<field name="model">yuthon.notice</field>
<field name="arch" type="xml">
<form string="公告管理" create="0">
<header>
<button name="action_print_notice" string="打印" type="object" class="btn-primary" invisible="not work_end"/>
</header>
<sheet>
<widget name="web_ribbon" title="普件" bg_color="text-bg-success"
invisible="urgency_level != 'normal'"/>