diff --git a/sf_manufacturing/views/mrp_workorder_batch_replan.xml b/sf_manufacturing/views/mrp_workorder_batch_replan.xml
index a09b1a0e..972d77c7 100644
--- a/sf_manufacturing/views/mrp_workorder_batch_replan.xml
+++ b/sf_manufacturing/views/mrp_workorder_batch_replan.xml
@@ -8,7 +8,8 @@
+ class="treeHeaderBtn"
+ invisible="context.get('workorder_type') not in ('工件装夹中心','1#自动生产线','工件拆卸中心')"/>
diff --git a/sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard.py b/sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard.py
index f9511040..5f5d5261 100644
--- a/sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard.py
+++ b/sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard.py
@@ -22,15 +22,12 @@ class MrpWorkorderBatchReplanWizard(models.TransientModel):
if active_ids:
workorders = self.env['mrp.workorder'].browse(active_ids)
if workorders:
- unique_types = set(workorders.mapped('type'))
- return '/'.join(sorted(unique_types)) if unique_types else None
+ routing_type = set(workorders.mapped('routing_type'))
+ return '/'.join(sorted(routing_type)) if routing_type else None
return None
workorder_type = fields.Char(string='工单类型', default=_get_default_workorder_type, readonly=True)
- date_planned_start = fields.Datetime(string='计划开始加工时间', index=True, copy=False,
- default=_get_date_planned_start)
-
workorder_count = fields.Integer(string='工单数量',
default=_get_default_workorder_count,
readonly=True)
@@ -38,5 +35,36 @@ class MrpWorkorderBatchReplanWizard(models.TransientModel):
workorder_id = fields.Many2many('mrp.workorder', string=u'工单')
def confirm(self):
- print("ddd")
- pass
+ routing_type = set(self.workorder_id.mapped('routing_type'))
+ if len(routing_type) > 1:
+ raise models.ValidationError("批量重新安排工单类型必须一致。")
+ show_json_popover = self.workorder_id.mapped('show_json_popover')
+ if any(not value for value in show_json_popover):
+ raise models.ValidationError("所选工单必须都为逾期状态")
+ failed_workorders = {}
+ for workorder_info in self.workorder_id:
+ try:
+ workorder_info.action_replan()
+ except Exception as e:
+ reason = str(e)
+ if reason in failed_workorders:
+ failed_workorders[reason].append(
+ workorder_info.production_id.name)
+ else:
+ failed_workorders[reason] = [workorder_info.production_id.name]
+ if failed_workorders:
+ error_messages = "\n".join(
+ [f"制造订单: {', '.join(workorder_names)}, 原因: {reason}" for reason, workorder_names in
+ failed_workorders.items()])
+ return {
+ 'type': 'ir.actions.client',
+ 'tag': 'display_notification',
+ 'params': {
+ 'message': f"以下工单重新安排失败:\n{error_messages}",
+ 'sticky': False,
+ 'color': 'red',
+ 'next': {
+ 'type': 'ir.actions.act_window_close'
+ }
+ },
+ }
diff --git a/sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard_views.xml b/sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard_views.xml
index e004cd6e..37d26ac7 100644
--- a/sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard_views.xml
+++ b/sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard_views.xml
@@ -7,7 +7,6 @@