From 1bdb81f5f7b4a4bb153a93598eed82eca335e138 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Thu, 29 May 2025 17:05:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=85=E4=B8=8B=E8=BE=BE=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E7=8A=B6=E6=80=81=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 | 30 ++++++++++++++----- sf_demand_plan/views/demand_plan.xml | 6 ++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 04b25949..dcab21d4 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -25,8 +25,8 @@ class sf_production_plan(models.Model): ('10', '草稿'), ('20', '待确认'), ('30', '需求确认'), - ('40', '待下达生产'), - ('50', '已下达'), + ('50', '待下达生产'), + ('60', '已下达'), ('100', '取消'), ], string='状态', compute='_compute_status', store=True) sale_order_id = fields.Many2one(comodel_name="sale.order", @@ -100,7 +100,8 @@ class sf_production_plan(models.Model): sequence = fields.Integer('序号') - @api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line') + @api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line', + 'sale_order_id.mrp_production_ids.state') def _compute_status(self): for record in self: if record.sale_order_id: @@ -110,16 +111,23 @@ class sf_production_plan(models.Model): if record.supply_method in ('purchase', 'outsourcing') and sale_order_state in ( 'sale', 'processing', 'physical_distribution', 'delivered', 'done') and sale_order_state != 'cancel': - record.status = '50' # 已下达 + record.status = '60' # 已下达 if record.supply_method in ('automation', 'manual'): if sale_order_state in ( 'sale', 'processing', 'physical_distribution', 'delivered', 'done') and sale_order_state != 'cancel': record.status = '30' # 需求确认 + # 检查所有制造订单的排程单状态,有一个为待排程状态,就为待下达生产 + pending_productions = record.sale_order_id.mrp_production_ids.filtered( + lambda p: p.state == 'confirmed' and p.product_id.id == record.product_id.id + ) + if pending_productions: + record.status = '50' # 待下达生产 # 检查所有制造订单的排程单状态 - if all(order.product_id == record.product_id and order.schedule_state != '未排' for order in - record.sale_order_id.mrp_production_ids): - record.status = '50' # 已下达 + if record.sale_order_id.mrp_production_ids and all( + order.product_id == record.product_id and order.schedule_state != '未排' for order in + record.sale_order_id.mrp_production_ids): + record.status = '60' # 已下达 if sale_order_state == 'cancel' or not record.sale_order_line_id: record.status = '100' # 取消 @@ -313,3 +321,11 @@ class sf_production_plan(models.Model): 'views': [[self.env.ref('sf_demand_plan.action_plan_print_tree').id, 'list']], 'target': 'new', } + + def action_open_sale_order(self): + return { + 'type': 'ir.actions.act_window', + 'res_model': 'sale.order', + 'res_id': self.sale_order_id.id, + 'view_mode': 'form', + } diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml index 0a89a9c1..4e679bad 100644 --- a/sf_demand_plan/views/demand_plan.xml +++ b/sf_demand_plan/views/demand_plan.xml @@ -37,8 +37,10 @@ - + +