基本的批量排程已实现

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,36 +153,37 @@ class sf_production_plan(models.Model):
""" """
排程方法 排程方法
""" """
if not self.production_line_id: for record in self:
if not record.production_line_id:
raise ValidationError("未选择生产线") raise ValidationError("未选择生产线")
else: else:
workorder_id_list = self.production_id.workorder_ids.ids workorder_id_list = record.production_id.workorder_ids.ids
if self.production_id.workorder_ids: if record.production_id.workorder_ids:
for item in self.production_id.workorder_ids: for item in record.production_id.workorder_ids:
if item.name == 'CNC加工': if item.name == 'CNC加工':
item.date_planned_finished = datetime.now() + timedelta(days=100) item.date_planned_finished = datetime.now() + timedelta(days=100)
item.date_planned_start = self.date_planned_start item.date_planned_start = record.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=record.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 = record.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', 'CNC加工')]).time_cycle [('name', '=', 'CNC加工')]).time_cycle
self.calculate_plan_time_before(item, workorder_id_list) record.calculate_plan_time_before(item, workorder_id_list)
self.calculate_plan_time_after(item, workorder_id_list) record.calculate_plan_time_after(item, workorder_id_list)
self.date_planned_start, self.date_planned_finished = \ record.date_planned_start, record.date_planned_finished = \
item.date_planned_start, item.date_planned_finished item.date_planned_start, item.date_planned_finished
self.state = 'done' record.state = 'done'
self.production_id.schedule_state = '已排' record.production_id.schedule_state = '已排'
mrp_production_ids = self.production_id._get_children().ids mrp_production_ids = record.production_id._get_children().ids
print('mrp_production_ids', mrp_production_ids) print('mrp_production_ids', mrp_production_ids)
for i in mrp_production_ids: for i in mrp_production_ids:
self.env['mrp.production'].browse(i).schedule_state = '已排' record.env['mrp.production'].browse(i).schedule_state = '已排'
# self.production_id.date_planned_start = self.date_planned_start # record.production_id.date_planned_start = record.date_planned_start
# self.production_id.date_planned_finished = self.date_planned_finished # record.production_id.date_planned_finished = record.date_planned_finished
else: else:
raise ValidationError("未找到工单") raise ValidationError("未找到工单")
# self.date_planned_finished = self.date_planned_start + timedelta(days=3) # record.date_planned_finished = record.date_planned_start + timedelta(days=3)
# self.state = 'done' # record.state = 'done'
return { return {
'name': '排程甘特图', 'name': '排程甘特图',
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',

View File

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