From fdddf19d134b5ffc37cb2ab10c8497a93e79d325 Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Tue, 27 Feb 2024 11:42:59 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=AD=E6=8E=A7=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=AF=B9=E5=B7=A5=E5=8D=95=E3=80=81?=
=?UTF-8?q?=E8=AE=A1=E5=88=92=E5=8D=95=E5=B1=9E=E6=80=A7=E7=9A=84=E6=94=B9?=
=?UTF-8?q?=E5=8F=98=EF=BC=88=E7=8A=B6=E6=80=81=EF=BC=8C=E6=97=B6=E9=97=B4?=
=?UTF-8?q?=E7=AD=89=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_manufacturing/controllers/controllers.py | 21 +++++++++++++++-
sf_manufacturing/models/mrp_production.py | 4 ++-
sf_plan/models/custom_plan.py | 23 ++++++++++++------
sf_plan/views/view.xml | 27 +++++++++++++++++----
sf_warehouse/models/model.py | 2 +-
5 files changed, 62 insertions(+), 15 deletions(-)
diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py
index f77450f9..d62de74f 100644
--- a/sf_manufacturing/controllers/controllers.py
+++ b/sf_manufacturing/controllers/controllers.py
@@ -164,6 +164,13 @@ class Manufacturing_Connect(http.Controller):
return json.JSONEncoder().encode(res)
workorder.equipment_id = work_equipment_id
workorder.button_start()
+
+ # 根据工单的实际开始时间修改排程单的开始时间、状态
+ if workorder.date_start:
+ request.env['sf.production.plan'].sudo().search([('production_id', '=', production_id)]).write(
+ {'actual_start_time': workorder.date_start,
+ 'state': 'processing'})
+
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('button_Work_START error:%s' % e)
@@ -193,6 +200,19 @@ class Manufacturing_Connect(http.Controller):
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '该工单未开始'}
return json.JSONEncoder().encode(res)
workorder.button_finish()
+
+ # 根据工单的实际结束时间修改排程单的结束时间、状态,同时修改销售订单的状态
+ if workorder.date_finished:
+ request.env['sf.production.plan'].sudo().search([('production_id', '=', production_id)]).write(
+ {'actual_end_time': workorder.date_finished,
+ 'state': 'finished'})
+ production_obj = request.env['mrp.production'].sudo().search([('name', '=', production_id)])
+ if production_obj:
+ production_obj.sudo().schedule_state = '已完成'
+ production_obj.write({'state': 'completed'})
+ request.env['sale.order'].sudo().search(
+ [('name', '=', production_obj.origin)]).write({'schedule_status': 'to deliver'})
+
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('button_Work_End error:%s' % e)
@@ -362,7 +382,6 @@ class Manufacturing_Connect(http.Controller):
old_localtion.location_status = '空闲'
old_localtion.production_id = False
-
# return json.JSONEncoder().encode(res)
# else:
# res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index b740704e..2ca0dbc6 100644
--- a/sf_manufacturing/models/mrp_production.py
+++ b/sf_manufacturing/models/mrp_production.py
@@ -92,7 +92,9 @@ class MrpProduction(models.Model):
# 新添加的状态逻辑
if production.state == 'progress' and production.schedule_state == '已排':
production.state = 'pending_processing'
- elif production.state == 'progress' and production.schedule_state == '已完成':
+ # elif production.state == 'progress' and production.schedule_state == '已完成':
+ # production.state = 'completed'
+ elif production.state == 'pending_processing' and production.schedule_state == '已完成':
production.state = 'completed'
def action_check(self):
diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py
index d1a82501..d4402c98 100644
--- a/sf_plan/models/custom_plan.py
+++ b/sf_plan/models/custom_plan.py
@@ -52,10 +52,10 @@ class sf_production_plan(models.Model):
('reverse', '倒排'), ('positive', '顺排')], string='排程设置', default='reverse')
product_id = fields.Many2one('product.product', '关联产品')
origin = fields.Char(string='订单号')
- # 加工时长
- process_time = fields.Float(string='加工时长', digits=(16, 2))
+ # # 加工时长
+ # process_time = fields.Float(string='加工时长', digits=(16, 2))
# 实际加工时长、实际开始时间、实际结束时间
- actual_process_time = fields.Float(string='实际加工时长', digits=(16, 2))
+ actual_process_time = fields.Float(string='实际加工时长(分钟)', digits=(16, 2), compute='_compute_actual_process_time')
actual_start_time = fields.Datetime(string='实际开始时间')
actual_end_time = fields.Datetime(string='实际结束时间')
shift = fields.Char(string='班次')
@@ -67,16 +67,25 @@ class sf_production_plan(models.Model):
sequence = fields.Integer(string='序号', copy=False, readonly=True, index=True)
current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划')
+ # 计算实际加工时长
+ @api.depends('actual_start_time', 'actual_end_time')
+ def _compute_actual_process_time(self):
+ for item in self:
+ if item.actual_start_time and item.actual_end_time:
+ item.actual_process_time = (item.actual_end_time - item.actual_start_time).total_seconds() / 60
+ else:
+ item.actual_process_time = None
+
@api.onchange('production_line_id')
def _compute_production_line_id(self):
for item in self:
item.sudo().production_id.production_line_id = item.production_line_id.id
item.sudo().production_id.plan_start_processing_time = item.date_planned_start
- @api.onchange('state')
- def _onchange_state(self):
- if self.state == 'finished':
- self.production_id.schedule_state = '已完成'
+ # @api.onchange('state')
+ # def _onchange_state(self):
+ # if self.state == 'finished':
+ # self.production_id.schedule_state = '已完成'
# @api.model
# def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
diff --git a/sf_plan/views/view.xml b/sf_plan/views/view.xml
index dfaa1ca8..efa350c4 100644
--- a/sf_plan/views/view.xml
+++ b/sf_plan/views/view.xml
@@ -66,9 +66,25 @@