基本的批量排程已实现

This commit is contained in:
mgw
2024-01-04 08:51:25 +08:00
parent b9bb528db0
commit ce58e989dd
2 changed files with 39 additions and 38 deletions

View File

@@ -153,44 +153,45 @@ class sf_production_plan(models.Model):
"""
排程方法
"""
if not self.production_line_id:
raise ValidationError("未选择生产线")
else:
workorder_id_list = self.production_id.workorder_ids.ids
if self.production_id.workorder_ids:
for item in self.production_id.workorder_ids:
if item.name == 'CNC加工':
item.date_planned_finished = datetime.now() + timedelta(days=100)
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
self.calculate_plan_time_before(item, workorder_id_list)
self.calculate_plan_time_after(item, workorder_id_list)
self.date_planned_start, self.date_planned_finished = \
item.date_planned_start, item.date_planned_finished
self.state = 'done'
self.production_id.schedule_state = '已排'
mrp_production_ids = self.production_id._get_children().ids
print('mrp_production_ids', mrp_production_ids)
for i in mrp_production_ids:
self.env['mrp.production'].browse(i).schedule_state = '已排'
# self.production_id.date_planned_start = self.date_planned_start
# self.production_id.date_planned_finished = self.date_planned_finished
for record in self:
if not record.production_line_id:
raise ValidationError("未选择生产线")
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', # 要跳转的模型名称
# 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
'view_mode': 'gantt,tree,form',
'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
}
workorder_id_list = record.production_id.workorder_ids.ids
if record.production_id.workorder_ids:
for item in record.production_id.workorder_ids:
if item.name == 'CNC加工':
item.date_planned_finished = datetime.now() + timedelta(days=100)
item.date_planned_start = record.date_planned_start
item.date_planned_finished = item.date_planned_start + timedelta(
minutes=record.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', 'CNC加工')]).time_cycle)
item.duration_expected = record.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', 'CNC加工')]).time_cycle
record.calculate_plan_time_before(item, workorder_id_list)
record.calculate_plan_time_after(item, workorder_id_list)
record.date_planned_start, record.date_planned_finished = \
item.date_planned_start, item.date_planned_finished
record.state = 'done'
record.production_id.schedule_state = '已排'
mrp_production_ids = record.production_id._get_children().ids
print('mrp_production_ids', mrp_production_ids)
for i in mrp_production_ids:
record.env['mrp.production'].browse(i).schedule_state = '已排'
# record.production_id.date_planned_start = record.date_planned_start
# record.production_id.date_planned_finished = record.date_planned_finished
else:
raise ValidationError("未找到工单")
# record.date_planned_finished = record.date_planned_start + timedelta(days=3)
# record.state = 'done'
return {
'name': '排程甘特图',
'type': 'ir.actions.act_window',
'res_model': 'sf.production.plan', # 要跳转的模型名称
# 要显示的视图类型,可以是'form', 'tree', 'kanban', 'graph', 'calendar', 'pivot'等
'view_mode': 'gantt,tree,form',
'target': 'current', # 跳转的目标窗口,可以是'current'或'new'
}
def calculate_plan_time_before(self, item, workorder_id_list):
"""

View File

@@ -5,7 +5,7 @@
<field name="name">sf.production.plan.tree</field>
<field name="model">sf.production.plan</field>
<field name="arch" type="xml">
<tree string="订单计划">
<tree string="订单计划" editable="bottom">
<header>
<button name="do_production_schedule" type="object" string="批量排程"/>
</header>