From e29456bbf7a42553d3689e5e0ae2761c30649a41 Mon Sep 17 00:00:00 2001
From: hyyy <123@qq.com>
Date: Mon, 16 Jun 2025 17:25:52 +0800
Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=88=97=E8=A1=A8=E5=B1=95?=
=?UTF-8?q?=E7=A4=BA=E5=9B=BE=E7=89=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_demand_plan/__manifest__.py | 1 +
sf_demand_plan/static/src/js/print_demand.js | 205 ++++++++++++++++++
sf_demand_plan/static/src/scss/style.css | 55 +++++
.../sf_demand_plan_print_wizard_view.xml | 6 +-
4 files changed, 264 insertions(+), 3 deletions(-)
create mode 100644 sf_demand_plan/static/src/js/print_demand.js
diff --git a/sf_demand_plan/__manifest__.py b/sf_demand_plan/__manifest__.py
index 932685e0..2a543f1a 100644
--- a/sf_demand_plan/__manifest__.py
+++ b/sf_demand_plan/__manifest__.py
@@ -23,6 +23,7 @@
],
'web.assets_backend': [
'sf_demand_plan/static/src/scss/style.css',
+ 'sf_demand_plan/static/src/js/print_demand.js',
]
},
'license': 'LGPL-3',
diff --git a/sf_demand_plan/static/src/js/print_demand.js b/sf_demand_plan/static/src/js/print_demand.js
new file mode 100644
index 00000000..b1ecd7e7
--- /dev/null
+++ b/sf_demand_plan/static/src/js/print_demand.js
@@ -0,0 +1,205 @@
+odoo.define('sf_demand.print_demand', function (require) {
+ "use strict";
+
+ var ListController = require('web.ListController');
+ var ListRenderer = require('web.ListRenderer');
+ var ListView = require('web.ListView');
+ var viewRegistry = require('web.view_registry');
+ var { url } = require("@web/core/utils/urls")
+
+ var CustomListRenderer = ListRenderer.extend({
+ _render: function () {
+ var self = this;
+ this.getParent()?.$buttons.hide()
+ return this._super.apply(this, arguments).then(function () {
+ // 添加图片预览容器到页面左侧
+ if (!$('.table-image-preview-container').length) {
+ self.$el.parent().addClass('custom-table-image-container')
+ self.$el.before(
+ `
+
![]()
+
+
`
+ );
+ self.$el.prepend(`
+
+
+
+
+ `);
+ }
+ });
+ },
+
+ events: _.extend({}, ListRenderer.prototype.events, {
+ 'click .o_data_row': '_onCustomRowClick',
+ 'click .o_print_custom': '_onPrintClick',
+ 'click .o_cancel_custom': '_onCancelClick'
+ }),
+ _onCancelClick() {
+ this.getParent()?.getParent()?.dialogs.closeAll()
+ },
+ _onCustomRowClick: async function (ev) {
+ var self = this;
+ var $row = $(ev.currentTarget);
+ var index = $row.index();
+ var data = this.state.data[index];
+ console.log(this, 'this', data);
+ if(data.fileData?.fileUrl) {
+
+ } else {
+ data.fileData = { }
+ if(data.res_id) {
+ // 正确获取 ORM 服务的方式
+ // var orm = this.getParent().getParent().env.services
+ const key = data.data.type == 1 ? 'machining_drawings' : 'cnc_worksheet'
+ const attachment = await this._rpc({
+ model: 'ir.binary',
+ method: 'attachment_info',
+ args: [
+ data.model,
+ data.res_id,
+ key
+ ],
+ })
+
+ if (attachment) {
+ Object.assign(data.fileData, attachment)
+ this._getTypeInfo(attachment.mimetype, data.fileData)
+ }
+ console.log(data, 'data', attachment);
+ const fileUrl = this.getFileUrl(data.fileData.attachment_type, data, key)
+ data.fileData.fileUrl = fileUrl
+ }
+ }
+ $('.table-image-preview-container').hide()
+ if(data.fileData.attachment_type == 'iframe') {
+
+ $('iframe.table-image-preview-container').attr('src', decodeURIComponent(data.fileData.fileUrl) ).show()
+ } else {
+ $('img.table-image-preview-container').attr('src', data.fileData.fileUrl).show()
+ }
+ },
+ getSelectedIds: function() {
+ return this.state.data.map(_ => {
+ return _.data.id
+ })
+ },
+ _onPrintClick(e) {
+ console.log(e, 'asdsadadsadasdad', this);
+ var selectedIds = this.getSelectedIds();
+
+ console.log(selectedIds);
+
+ this._rpc({
+ model: 'sf.demand.plan.print.wizard',
+ method: 'demand_plan_print',
+ kwargs: selectedIds,
+ // context: this.state.getContext()
+ }).then(function() {
+ self.do_notify("成功", "打印任务已发送到打印机");
+ }).catch(function(error) {
+ console.error("打印错误:", error);
+ self.do_warn("打印失败", error.data.message || "未知错误");
+ });
+
+ },
+ getFileUrl(attachment_type, data, key) {
+ let fileUrl
+ switch (attachment_type) {
+ case 'image':
+ const timer = +new Date()
+ fileUrl = url("/web/image", {
+ model: data.model,
+ id: data.res_id,
+ field: key,
+ unique: '',
+ timer
+ });
+
+ break;
+ case 'iframe':
+
+ const iframe_file_url = encodeURIComponent(
+ url("/web/content", {
+ model: data.model,
+ id: data.res_id,
+ field: key,
+ })
+ );
+ fileUrl = `${this.state.attachment_base}?file=${iframe_file_url}`;
+ case 'unknown':
+ fileUrl = encodeURIComponent(
+ url("/web/content", {
+ model: data.model,
+ id: data.res_id,
+ field: key,
+ })
+ );
+ }
+
+ return fileUrl
+ },
+ _getTypeInfo(type, data) {
+ switch (type) {
+ case 'application/pdf':
+ data.attachment_base = `/web/static/lib/pdfjs/web/viewer.html`;
+ data.attachment_type = 'iframe'
+ break;
+ case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
+ data.attachment_base = `/jikimo_attachment_viewer/static/lib/docxjs/viewer.html`;
+ data.attachment_type = 'iframe'
+ break;
+ case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
+ data.attachment_base = `/jikimo_attachment_viewer/static/lib/exceljs/viewer.html`;
+ data.attachment_type = 'iframe'
+ break;
+ case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
+ data.attachment_base = '';
+ data.attachment_type = 'unknown'
+ break;
+ case 'image/png':
+ case 'image/jpeg':
+ case 'image/jpg':
+ data.attachment_base = ''
+ data.attachment_type = 'image'
+ break;
+ default:
+ data.attachment_base = ''
+ data.attachment_type = 'unknown'
+ break;
+ }
+ }
+ });
+
+ var CustomListController = ListController.extend({
+ // 可以保留或移除,根据是否需要处理自定义事件
+ // 处理打印操作
+ // rpc.query({
+ // model: 'sf.demand.plan.print.wizard',
+ // method: 'demand_plan_print',
+ // args: [recordIds]
+ // }).then(function(result) {
+ // self.do_notify("成功", "打印任务已发送到打印机");
+ // // 刷新视图显示最新状态
+ // self.reload();
+ // }).catch(function(error) {
+ // self.do_warn("打印失败", error.data.message || "发生未知错误");
+ // });
+ });
+
+ var PrintDemand = ListView.extend({
+ config: _.extend({}, ListView.prototype.config, {
+ Renderer: CustomListRenderer,
+ Controller: CustomListController,
+ }),
+ });
+
+ viewRegistry.add('print_demand', PrintDemand);
+
+ return PrintDemand;
+});
\ No newline at end of file
diff --git a/sf_demand_plan/static/src/scss/style.css b/sf_demand_plan/static/src/scss/style.css
index f5b687fb..358156b5 100644
--- a/sf_demand_plan/static/src/scss/style.css
+++ b/sf_demand_plan/static/src/scss/style.css
@@ -9,3 +9,58 @@
.demand_plan_tree .o_list_table_ungrouped {
min-width: 1900px;
}
+
+
+.o_selected_row {
+ background-color: #e6f7ff !important;
+ font-weight: bold;
+}
+
+.custom-table-image-container {
+ display: flex;
+ height: calc(95vh - 254px);
+ gap: 20px;
+ position: relative;
+ th.o_list_record_selector, td.o_list_record_selector{
+ display: none;
+ }
+ .custom-preview-container, .print_demand {
+ flex: 1;
+
+ max-width: 49%;
+ tbody {
+ tr:not(.o_data_row) {
+ display: none;
+ }
+ }
+ tfoot {
+ display: none;
+ }
+ }
+ .print_demand {
+ .table-responsive {
+ width: 100%;
+ overflow-x: auto!important;
+ }
+ }
+ .custom-preview-container {
+ background-color: #dadce0;
+ padding: 20px;
+ img {
+ max-width: 100%;
+ max-height: 100%;
+ }
+ iframe {
+ width: 100%;
+ height: 100%;
+ }
+ }
+ .o_print_custom, .o_cancel_custom {
+ position: absolute;
+ bottom: 20px;
+ right: 20px;
+ }
+ .o_print_custom {
+ right: 66px;
+ }
+}
\ No newline at end of file
diff --git a/sf_demand_plan/wizard/sf_demand_plan_print_wizard_view.xml b/sf_demand_plan/wizard/sf_demand_plan_print_wizard_view.xml
index 56b3c4fd..6927c283 100644
--- a/sf_demand_plan/wizard/sf_demand_plan_print_wizard_view.xml
+++ b/sf_demand_plan/wizard/sf_demand_plan_print_wizard_view.xml
@@ -4,12 +4,12 @@
sf.demand.plan.print.wizard.tree
sf.demand.plan.print.wizard
-
+
-
-
+
+