From d5b5231873470433d02ef8b4bbc54447617756b3 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Tue, 27 Aug 2024 14:03:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E9=9D=A2=E5=8A=A0=E5=B7=A5=E5=B7=A5?= =?UTF-8?q?=E5=8D=95=E6=8E=92=E7=A8=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 44 +++++++++++++++++- .../models/mrp_routing_workcenter.py | 2 +- sf_manufacturing/models/mrp_workorder.py | 46 +++++++++++-------- .../views/mrp_routing_workcenter_view.xml | 1 + sf_manufacturing/views/mrp_workorder_view.xml | 3 ++ sf_mrs_connect/controllers/controllers.py | 1 + sf_plan/wizard/action_plan_some.py | 3 ++ sf_plan/wizard/action_plan_some.xml | 1 + 8 files changed, 80 insertions(+), 21 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 8e1f7199..cf4a6dce 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- import base64 +import datetime import logging import json import os import re import requests from itertools import groupby -from datetime import datetime from collections import defaultdict, namedtuple from odoo import api, fields, models, SUPERUSER_ID, _ from odoo.exceptions import UserError, ValidationError @@ -701,6 +701,48 @@ class MrpProduction(models.Model): self._reset_work_order_sequence() return True + def process_range_time(self): + for production in self: + works = production.workorder_ids + pro_plan = self.env['sf.production.plan'].search([('production_id', '=', production.id)], limit=1) + if not pro_plan: + continue + type_map = {'装夹预调': False, 'CNC加工': False, '解除装夹': False} + # 最后一次加工结束时间 + last_time = pro_plan.date_planned_start + # 预置时间 + for work in works: + count = type_map.get(work.routing_type) + date_planned_end = None + date_planned_start = None + duration_expected = datetime.timedelta(minutes=work.duration_expected) + reserve_time = datetime.timedelta(minutes=work.reserved_duration) + if not count: + # 第一轮加工 + if work.routing_type == '装夹预调': + date_planned_end = last_time - reserve_time + date_planned_start = date_planned_end - duration_expected + elif work.routing_type == 'CNC加工': + date_planned_start = last_time + date_planned_end = last_time + duration_expected + last_time = date_planned_end + else: + date_planned_start = last_time + reserve_time + date_planned_end = date_planned_start + duration_expected + last_time = date_planned_end + type_map.update({work.routing_type: True}) + else: + date_planned_start = last_time + reserve_time + date_planned_end = date_planned_start + duration_expected + last_time = date_planned_end + work.leave_id.write({ + 'date_from': date_planned_start, + 'date_to': date_planned_end, + }) + work.date_planned_start = date_planned_start + work.date_planned_finished = date_planned_end + # work.write({'date_planned_start': date_planned_start, 'date_planned_finished': date_planned_end}) + # 修改标记已完成方法 def button_mark_done1(self): if not self.workorder_ids.filtered(lambda w: w.routing_type not in ['表面工艺']): diff --git a/sf_manufacturing/models/mrp_routing_workcenter.py b/sf_manufacturing/models/mrp_routing_workcenter.py index 223ace85..0c380ebd 100644 --- a/sf_manufacturing/models/mrp_routing_workcenter.py +++ b/sf_manufacturing/models/mrp_routing_workcenter.py @@ -21,7 +21,7 @@ class ResMrpRoutingWorkcenter(models.Model): workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_route', required=True) bom_id = fields.Many2one('mrp.bom', required=False) surface_technics_id = fields.Many2one('sf.production.process', string="表面工艺") - + reserved_duration = fields.Float('预留时长', default=30, tracking=True) def get_no(self): international_standards = self.search( [('code', '!=', ''), ('active', 'in', [True, False])], diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 066cb133..0c8dad5f 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -237,7 +237,7 @@ class ResMrpWorkOrder(models.Model): tool_state = fields.Selection([('0', '正常'), ('1', '缺刀'), ('2', '无效刀')], string='功能刀具状态', default='0', store=True, compute='_compute_tool_state') tool_state_remark = fields.Text(string='功能刀具状态备注(缺刀)', compute='_compute_tool_state_remark', store=True) - + reserved_duration = fields.Float('预留时长', default=30, tracking=True) @api.depends('cnc_ids.tool_state') def _compute_tool_state_remark(self): for item in self: @@ -646,29 +646,36 @@ class ResMrpWorkOrder(models.Model): # 拼接工单对象属性值 def json_workorder_str(self, k, production, route, item): # 计算预计时长duration_expected - if route.routing_type == '切割': - duration_expected = self.env['mrp.routing.workcenter'].sudo().search( - [('name', '=', '切割')]).time_cycle - # elif route.routing_type == '获取CNC加工程序': + routing_types = ['切割', '装夹预调', 'CNC加工','解除装夹'] + if route.routing_type in routing_types: + routing_workcenter = self.env['mrp.routing.workcenter'].sudo().search( + [('name', '=', route.routing_type)]) + duration_expected = routing_workcenter.time_cycle + reserved_duration = routing_workcenter.reserved_duration + # if route.routing_type == '切割': # duration_expected = self.env['mrp.routing.workcenter'].sudo().search( - # [('name', '=', '获取CNC加工程序')]).time_cycle - elif route.routing_type == '装夹预调': - duration_expected = self.env['mrp.routing.workcenter'].sudo().search( - [('name', '=', '装夹预调')]).time_cycle - # elif route.routing_type == '前置三元定位检测': + # [('name', '=', '切割')]).time_cycle + # # elif route.routing_type == '获取CNC加工程序': + # # duration_expected = self.env['mrp.routing.workcenter'].sudo().search( + # # [('name', '=', '获取CNC加工程序')]).time_cycle + # elif route.routing_type == '装夹预调': # duration_expected = self.env['mrp.routing.workcenter'].sudo().search( - # [('name', '=', '前置三元定位检测')]).time_cycle - elif route.routing_type == 'CNC加工': - duration_expected = self.env['mrp.routing.workcenter'].sudo().search( - [('name', '=', 'CNC加工')]).time_cycle - # elif route.routing_type == '后置三元质量检测': + # [('name', '=', '装夹预调')]).time_cycle + # # elif route.routing_type == '前置三元定位检测': + # # duration_expected = self.env['mrp.routing.workcenter'].sudo().search( + # # [('name', '=', '前置三元定位检测')]).time_cycle + # elif route.routing_type == 'CNC加工': # duration_expected = self.env['mrp.routing.workcenter'].sudo().search( - # [('name', '=', '后置三元质量检测')]).time_cycle - elif route.routing_type == '解除装夹': - duration_expected = self.env['mrp.routing.workcenter'].sudo().search( - [('name', '=', '解除装夹')]).time_cycle + # [('name', '=', 'CNC加工')]).time_cycle + # # elif route.routing_type == '后置三元质量检测': + # # duration_expected = self.env['mrp.routing.workcenter'].sudo().search( + # # [('name', '=', '后置三元质量检测')]).time_cycle + # elif route.routing_type == '解除装夹': + # duration_expected = self.env['mrp.routing.workcenter'].sudo().search( + # [('name', '=', '解除装夹')]).time_cycle else: duration_expected = 60 + reserved_duration = 30 workorders_values_str = [0, '', { 'product_uom_id': production.product_uom_id.id, 'qty_producing': 0, @@ -692,6 +699,7 @@ class ResMrpWorkOrder(models.Model): item), # 'workpiece_delivery_ids': False if not route.routing_type == '装夹预调' else self._json_workpiece_delivery_list( # production) + 'reserved_duration': reserved_duration, }] return workorders_values_str diff --git a/sf_manufacturing/views/mrp_routing_workcenter_view.xml b/sf_manufacturing/views/mrp_routing_workcenter_view.xml index 5ab745db..eada92d9 100644 --- a/sf_manufacturing/views/mrp_routing_workcenter_view.xml +++ b/sf_manufacturing/views/mrp_routing_workcenter_view.xml @@ -17,6 +17,7 @@ + diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index eab42424..fd1141c4 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -36,6 +36,9 @@ + + + diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index ce342d4a..9fc65a85 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -48,6 +48,7 @@ class Sf_Mrs_Connect(http.Controller): if not production.workorder_ids: production.product_id.model_processing_panel = ret['processing_panel'] production._create_workorder(ret) + productions.process_range_time() # else: # for panel in ret['processing_panel'].split(','): # # 查询状态为进行中且工序类型为CNC加工的工单 diff --git a/sf_plan/wizard/action_plan_some.py b/sf_plan/wizard/action_plan_some.py index 7078efae..706714ee 100644 --- a/sf_plan/wizard/action_plan_some.py +++ b/sf_plan/wizard/action_plan_some.py @@ -16,6 +16,8 @@ class Action_Plan_All_Wizard(models.TransientModel): # 选择生产线 production_line_id = fields.Many2one('sf.production.line', string=u'生产线', required=True) + date_planned_start = fields.Datetime(string='计划开始时间', index=True, copy=False, + default=fields.Datetime.now) # 接收传递过来的计划ID plan_ids = fields.Many2many('sf.production.plan', string=u'计划ID') @@ -33,6 +35,7 @@ class Action_Plan_All_Wizard(models.TransientModel): # 拿到计划对象 plan_obj = self.env['sf.production.plan'].browse(plan.id) plan_obj.production_line_id = self.production_line_id.id + plan.date_planned_start = self.date_planned_start plan_obj.do_production_schedule() # plan_obj.state = 'done' print('处理计划:', plan.id, '完成') diff --git a/sf_plan/wizard/action_plan_some.xml b/sf_plan/wizard/action_plan_some.xml index b659da03..a3d5f2bf 100644 --- a/sf_plan/wizard/action_plan_some.xml +++ b/sf_plan/wizard/action_plan_some.xml @@ -7,6 +7,7 @@
+