From b267f2351dbf2aa4bf562fe57806e3c4230fdc11 Mon Sep 17 00:00:00 2001 From: guanhuan Date: Tue, 1 Jul 2025 14:34:27 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E8=AE=A1=E5=88=92=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/models/sf_demand_plan.py | 1 + .../models/sf_production_demand_plan.py | 21 +++++++++++++++---- sf_demand_plan/models/sf_production_plan.py | 15 ------------- sf_demand_plan/views/demand_plan.xml | 6 +++--- sf_demand_plan/views/demand_plan_info.xml | 10 ++++----- 5 files changed, 26 insertions(+), 27 deletions(-) delete mode 100644 sf_demand_plan/models/sf_production_plan.py diff --git a/sf_demand_plan/models/sf_demand_plan.py b/sf_demand_plan/models/sf_demand_plan.py index 948ee9e1..9ca91077 100644 --- a/sf_demand_plan/models/sf_demand_plan.py +++ b/sf_demand_plan/models/sf_demand_plan.py @@ -173,6 +173,7 @@ class SfDemandPlan(models.Model): status_line = line.line_ids.filtered(lambda p: p.status == '60') if line.sale_order_id.state == 'cancel': line.state = '50' + line.line_ids.status = '100' elif len(line.line_ids) == len(status_line): line.state = '40' elif bool(status_line): diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index bf27d5ee..3be61e85 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -257,8 +257,11 @@ class SfProductionDemandPlan(models.Model): @api.depends('status') def _compute_mrp_production_ids(self): for record in self: - record.mrp_production_ids = self.env['mrp.production'].sudo().search( - [('demand_plan_line_id', '=', record.id)]).ids + if record.status in ('50', '60'): + record.mrp_production_ids = self.env['mrp.production'].sudo().search( + [('demand_plan_line_id', '=', record.id)]).ids + else: + record.mrp_production_ids = None @api.depends('mrp_production_ids.state') def _compute_hide_release_production_order(self): @@ -274,10 +277,11 @@ class SfProductionDemandPlan(models.Model): if record.planned_start_date and record.planned_start_date < fields.Date.today(): raise ValidationError("计划开工日期必须大于或等于今天。") - def release_production_order(self): + def button_release_production(self): + self.ensure_one() if not self.planned_start_date: raise ValidationError("请先填写计划开工日期") - pro_plan_list = self.env['sf.production.plan'].search( + pro_plan_list = self.env['sf.production.plan'].sudo().search( [('production_id', 'in', self.mrp_production_ids.ids), ('state', '=', 'draft')]) sf_production_line = self.env['sf.production.line'].sudo().search( [('name', '=', '1#CNC自动生产线')], limit=1) @@ -290,11 +294,19 @@ class SfProductionDemandPlan(models.Model): pro_plan_list.date_planned_start = date_planned_start self._do_production_schedule(pro_plan_list) self.status = '60' + self.update_sale_order_state() def _do_production_schedule(self, pro_plan_list): for pro_plan in pro_plan_list: pro_plan.do_production_schedule() + def update_sale_order_state(self): + demand_plan = self.env['sf.demand.plan'].sudo().search([('sale_order_id', '=', self.sale_order_id.id)]) + demand_plan_state = demand_plan.filtered(lambda line: line.state != '40') + if not demand_plan_state: + # 修改销售订单为加工中 + self.sale_order_id.state = 'processing' + def edit_button(self): self.ensure_one() action = { @@ -563,6 +575,7 @@ class SfProductionDemandPlan(models.Model): self.write({'status': '50'}) else: self.write({'status': '60'}) + self.update_sale_order_state() def mrp_bom_create(self): if self.supply_method in ('automation', 'manual'): diff --git a/sf_demand_plan/models/sf_production_plan.py b/sf_demand_plan/models/sf_production_plan.py deleted file mode 100644 index daf527f6..00000000 --- a/sf_demand_plan/models/sf_production_plan.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -from odoo import models, fields, api, _ - - -class SfProductionPlan(models.Model): - _inherit = 'sf.production.plan' - - demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan", - string="需求计划明细", readonly=True) - - @api.model - def create(self, vals): - res = super(SfProductionPlan, self).create(vals) - res.demand_plan_line_id = res.production_id.demand_plan_line_id.id - return res diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml index dc8a99c9..a466f691 100644 --- a/sf_demand_plan/views/demand_plan.xml +++ b/sf_demand_plan/views/demand_plan.xml @@ -43,7 +43,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -69,7 +69,7 @@ -