From 20415d0d3f5ec4eb32c98027452fee7db70e936c Mon Sep 17 00:00:00 2001 From: hyyy <123@qq.com> Date: Wed, 16 Jul 2025 17:37:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E6=8B=89=E9=80=89=E9=A1=B9=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= 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/custom_button.js | 1 - .../src/js/custom_made_type_listener.js | 116 ++++++++++++++++++ sf_demand_plan/views/demand_plan.xml | 2 +- sf_demand_plan/views/demand_plan_info.xml | 2 +- 5 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 sf_demand_plan/static/src/js/custom_made_type_listener.js diff --git a/sf_demand_plan/__manifest__.py b/sf_demand_plan/__manifest__.py index 02fa7c2b..6e20e1e6 100644 --- a/sf_demand_plan/__manifest__.py +++ b/sf_demand_plan/__manifest__.py @@ -32,6 +32,7 @@ 'sf_demand_plan/static/src/scss/style.css', 'sf_demand_plan/static/src/js/print_demand.js', 'sf_demand_plan/static/src/js/custom_button.js', + 'sf_demand_plan/static/src/js/custom_made_type_listener.js', ] }, 'license': 'LGPL-3', diff --git a/sf_demand_plan/static/src/js/custom_button.js b/sf_demand_plan/static/src/js/custom_button.js index 4a510923..e0280671 100644 --- a/sf_demand_plan/static/src/js/custom_button.js +++ b/sf_demand_plan/static/src/js/custom_button.js @@ -25,7 +25,6 @@ export class CustomDemandPlanListRenderer extends ListRenderer { const selectedRecords = this.props.list.selection; const isStatus30 = selectedRecords.some(record => record.data.status != "30"); const button = $(this.__owl__.parent.bdom.parentEl).find('button[name="button_batch_release_plan"]'); - console.log('isStatus30', isStatus30, button); if (isStatus30) { // 禁用按钮 button.attr('disabled', true); diff --git a/sf_demand_plan/static/src/js/custom_made_type_listener.js b/sf_demand_plan/static/src/js/custom_made_type_listener.js new file mode 100644 index 00000000..4f2d3b9e --- /dev/null +++ b/sf_demand_plan/static/src/js/custom_made_type_listener.js @@ -0,0 +1,116 @@ +/** @odoo-module */ +import {patch} from '@web/core/utils/patch'; +import {ListRenderer} from "@web/views/list/list_renderer"; +import { useService } from "@web/core/utils/hooks"; +import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; + +patch(ListRenderer.prototype, 'jikimo_sf_demand_plan.ListRenderer', { + setup() { + // 获取各种服务 + this.dialog = useService("dialog"); + this.notification = useService("notification"); + this.orm = useService("orm"); + + owl.onMounted(() => { + this.listenSelect(); + }); + return this._super(...arguments); + }, + + listenSelect() { + // console.log('listenSelect 被调用'); + const dom = $(this.__owl__.bdom.el); + const _this = this; + if(dom.hasClass('custom_made_type_listener_select2')) { + this.listenSelect2(); + return + } + if(!dom.hasClass('custom_made_type_listener_select')) { + return; + } + // 检查是否包含custom_made_type字段 + const hasCustomMadeTypeField = dom.find('[name="custom_made_type"]').length > 0; + + if (hasCustomMadeTypeField) { + // console.log('找到custom_made_type字段,设置监听器'); + + dom.on('change', '[name="custom_made_type"] select', function (event) { + // console.log('检测到custom_made_type变化'); + + const record = _this.props.list.records; + const limitData = record.find(item => + item.data.status == '30' && + item.data.new_supply_method == 'custom_made' + ); + + if (!limitData) { + // console.log('未找到符合条件的记录'); + return; + } + + let limitVal = limitData.data.custom_made_type; + if (!limitVal) { + // console.log('limitVal为空'); + return; + } + + const v = $(this).val(); + limitVal = '"' + limitVal + '"'; + // console.log('当前值:', v, '限制值:', limitVal); + + if (v != limitVal) { + // console.log('值不匹配,显示确认对话框'); + + // 方法1:使用Odoo的确认对话框服务(推荐) + _this.showConfirmationDialog2(event.target, limitVal); + } + }); + } else { + console.log('未找到custom_made_type字段'); + } + }, + listenSelect2() { + // console.log('listenSelect2 被调用',this); + const dom = $(this.__owl__.bdom.el); + const _this = this; + dom.on('change', '[name="custom_made_type"] select', function (event) { + // console.log('检测到custom_made_type变化', event); + const record = _this.props.list.records; + const index = $(this).parents('tr').index(); + const data = record[index].data; + const data_id = data.id; + const product_id = data.product_id[0] + const v = $(this).val(); + const limitVal = $(this).find('option:selected').siblings(':not([value=false])').attr('value'); + // 请求接口 + _this.orm.call('sf.production.demand.plan', 'check_other_custom_made_demands', [data_id, product_id, v]).then(res => { + if(res) { + _this.showConfirmationDialog2(event.target, limitVal); + } + }) + }); + }, + + /** + * 方法2:使用ConfirmationDialog组件 + */ + async showConfirmationDialog2(target, correctValue) { + const confirmed = await this.dialog.add(ConfirmationDialog, { + title: "确认", + body: "请选择正确的类型", + confirm: () => { + console.log('用户确认'); + $(target).val(correctValue); + }, + cancel: () => { + console.log('用户取消'); + $(target).val(correctValue); + } + }); + }, + + + + +}); + diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml index a5b3bddd..68fb14e1 100644 --- a/sf_demand_plan/views/demand_plan.xml +++ b/sf_demand_plan/views/demand_plan.xml @@ -4,7 +4,7 @@ sf.production.demand.plan