Accept Merge Request #1616: (feature/逾期工单批量重新安排 -> develop)
Merge Request: 逾期工单不能批量重新安排的优化需求 Created By: @管欢 Reviewed By: @胡尧 Approved By: @胡尧 Accepted By: @管欢 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1616
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
'wizard/production_wizard_views.xml',
|
||||
'wizard/production_technology_wizard_views.xml',
|
||||
'wizard/production_technology_re_adjust_wizard_views.xml',
|
||||
'wizard/mrp_workorder_batch_replan_wizard_views.xml',
|
||||
'views/mrp_views_menus.xml',
|
||||
'views/agv_scheduling_views.xml',
|
||||
'views/stock_lot_views.xml',
|
||||
@@ -38,6 +39,7 @@
|
||||
'views/sf_maintenance_equipment.xml',
|
||||
'views/res_config_settings_views.xml',
|
||||
'views/sale_order_views.xml',
|
||||
'views/mrp_workorder_batch_replan.xml',
|
||||
],
|
||||
'assets': {
|
||||
|
||||
|
||||
@@ -403,10 +403,31 @@ class MrpProduction(models.Model):
|
||||
if process_parameters:
|
||||
raise UserError(_("【工艺设计】-【参数】为%s的在【产品】中不存在,请先创建", ", ".join(process_parameters)))
|
||||
if production_confirmed:
|
||||
production_count = self.env['mrp.production'].search_count([
|
||||
('origin', '=', self.origin),
|
||||
('product_id', '=', self.product_id.id),
|
||||
('state', '=', 'confirmed')
|
||||
])
|
||||
if production_count > 1:
|
||||
return {
|
||||
'name': _('退回调整'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'form',
|
||||
'views': [(self.env.ref(
|
||||
'sf_manufacturing.sf_production_technology_re_adjust_wizard_form_view').id,
|
||||
'form')],
|
||||
'res_model': 'sf.production.technology.re_adjust.wizard',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_production_id': self.id,
|
||||
'default_origin': self.origin,
|
||||
}}
|
||||
else:
|
||||
return {
|
||||
'name': _('退回调整'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(self.env.ref(
|
||||
'sf_manufacturing.sf_production_technology_re_adjust_wizard_confirm_form_view').id,
|
||||
'form')],
|
||||
'res_model': 'sf.production.technology.re_adjust.wizard',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
@@ -466,10 +487,31 @@ class MrpProduction(models.Model):
|
||||
error_panel.append(design.panel)
|
||||
else:
|
||||
if not error_panel and not process_parameters:
|
||||
production_count = self.env['mrp.production'].search_count([
|
||||
('origin', '=', self.origin),
|
||||
('product_id', '=', self.product_id.id),
|
||||
('state', '=', 'technology_to_confirmed')
|
||||
])
|
||||
if production_count > 1:
|
||||
return {
|
||||
'name': _('工艺确认'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'form',
|
||||
'views': [(self.env.ref(
|
||||
'sf_manufacturing.sf_production_technology_wizard_form_view').id,
|
||||
'form')],
|
||||
'res_model': 'sf.production.technology.wizard',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_production_id': self.id,
|
||||
'default_origin': self.origin,
|
||||
}}
|
||||
else:
|
||||
return {
|
||||
'name': _('工艺确认'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(self.env.ref(
|
||||
'sf_manufacturing.sf_production_technology_wizard_confirm_form_view').id,
|
||||
'form')],
|
||||
'res_model': 'sf.production.technology.wizard',
|
||||
'target': 'new',
|
||||
'context': {
|
||||
@@ -1543,7 +1585,9 @@ class MrpProduction(models.Model):
|
||||
|
||||
def action_view_purchase_orders(self):
|
||||
self.ensure_one()
|
||||
if self.product_id.product_tmpl_id.single_manufacturing == True:
|
||||
if self.is_remanufacture:
|
||||
production = self
|
||||
elif self.product_id.product_tmpl_id.single_manufacturing == True:
|
||||
production = self.env['mrp.production'].search(
|
||||
[('origin', '=', self.origin), ('product_id', '=', self.product_id.id)], limit=1, order='id asc')
|
||||
else:
|
||||
|
||||
@@ -182,3 +182,5 @@ access_sf_manual_product_model_type_routing_sort_group_sf_mrp_user,sf_manual_pro
|
||||
access_sf_manual_product_model_type_routing_sort_manager,sf_manual_product_model_type_routing_sort,model_sf_manual_product_model_type_routing_sort,sf_base.group_sf_mrp_manager,1,1,1,1
|
||||
access_sf_manual_product_model_type_routing_sort_group_plan_dispatch,sf_manual_product_model_type_routing_sort_group_plan_dispatch,model_sf_manual_product_model_type_routing_sort,sf_base.group_plan_dispatch,1,0,0,0
|
||||
access_sf_detection_result_manager,sf_detection_result_manager,model_sf_detection_result,,1,1,1,1
|
||||
|
||||
access_mrp_workorder_batch_replan_wizard_group_plan_dispatch,mrp_workorder_batch_replan_wizard_group_plan_dispatch,model_mrp_workorder_batch_replan_wizard,sf_base.group_plan_dispatch,1,1,1,0
|
||||
|
18
sf_manufacturing/views/mrp_workorder_batch_replan.xml
Normal file
18
sf_manufacturing/views/mrp_workorder_batch_replan.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="mrp_production_workorder_tree_editable_view_inherit" model="ir.ui.view">
|
||||
<field name="name">>mrp.workorder.tree.editable.inherit</field>
|
||||
<field name="model">mrp.workorder</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_workorder_tree_editable_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//tree/field[1]" position="before">
|
||||
<header>
|
||||
<button string="重新安排" name="%(sf_manufacturing.mrp_workorder_batch_replan_wizard)d" type="action"
|
||||
class="treeHeaderBtn"
|
||||
invisible="context.get('workorder_type') not in ('工件装夹中心','1#自动生产线','工件拆卸中心')"/>
|
||||
</header>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -3,3 +3,4 @@ from . import rework_wizard
|
||||
from . import production_wizard
|
||||
from . import production_technology_wizard
|
||||
from . import production_technology_re_adjust_wizard
|
||||
from . import mrp_workorder_batch_replan_wizard
|
||||
|
||||
70
sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard.py
Normal file
70
sf_manufacturing/wizard/mrp_workorder_batch_replan_wizard.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
from odoo import models, api, fields, _
|
||||
|
||||
|
||||
class MrpWorkorderBatchReplanWizard(models.TransientModel):
|
||||
_name = 'mrp.workorder.batch.replan.wizard'
|
||||
_description = '制造订单批量重新安排向导'
|
||||
|
||||
def _get_date_planned_start(self):
|
||||
planned_start_date = datetime.now() + timedelta(hours=2)
|
||||
logging.info('计划开始加工时间: %s', planned_start_date)
|
||||
return planned_start_date
|
||||
|
||||
def _get_default_workorder_count(self):
|
||||
active_ids = self.env.context.get('active_ids', [])
|
||||
return len(active_ids)
|
||||
|
||||
def _get_default_workorder_type(self):
|
||||
active_ids = self.env.context.get('active_ids', [])
|
||||
if active_ids:
|
||||
workorders = self.env['mrp.workorder'].browse(active_ids)
|
||||
if workorders:
|
||||
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)
|
||||
|
||||
workorder_count = fields.Integer(string='工单数量',
|
||||
default=_get_default_workorder_count,
|
||||
readonly=True)
|
||||
|
||||
workorder_id = fields.Many2many('mrp.workorder', string=u'工单')
|
||||
|
||||
def confirm(self):
|
||||
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'
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="mrp_workorder_batch_replan_wizard_form" model="ir.ui.view">
|
||||
<field name="name">mrp.workorder.batch.replan.wizard.form.view</field>
|
||||
<field name="model">mrp.workorder.batch.replan.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group>
|
||||
<field name="workorder_type"/>
|
||||
<field name="workorder_count"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button string="确认" name="confirm" type="object" class="oe_highlight"/>
|
||||
<button string="取消" class="btn-primary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="mrp_workorder_batch_replan_wizard" model="ir.actions.act_window">
|
||||
<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>
|
||||
<field name="view_id" ref="mrp_workorder_batch_replan_wizard_form"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'default_workorder_id': active_ids}</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -21,6 +21,26 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="sf_production_technology_re_adjust_wizard_confirm_form_view">
|
||||
<field name="name">sf.production.technology.re_adjust.wizard.form.view</field>
|
||||
<field name="model">sf.production.technology.re_adjust.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<field name="production_id" invisible="1"/>
|
||||
<field name="origin" invisible="1"/>
|
||||
<div>
|
||||
是否确认退回调整
|
||||
</div>
|
||||
<footer>
|
||||
<button string="确认" name="confirm" type="object" class="oe_highlight"/>
|
||||
<button string="取消" class="btn btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_sf_production_technology_re_adjust_wizard" model="ir.actions.act_window">
|
||||
<field name="name">工艺退回调整</field>
|
||||
<field name="res_model">sf.production.technology.re_adjust.wizard</field>
|
||||
|
||||
@@ -13,7 +13,28 @@
|
||||
对当前制造订单,同一销售订单相同产品所生成的制造订单统一进行工艺调整与确认
|
||||
</div>
|
||||
<footer>
|
||||
<button string="确认" name="confirm" type="object" class="oe_highlight" confirm="是否确认工艺调整"/>
|
||||
<button string="确认" name="confirm" type="object" class="oe_highlight"
|
||||
confirm="是否确认工艺调整"/>
|
||||
<button string="取消" class="btn btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="sf_production_technology_wizard_confirm_form_view">
|
||||
<field name="name">sf.production.technology.wizard.form.view</field>
|
||||
<field name="model">sf.production.technology.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<field name="production_id" invisible="1"/>
|
||||
<field name="origin" invisible="1"/>
|
||||
<div>
|
||||
是否确认工艺调整
|
||||
</div>
|
||||
<footer>
|
||||
<button string="确认" name="confirm" type="object" class="oe_highlight"/>
|
||||
<button string="取消" class="btn btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</sheet>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<t t-if="record.workorder_count.raw_value > 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>
|
||||
|
||||
Reference in New Issue
Block a user