增加排程后各工单时间预估功能

This commit is contained in:
mgw
2023-11-07 10:17:06 +08:00
parent 82ce347ca4
commit 77852900a3
4 changed files with 95 additions and 37 deletions

View File

@@ -11,6 +11,7 @@ class sf_production_plan(models.Model):
_name = 'sf.production.plan'
# _inherit = 'mrp.production'
_description = 'sf_production_plan'
_order = 'create_date desc'
state = fields.Selection([
('draft', '待排程'),
@@ -41,18 +42,12 @@ class sf_production_plan(models.Model):
actual_end_time = fields.Datetime(string='实际结束时间')
shift = fields.Char(string='班次')
# 序号、坯料编号、坯料名称、材质、数量、长度、宽度、厚度、直径、计划开始时间、计划结束时间、状态(已产出与待产出)、操作、创建人、创建时间、客户名称、订单号、行号、长度、宽度、厚度、直径、交货数量、交货日期
# sequence = fields.Integer(string='序号', required=True, copy=False, readonly=True, index=True,
# default=lambda self: self.env['ir.sequence'].sudo().next_by_code('sf.pl.plan'))
sequence = fields.Integer(string='序号', copy=False, readonly=True, index=True)
current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划')
# state = fields.Selection([
# ('未排程', '未排程'), ('已排程', '已排程')], string='State', copy=False, index=True, readonly=True,
# store=True, tracking=True)
@@ -179,16 +174,62 @@ class sf_production_plan(models.Model):
else:
aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
workorder_time = 0
print(aa.workorder_ids)
print(type(aa.workorder_ids))
if aa.workorder_ids:
for item in aa.workorder_ids:
current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)])
workorder_time += current_workorder.duration_expected
print(workorder_time)
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)
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'
aa.schedule_state = '已排'
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)