From bfc071debd95e1b3eaac78484bf470256e5d076e Mon Sep 17 00:00:00 2001 From: guanhuan Date: Tue, 15 Jul 2025 10:34:28 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E9=9C=80=E6=B1=82=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/sf_production_demand_plan.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index ca957bfb..651f7884 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -14,8 +14,8 @@ class SfProductionDemandPlan(models.Model): _description = 'sf_production_demand_plan' def get_location_id(self): - stock_location = self.env['stock.location'].sudo().search([('name', '=', '客户')], limit=1) - return stock_location.id + customer_location_id = self.env['ir.model.data']._xmlid_to_res_id('stock.stock_location_customers') + return customer_location_id priority = fields.Selection(related='demand_plan_id.priority', string='优先级') status = fields.Selection([ From 46f60028aa462711ae885a72cc9eddc840cc5f06 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Tue, 15 Jul 2025 10:40:19 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E9=9C=80=E6=B1=82=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/sf_production_demand_plan.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 651f7884..27de5b16 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -691,18 +691,6 @@ class SfProductionDemandPlan(models.Model): self.update_sale_order_state() def mrp_bom_create(self): - if self.supply_method in ('automation', 'manual'): - line_ids = self.demand_plan_id.line_ids.filtered( - lambda p: p.supply_method in ('automation', 'manual') and p.status in ('50', '60')) - if line_ids: - self.bom_id = line_ids[0].bom_id.id - return - elif self.supply_method == 'outsourcing': - line_ids = self.demand_plan_id.line_ids.filtered( - lambda p: p.supply_method == 'outsourcing' and p.status == '60') - if line_ids: - self.bom_id = line_ids[0].bom_id.id - return bom_type = '' # 根据供货方式修改成品模板 if self.supply_method == 'automation': @@ -722,6 +710,18 @@ class SfProductionDemandPlan(models.Model): # 复制成品模板上的属性 self.product_id.product_tmpl_id.copy_template(product_template_id) + if self.supply_method in ('automation', 'manual'): + line_ids = self.demand_plan_id.line_ids.filtered( + lambda p: p.supply_method in ('automation', 'manual') and p.status in ('50', '60')) + if line_ids: + self.bom_id = line_ids[0].bom_id.id + return + elif self.supply_method == 'outsourcing': + line_ids = self.demand_plan_id.line_ids.filtered( + lambda p: p.supply_method == 'outsourcing' and p.status == '60') + if line_ids: + self.bom_id = line_ids[0].bom_id.id + return future_time = datetime.now() + timedelta(hours=8) # 生成BOM单据编码 code = f"{self.product_id.default_code}-{bom_type}-{future_time.strftime('%Y%m%d%H%M%S')}" 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 3/6] =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=B8=8B=E8=BE=BE?= =?UTF-8?q?=E8=AE=A1=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">