修改订单排程功能为通用方法,同时增加动态判断计划时间是否与获取cnc程序的时间冲突功能,如果冲突,时间自动延后1h;优化gantt显示
This commit is contained in:
@@ -95,7 +95,7 @@ class ResMrpBomMo(models.Model):
|
|||||||
limit=1,
|
limit=1,
|
||||||
order='volume desc'
|
order='volume desc'
|
||||||
)
|
)
|
||||||
logging.info('get_bom-vals:%s' % embryo_has)
|
# logging.info('get_bom-vals:%s' % embryo_has)
|
||||||
if embryo_has:
|
if embryo_has:
|
||||||
rate_of_waste = ((embryo_has.volume - product.model_volume) % embryo_has.volume) * 100
|
rate_of_waste = ((embryo_has.volume - product.model_volume) % embryo_has.volume) * 100
|
||||||
if rate_of_waste <= 20:
|
if rate_of_waste <= 20:
|
||||||
|
|||||||
@@ -162,6 +162,86 @@ class sf_production_plan(models.Model):
|
|||||||
# delivery_date = fields.Datetime(string='交货日期', related='plan_end_time', readonly=False, store=True)
|
# delivery_date = fields.Datetime(string='交货日期', related='plan_end_time', readonly=False, store=True)
|
||||||
|
|
||||||
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
|
# 当不设置计划结束时间时,增加计算计划结束时间的方法,根据采购周期加缓冲期两个值来算就可以了
|
||||||
|
# def do_production_schedule(self):
|
||||||
|
# """
|
||||||
|
# 排程方法
|
||||||
|
# """
|
||||||
|
# if not self.production_line_id:
|
||||||
|
# raise ValidationError("未选择生产线")
|
||||||
|
# else:
|
||||||
|
# aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
|
||||||
|
# workorder_time = 0
|
||||||
|
# workorder_id_list = self.production_id.workorder_ids.ids
|
||||||
|
# print(workorder_id_list)
|
||||||
|
# print(type(self.production_id.workorder_ids))
|
||||||
|
# if self.production_id.workorder_ids:
|
||||||
|
# for item in self.production_id.workorder_ids:
|
||||||
|
# if item.name == 'CNC加工':
|
||||||
|
# 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
|
||||||
|
# # print(item.id)
|
||||||
|
# sequence = workorder_id_list.index(item.id) - 1
|
||||||
|
# # print('sequence', sequence)
|
||||||
|
# # print('total', len(workorder_id_list))
|
||||||
|
# # 计算CNC加工之前工单的开始结束时间
|
||||||
|
# for i in range(sequence):
|
||||||
|
# current_workorder_id = (item.id - (i + 1))
|
||||||
|
# current_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||||
|
# [('id', '=', current_workorder_id)])
|
||||||
|
# old_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||||
|
# [('id', '=', (current_workorder_id + 1))])
|
||||||
|
# work_order = self.env['mrp.workorder'].sudo().search(
|
||||||
|
# [('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
|
||||||
|
# work_order.date_planned_finished = old_workorder_obj.date_planned_start
|
||||||
|
# work_order.date_planned_start = old_workorder_obj.date_planned_start - timedelta(
|
||||||
|
# minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
|
# [('name', '=', current_workorder_obj.name)]).time_cycle)
|
||||||
|
# work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
|
# [('name', '=', current_workorder_obj.name)]).time_cycle
|
||||||
|
# # 计算CNC加工之后工单的开始结束时间
|
||||||
|
# for j in range(len(workorder_id_list) - sequence - 2):
|
||||||
|
# current_workorder_id = (item.id + (j + 1))
|
||||||
|
# current_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||||
|
# [('id', '=', current_workorder_id)])
|
||||||
|
# old_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||||
|
# [('id', '=', (current_workorder_id - 1))])
|
||||||
|
# work_order = self.env['mrp.workorder'].sudo().search(
|
||||||
|
# [('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
|
||||||
|
# try:
|
||||||
|
# work_order.date_planned_start = old_workorder_obj.date_planned_finished
|
||||||
|
# print('work_order.data_start', work_order.date_planned_start)
|
||||||
|
# work_order.date_planned_finished = old_workorder_obj.date_planned_finished + timedelta(
|
||||||
|
# minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
|
# [('name', '=', current_workorder_obj.name)]).time_cycle)
|
||||||
|
# work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
|
# [('name', '=', current_workorder_obj.name)]).time_cycle
|
||||||
|
# except ValueError as e:
|
||||||
|
# print('时间设置失败,请检查是否为工序分配工作中心,%s' % e)
|
||||||
|
#
|
||||||
|
# current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)])
|
||||||
|
# workorder_time += current_workorder.duration_expected
|
||||||
|
# print('workorder_time', workorder_time)
|
||||||
|
# self.date_planned_finished = self.date_planned_start + timedelta(minutes=workorder_time)
|
||||||
|
# self.state = 'done'
|
||||||
|
# self.production_id.schedule_state = '已排'
|
||||||
|
# # self.production_id.date_planned_start = self.date_planned_start
|
||||||
|
# # self.production_id.date_planned_finished = self.date_planned_finished
|
||||||
|
# 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', # 要跳转的模型名称
|
||||||
|
# 'view_mode': 'gantt,tree,form', # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
|
||||||
|
# 'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
|
||||||
|
# }
|
||||||
|
|
||||||
def do_production_schedule(self):
|
def do_production_schedule(self):
|
||||||
"""
|
"""
|
||||||
排程方法
|
排程方法
|
||||||
@@ -169,60 +249,20 @@ class sf_production_plan(models.Model):
|
|||||||
if not self.production_line_id:
|
if not self.production_line_id:
|
||||||
raise ValidationError("未选择生产线")
|
raise ValidationError("未选择生产线")
|
||||||
else:
|
else:
|
||||||
aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
|
|
||||||
workorder_time = 0
|
|
||||||
workorder_id_list = self.production_id.workorder_ids.ids
|
workorder_id_list = self.production_id.workorder_ids.ids
|
||||||
print(workorder_id_list)
|
|
||||||
print(type(self.production_id.workorder_ids))
|
|
||||||
if self.production_id.workorder_ids:
|
if self.production_id.workorder_ids:
|
||||||
for item in self.production_id.workorder_ids:
|
for item in self.production_id.workorder_ids:
|
||||||
if item.name == 'CNC加工':
|
if item.name == 'CNC加工':
|
||||||
|
item.date_planned_finished = datetime.now() + timedelta(days=100)
|
||||||
item.date_planned_start = self.date_planned_start
|
item.date_planned_start = self.date_planned_start
|
||||||
item.date_planned_finished = item.date_planned_start + timedelta(
|
item.date_planned_finished = item.date_planned_start + timedelta(
|
||||||
minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
[('name', '=', 'CNC加工')]).time_cycle)
|
[('name', '=', 'CNC加工')]).time_cycle)
|
||||||
item.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
item.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
[('name', '=', 'CNC加工')]).time_cycle
|
[('name', '=', 'CNC加工')]).time_cycle
|
||||||
# print(item.id)
|
self.calculate_plan_time_before(item, workorder_id_list)
|
||||||
sequence = workorder_id_list.index(item.id) - 1
|
self.calculate_plan_time_after(item, workorder_id_list)
|
||||||
# print('sequence', sequence)
|
self.date_planned_start, self.date_planned_finished = item.date_planned_start, item.date_planned_finished
|
||||||
# print('total', len(workorder_id_list))
|
|
||||||
# 计算CNC加工之前工单的开始结束时间
|
|
||||||
for i in range(sequence):
|
|
||||||
current_workorder_id = (item.id - (i + 1))
|
|
||||||
current_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
|
||||||
[('id', '=', current_workorder_id)])
|
|
||||||
old_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
|
||||||
[('id', '=', (current_workorder_id + 1))])
|
|
||||||
work_order = self.env['mrp.workorder'].sudo().search(
|
|
||||||
[('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
|
|
||||||
work_order.date_planned_finished = old_workorder_obj.date_planned_start
|
|
||||||
work_order.date_planned_start = old_workorder_obj.date_planned_start - timedelta(
|
|
||||||
minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
|
||||||
[('name', '=', current_workorder_obj.name)]).time_cycle)
|
|
||||||
# work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', current_workorder_obj.name)]).time_cycle
|
|
||||||
# 计算CNC加工之后工单的开始结束时间
|
|
||||||
for j in range(len(workorder_id_list) - sequence - 2):
|
|
||||||
current_workorder_id = (item.id + (j + 1))
|
|
||||||
current_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
|
||||||
[('id', '=', current_workorder_id)])
|
|
||||||
old_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
|
||||||
[('id', '=', (current_workorder_id - 1))])
|
|
||||||
work_order = self.env['mrp.workorder'].sudo().search(
|
|
||||||
[('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
|
|
||||||
try:
|
|
||||||
work_order.date_planned_start = old_workorder_obj.date_planned_finished
|
|
||||||
print('work_order.data_start', work_order.date_planned_start)
|
|
||||||
work_order.date_planned_finished = old_workorder_obj.date_planned_finished + timedelta(
|
|
||||||
minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
|
||||||
[('name', '=', current_workorder_obj.name)]).time_cycle)
|
|
||||||
except ValueError as e:
|
|
||||||
print('时间设置失败,请检查是否为工序分配工作中心,%s' % e)
|
|
||||||
|
|
||||||
current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)])
|
|
||||||
workorder_time += current_workorder.duration_expected
|
|
||||||
print('workorder_time', workorder_time)
|
|
||||||
self.date_planned_finished = self.date_planned_start + timedelta(minutes=workorder_time)
|
|
||||||
self.state = 'done'
|
self.state = 'done'
|
||||||
self.production_id.schedule_state = '已排'
|
self.production_id.schedule_state = '已排'
|
||||||
# self.production_id.date_planned_start = self.date_planned_start
|
# self.production_id.date_planned_start = self.date_planned_start
|
||||||
@@ -238,36 +278,62 @@ class sf_production_plan(models.Model):
|
|||||||
'view_mode': 'gantt,tree,form', # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
|
'view_mode': 'gantt,tree,form', # 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
|
||||||
'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
|
'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
|
||||||
}
|
}
|
||||||
# if self.production_line_id:
|
|
||||||
# if self.plan_start_time and self.plan_end_time:
|
def calculate_plan_time_before(self, item, workorder_id_list):
|
||||||
# return None
|
"""
|
||||||
# elif self.plan_start_time and not self.plan_end_time:
|
根据CNC工单的时间去计算之前的其他工单的开始结束时间
|
||||||
# # 如果没有给出计划结束时间,则计划结束时间为计划开始时间+采购周期+缓冲期
|
"""
|
||||||
# # 采购周期
|
sequence = workorder_id_list.index(item.id) - 1
|
||||||
# purchase_cycle = 3
|
# 计算CNC加工之前工单的开始结束时间
|
||||||
# # 缓冲期
|
for i in range(sequence):
|
||||||
# buffer_period = 1
|
current_workorder_id = (item.id - (i + 1))
|
||||||
# # 计划结束时间 = 计划开始时间 + 采购周期 + 缓冲期
|
current_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||||
# self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(
|
[('id', '=', current_workorder_id)])
|
||||||
# days=buffer_period)
|
old_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||||
# self.state = 'produce'
|
[('id', '=', (current_workorder_id + 1))])
|
||||||
# return self.plan_end_time
|
work_order = self.env['mrp.workorder'].sudo().search(
|
||||||
# else:
|
[('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
|
||||||
# return None
|
work_order.date_planned_finished = datetime.now() + timedelta(days=100)
|
||||||
# # 后面要补充计划开始时间的计算方法
|
work_order.date_planned_start = old_workorder_obj.date_planned_start - timedelta(
|
||||||
# # # 坯料预制时间
|
minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
# # # pl_time = 0.5
|
[('name', '=', current_workorder_obj.name)]).time_cycle)
|
||||||
# # # 采购周期
|
work_order.date_planned_finished = old_workorder_obj.date_planned_start
|
||||||
# # purchase_cycle = 3
|
work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
# # # 缓冲期
|
[('name', '=', current_workorder_obj.name)]).time_cycle
|
||||||
# # buffer_period = 1
|
first_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', workorder_id_list[0])])
|
||||||
# # # 计划结束时间 = 计划开始时间 + 坯料预制时间 + 采购周期 + 缓冲期
|
second_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', workorder_id_list[1])])
|
||||||
# # # plan_end_time = plan_start_time + pl_time + purchase_cycle + buffer_period
|
if second_workorder.date_planned_start < first_workorder.date_planned_finished:
|
||||||
# # # 计划结束时间 = 计划开始时间(是一个datatime) + 采购周期(Float) + 缓冲期(Float)
|
item.date_planned_start += timedelta(minutes=60)
|
||||||
# # self.plan_end_time = self.plan_start_time + timedelta(days=purchase_cycle) + timedelta(days=buffer_period)
|
item.date_planned_finished += timedelta(minutes=60)
|
||||||
# # return self.plan_end_time
|
item.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
# else:
|
[('name', '=', 'CNC加工')]).time_cycle
|
||||||
# raise ValidationError('生产线为空!')
|
self.calculate_plan_time_before(item, workorder_id_list)
|
||||||
|
|
||||||
|
def calculate_plan_time_after(self, item, workorder_id_list):
|
||||||
|
"""
|
||||||
|
计算CNC加工之后工单的开始结束时间
|
||||||
|
"""
|
||||||
|
sequence = workorder_id_list.index(item.id) - 1
|
||||||
|
# 计算CNC加工之后工单的开始结束时间
|
||||||
|
for j in range(len(workorder_id_list) - sequence - 2):
|
||||||
|
current_workorder_id = (item.id + (j + 1))
|
||||||
|
current_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||||
|
[('id', '=', current_workorder_id)])
|
||||||
|
old_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||||
|
[('id', '=', (current_workorder_id - 1))])
|
||||||
|
work_order = self.env['mrp.workorder'].sudo().search(
|
||||||
|
[('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
|
||||||
|
try:
|
||||||
|
work_order.date_planned_finished = datetime.now() + timedelta(days=100)
|
||||||
|
work_order.date_planned_start = old_workorder_obj.date_planned_finished
|
||||||
|
print('work_order.data_start', work_order.date_planned_start)
|
||||||
|
work_order.date_planned_finished = old_workorder_obj.date_planned_finished + timedelta(
|
||||||
|
minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
|
[('name', '=', current_workorder_obj.name)]).time_cycle)
|
||||||
|
work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
||||||
|
[('name', '=', current_workorder_obj.name)]).time_cycle
|
||||||
|
except ValueError as e:
|
||||||
|
print('时间设置失败,请检查是否为工序分配工作中心,%s' % e)
|
||||||
|
|
||||||
def cancel_production_schedule(self):
|
def cancel_production_schedule(self):
|
||||||
self.date_planned_finished = False
|
self.date_planned_finished = False
|
||||||
|
|||||||
@@ -77,13 +77,13 @@
|
|||||||
<t t-if="widget.state.scale in formats" t-esc="slot.format(formats[widget.state.scale])"/>
|
<t t-if="widget.state.scale in formats" t-esc="slot.format(formats[widget.state.scale])"/>
|
||||||
<small t-else="">
|
<small t-else="">
|
||||||
<t t-if="slot.format('k') == 24">
|
<t t-if="slot.format('k') == 24">
|
||||||
<div>夜班</div>
|
<div>夜班(00:00-08:00)</div>
|
||||||
</t>
|
</t>
|
||||||
<t t-if="slot.format('k') == 8">
|
<t t-if="slot.format('k') == 8">
|
||||||
<div>早班</div>
|
<div>早班(08:00-16:00)</div>
|
||||||
</t>
|
</t>
|
||||||
<t t-if="slot.format('k') == 16">
|
<t t-if="slot.format('k') == 16">
|
||||||
<div>晚班</div>
|
<div>晚班(16:00-00:00)</div>
|
||||||
</t>
|
</t>
|
||||||
<!-- <b t-esc="slot.format('k')"/> -->
|
<!-- <b t-esc="slot.format('k')"/> -->
|
||||||
<!-- <span class="d-block d-xl-inline-block" t-esc="slot.format('a')"/> -->
|
<!-- <span class="d-block d-xl-inline-block" t-esc="slot.format('a')"/> -->
|
||||||
|
|||||||
Reference in New Issue
Block a user