diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index 1ef18c4f..c67fd105 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
@@ -732,6 +732,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 d6a9b7a4..8bce60d6 100644
--- a/sf_manufacturing/models/mrp_workorder.py
+++ b/sf_manufacturing/models/mrp_workorder.py
@@ -242,7 +242,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:
@@ -651,29 +651,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,
@@ -697,6 +704,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 @@