From ce58e989dda44df9a74cc198bc99c539e71988f9 Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Thu, 4 Jan 2024 08:51:25 +0800
Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E7=9A=84=E6=89=B9=E9=87=8F?=
=?UTF-8?q?=E6=8E=92=E7=A8=8B=E5=B7=B2=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_plan/models/custom_plan.py | 75 ++++++++++++++++++-----------------
sf_plan/views/view.xml | 2 +-
2 files changed, 39 insertions(+), 38 deletions(-)
diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py
index ddc7ed1c..a60af7f3 100644
--- a/sf_plan/models/custom_plan.py
+++ b/sf_plan/models/custom_plan.py
@@ -153,44 +153,45 @@ class sf_production_plan(models.Model):
"""
排程方法
"""
- if not self.production_line_id:
- raise ValidationError("未选择生产线")
- else:
- workorder_id_list = self.production_id.workorder_ids.ids
- if self.production_id.workorder_ids:
- for item in self.production_id.workorder_ids:
- if item.name == 'CNC加工':
- item.date_planned_finished = datetime.now() + timedelta(days=100)
- item.date_planned_start = self.date_planned_start
- item.date_planned_finished = item.date_planned_start + timedelta(
- minutes=self.env['mrp.routing.workcenter'].sudo().search(
- [('name', '=', 'CNC加工')]).time_cycle)
- item.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
- [('name', '=', 'CNC加工')]).time_cycle
- self.calculate_plan_time_before(item, workorder_id_list)
- self.calculate_plan_time_after(item, workorder_id_list)
- self.date_planned_start, self.date_planned_finished = \
- item.date_planned_start, item.date_planned_finished
- self.state = 'done'
- self.production_id.schedule_state = '已排'
- mrp_production_ids = self.production_id._get_children().ids
- print('mrp_production_ids', mrp_production_ids)
- for i in mrp_production_ids:
- self.env['mrp.production'].browse(i).schedule_state = '已排'
- # self.production_id.date_planned_start = self.date_planned_start
- # self.production_id.date_planned_finished = self.date_planned_finished
+ for record in self:
+ if not record.production_line_id:
+ raise ValidationError("未选择生产线")
else:
- raise ValidationError("未找到工单")
- # self.date_planned_finished = self.date_planned_start + timedelta(days=3)
- # self.state = 'done'
- return {
- 'name': '排程甘特图',
- 'type': 'ir.actions.act_window',
- 'res_model': 'sf.production.plan', # 要跳转的模型名称
- # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
- 'view_mode': 'gantt,tree,form',
- 'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
- }
+ workorder_id_list = record.production_id.workorder_ids.ids
+ if record.production_id.workorder_ids:
+ for item in record.production_id.workorder_ids:
+ if item.name == 'CNC加工':
+ item.date_planned_finished = datetime.now() + timedelta(days=100)
+ item.date_planned_start = record.date_planned_start
+ item.date_planned_finished = item.date_planned_start + timedelta(
+ minutes=record.env['mrp.routing.workcenter'].sudo().search(
+ [('name', '=', 'CNC加工')]).time_cycle)
+ item.duration_expected = record.env['mrp.routing.workcenter'].sudo().search(
+ [('name', '=', 'CNC加工')]).time_cycle
+ record.calculate_plan_time_before(item, workorder_id_list)
+ record.calculate_plan_time_after(item, workorder_id_list)
+ record.date_planned_start, record.date_planned_finished = \
+ item.date_planned_start, item.date_planned_finished
+ record.state = 'done'
+ record.production_id.schedule_state = '已排'
+ mrp_production_ids = record.production_id._get_children().ids
+ print('mrp_production_ids', mrp_production_ids)
+ for i in mrp_production_ids:
+ record.env['mrp.production'].browse(i).schedule_state = '已排'
+ # record.production_id.date_planned_start = record.date_planned_start
+ # record.production_id.date_planned_finished = record.date_planned_finished
+ else:
+ raise ValidationError("未找到工单")
+ # record.date_planned_finished = record.date_planned_start + timedelta(days=3)
+ # record.state = 'done'
+ return {
+ 'name': '排程甘特图',
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'sf.production.plan', # 要跳转的模型名称
+ # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
+ 'view_mode': 'gantt,tree,form',
+ 'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
+ }
def calculate_plan_time_before(self, item, workorder_id_list):
"""
diff --git a/sf_plan/views/view.xml b/sf_plan/views/view.xml
index 4e872b5a..c1bdf5fe 100644
--- a/sf_plan/views/view.xml
+++ b/sf_plan/views/view.xml
@@ -5,7 +5,7 @@
sf.production.plan.tree
sf.production.plan
-
+