From e5404efb60361c8f55c3c1824602105db39e1e85 Mon Sep 17 00:00:00 2001 From: hyyy <123@qq.com> Date: Tue, 15 Jul 2025 11:39:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=B8=8B=E8=BE=BE=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E7=A6=81=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/__manifest__.py | 4 +- sf_demand_plan/static/src/js/custom_button.js | 59 +++++++++++++++++++ sf_demand_plan/views/demand_plan.xml | 3 +- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 sf_demand_plan/static/src/js/custom_button.js diff --git a/sf_demand_plan/__manifest__.py b/sf_demand_plan/__manifest__.py index 474c1608..3b20be8f 100644 --- a/sf_demand_plan/__manifest__.py +++ b/sf_demand_plan/__manifest__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +# jikimo_printing { 'name': '机企猫智能工厂 需求计划', 'version': '1.1', @@ -10,7 +11,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': ['sf_plan','jikimo_printing'], + 'depends': ['sf_plan' ], 'data': [ 'security/ir.model.access.csv', 'data/stock_route_group.xml', @@ -30,6 +31,7 @@ 'web.assets_backend': [ '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', ] }, '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 new file mode 100644 index 00000000..4a510923 --- /dev/null +++ b/sf_demand_plan/static/src/js/custom_button.js @@ -0,0 +1,59 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { ListRenderer } from "@web/views/list/list_renderer"; +import { useService } from "@web/core/utils/hooks"; +import { useEffect } from "@odoo/owl"; + +export class CustomDemandPlanListRenderer extends ListRenderer { + setup() { + super.setup(); + this.orm = useService("orm"); + this.notification = useService("notification"); + console.log('setup', this.props); + + // 监听selection属性的变化 + useEffect(() => { + this.updateButtonState(); + }, () => [this.props.list.selection]); + } + + /** + * 更新按钮状态 + */ + async updateButtonState() { + 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); + } else { + button.attr('disabled', false); + } + } +} +// 使用setTimeout延迟注册,避免在模块加载时立即执行 +setTimeout(() => { + const registerCustomRenderer = () => { + try { + const listView = registry.category("views").get("list"); + if (listView) { + registry.category("views").add("custom_demand_plan_list", { + ...listView, + Renderer: CustomDemandPlanListRenderer, + }); + console.log("Custom demand plan list renderer registered successfully"); + } else { + console.warn("List view not found, retrying..."); + // 如果还没找到,再等一段时间 + setTimeout(registerCustomRenderer, 1000); + } + } catch (error) { + console.error("Error registering custom renderer:", error); + } + }; + + registerCustomRenderer(); +}, 1000); \ No newline at end of file diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml index d03f55e7..a5b3bddd 100644 --- a/sf_demand_plan/views/demand_plan.xml +++ b/sf_demand_plan/views/demand_plan.xml @@ -4,7 +4,8 @@ sf.production.demand.plan + class="demand_plan_tree freeze-columns-before-part_number" create="false" delete="false" + js_class="custom_demand_plan_list">