From 413cf43ea062b5c924782204c2b94e7421086a35 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Wed, 25 Jun 2025 15:33:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E6=96=99=E9=9C=80=E6=B1=82=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/sale_order.py | 17 ++--- .../models/sf_production_demand_plan.py | 68 +++++++++---------- sf_demand_plan/models/stock_route.py | 2 +- 3 files changed, 39 insertions(+), 48 deletions(-) diff --git a/sf_demand_plan/models/sale_order.py b/sf_demand_plan/models/sale_order.py index f0bd5570..0d0bbf1c 100644 --- a/sf_demand_plan/models/sale_order.py +++ b/sf_demand_plan/models/sale_order.py @@ -50,19 +50,10 @@ class ReSaleOrder(models.Model): def action_view_demand_plan(self): self.ensure_one() demand_plan_ids = self.env['sf.production.demand.plan'].sudo().search([('sale_order_id', '=', self.id)]).ids - action = { + return { 'res_model': 'sf.production.demand.plan', 'type': 'ir.actions.act_window', + 'name': _("需求计划"), + 'domain': [('id', 'in', demand_plan_ids)], + 'view_mode': 'tree', } - if len(demand_plan_ids) == 1: - action.update({ - 'view_mode': 'form', - 'res_id': demand_plan_ids[0], - }) - else: - action.update({ - 'name': _("需求计划"), - 'domain': [('id', 'in', demand_plan_ids)], - 'view_mode': 'tree', - }) - return action diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 3abdd0f3..97d0fcfb 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -30,7 +30,7 @@ class SfProductionDemandPlan(models.Model): ('50', '待下达生产'), ('60', '已下达'), ('100', '取消'), - ], string='状态', default='30', compute='_compute_status', store=True) + ], string='状态', default='30', readonly=True) demand_plan_id = fields.Many2one(comodel_name="sf.demand.plan", string="物料需求", readonly=True) sale_order_id = fields.Many2one(comodel_name="sale.order", @@ -154,41 +154,41 @@ class SfProductionDemandPlan(models.Model): [('demand_plan_selectable', '=', True), ('stock_route_group_ids', '=', group_id.id)]) if route_ids: pdp.route_ids = route_ids.ids - break + continue pdp.route_ids = None - @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: - sale_order_state = record.sale_order_id.state - if sale_order_state in ('draft', 'sent', 'supply method'): - record.status = '20' # 待确认 - 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 = '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 record.sale_order_id.mrp_production_ids: - product_productions = record.sale_order_id.mrp_production_ids.filtered( - lambda p: p.product_id.id == record.product_id.id - ) - if product_productions and all(order.schedule_state != '未排' for order in product_productions): - record.status = '60' # 已下达 - if sale_order_state == 'cancel' or not record.sale_order_line_id: - record.status = '100' # 取消 + # @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: + # sale_order_state = record.sale_order_id.state + # if sale_order_state in ('draft', 'sent', 'supply method'): + # record.status = '20' # 待确认 + # 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 = '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 record.sale_order_id.mrp_production_ids: + # product_productions = record.sale_order_id.mrp_production_ids.filtered( + # lambda p: p.product_id.id == record.product_id.id + # ) + # if product_productions and all(order.schedule_state != '未排' for order in product_productions): + # record.status = '60' # 已下达 + # if sale_order_state == 'cancel' or not record.sale_order_line_id: + # record.status = '100' # 取消 @api.depends('sale_order_line_id.product_id.name') def _compute_sale_order_line_number(self): diff --git a/sf_demand_plan/models/stock_route.py b/sf_demand_plan/models/stock_route.py index 20e4b3c9..7719d7b1 100644 --- a/sf_demand_plan/models/stock_route.py +++ b/sf_demand_plan/models/stock_route.py @@ -19,7 +19,7 @@ class SfStockRoute(models.Model): [('supply_method', 'in', stock_route_group)]) if demand_plan_ids: sr.demand_plan_ids = demand_plan_ids.ids - break + continue sr.demand_plan_ids = None # def name_get(self):