逾期工单不能批量重新安排的优化需求

This commit is contained in:
guanhuan
2024-12-13 16:24:25 +08:00
parent 01fa7bbe87
commit b551777d49
4 changed files with 39 additions and 11 deletions

View File

@@ -8,7 +8,8 @@
<xpath expr="//tree/field[1]" position="before">
<header>
<button string="重新安排" name="%(sf_manufacturing.mrp_workorder_batch_replan_wizard)d" type="action"
class="treeHeaderBtn"/>
class="treeHeaderBtn"
invisible="context.get('workorder_type') not in ('工件装夹中心','1#自动生产线','工件拆卸中心')"/>
</header>
</xpath>
</field>

View File

@@ -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'
}
},
}

View File

@@ -7,7 +7,6 @@
<form>
<group>
<field name="workorder_type"/>
<field name="date_planned_start"/>
<field name="workorder_count"/>
</group>
<footer>
@@ -20,7 +19,7 @@
<record id="mrp_workorder_batch_replan_wizard" model="ir.actions.act_window">
<field name="name">重新安排</field>
<field name="name">重新安排工单</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">mrp.workorder.batch.replan.wizard</field>
<field name="view_mode">form</field>

View File

@@ -23,7 +23,7 @@
<t t-if="record.workorder_count.raw_value &gt; 0">
<button class="btn btn-primary" name="action_work_order" type="object"
attrs="{'invisible': [('name', '=', '功能刀具组装中心')]}"
context="{'search_default_ready': 1, 'search_default_progress': 1}">
context="{'search_default_ready': 1, 'search_default_progress': 1, 'workorder_type': name}">
<span>工单</span>
</button>
</t>