优化取消接单功能
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
|
|
||||||
|
|
||||||
class SFSaleOrderCancelWizard(models.TransientModel):
|
class SFSaleOrderCancelWizard(models.TransientModel):
|
||||||
_name = 'sf.sale.order.cancel.wizard'
|
_name = 'sf.sale.order.cancel.wizard'
|
||||||
_description = '销售订单取消向导'
|
_description = '销售订单取消向导'
|
||||||
|
|
||||||
order_id = fields.Many2one('sale.order', string='销售订单')
|
order_id = fields.Many2one('sale.order', string='销售订单')
|
||||||
related_docs = fields.One2many('sf.sale.order.cancel.line', 'wizard_id', string='相关单据')
|
related_docs = fields.One2many('sf.sale.order.cancel.line', 'wizard_id', string='相关单据')
|
||||||
|
has_movement = fields.Boolean(compute='_compute_has_movement', string='是否有异动')
|
||||||
|
display_message = fields.Char(compute='_compute_display_message', string='显示消息')
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields_list):
|
def default_get(self, fields_list):
|
||||||
@@ -19,9 +22,28 @@ class SFSaleOrderCancelWizard(models.TransientModel):
|
|||||||
defaults['related_docs'] = wizard.related_docs.ids
|
defaults['related_docs'] = wizard.related_docs.ids
|
||||||
return defaults
|
return defaults
|
||||||
|
|
||||||
|
@api.depends('related_docs.cancel_reason')
|
||||||
|
def _compute_has_movement(self):
|
||||||
|
for wizard in self:
|
||||||
|
wizard.has_movement = any(doc.cancel_reason for doc in wizard.related_docs)
|
||||||
|
|
||||||
|
@api.depends('has_movement')
|
||||||
|
def _compute_display_message(self):
|
||||||
|
for wizard in self:
|
||||||
|
wizard.display_message = '部分或全部下游单据存在异动,无法取消,详情如下:' if wizard.has_movement else '确认所有下游单据全部取消?'
|
||||||
|
|
||||||
def action_confirm_cancel(self):
|
def action_confirm_cancel(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
return self.order_id.action_cancel()
|
# 取消销售订单
|
||||||
|
result = self.order_id.action_cancel()
|
||||||
|
# 取消关联的制造订单
|
||||||
|
manufacturing_orders = self.env['mrp.production'].search([
|
||||||
|
('origin', '=', self.order_id.name)
|
||||||
|
])
|
||||||
|
if manufacturing_orders:
|
||||||
|
manufacturing_orders.action_cancel()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
class SFSaleOrderCancelLine(models.TransientModel):
|
class SFSaleOrderCancelLine(models.TransientModel):
|
||||||
_name = 'sf.sale.order.cancel.line'
|
_name = 'sf.sale.order.cancel.line'
|
||||||
@@ -73,7 +95,8 @@ class SFSaleOrderCancelLine(models.TransientModel):
|
|||||||
'operation_type': '调拨',
|
'operation_type': '调拨',
|
||||||
'doc_number': picking.name,
|
'doc_number': picking.name,
|
||||||
'product_name': picking.product_id.name if picking.product_id else '',
|
'product_name': picking.product_id.name if picking.product_id else '',
|
||||||
'quantity': picking.product_qty if hasattr(picking, 'product_qty') else 0,
|
# 'quantity': picking.product_qty if hasattr(picking, 'product_qty') else 0,
|
||||||
|
'quantity': sum(picking.move_ids.mapped('product_uom_qty') or [0]),
|
||||||
'doc_state': picking.state,
|
'doc_state': picking.state,
|
||||||
'cancel_reason': '已有异动' if picking.state not in ['draft', 'cancel', 'waiting'] else ''
|
'cancel_reason': '已有异动' if picking.state not in ['draft', 'cancel', 'waiting'] else ''
|
||||||
}
|
}
|
||||||
@@ -113,6 +136,7 @@ class SFSaleOrderCancelLine(models.TransientModel):
|
|||||||
'category': '制造',
|
'category': '制造',
|
||||||
'doc_name': '制造订单',
|
'doc_name': '制造订单',
|
||||||
'doc_number': mo.name,
|
'doc_number': mo.name,
|
||||||
|
'operation_type': '制造',
|
||||||
'product_name': mo.product_id.name,
|
'product_name': mo.product_id.name,
|
||||||
'quantity': mo.product_qty,
|
'quantity': mo.product_qty,
|
||||||
'doc_state': mo.state,
|
'doc_state': mo.state,
|
||||||
@@ -153,7 +177,7 @@ class SFSaleOrderCancelLine(models.TransientModel):
|
|||||||
'doc_number': picking.name,
|
'doc_number': picking.name,
|
||||||
'operation_type': picking.picking_type_id.name,
|
'operation_type': picking.picking_type_id.name,
|
||||||
'product_name': picking.product_id.name if picking.product_id else '',
|
'product_name': picking.product_id.name if picking.product_id else '',
|
||||||
'quantity': picking.product_qty if hasattr(picking, 'product_qty') else 0,
|
'quantity': sum(picking.move_ids.mapped('product_uom_qty') or [0]),
|
||||||
'doc_state': picking.state,
|
'doc_state': picking.state,
|
||||||
'cancel_reason': '已有异动' if picking.state not in ['draft', 'cancel', 'waiting'] else ''
|
'cancel_reason': '已有异动' if picking.state not in ['draft', 'cancel', 'waiting'] else ''
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,10 @@
|
|||||||
<form string="下游单据清单">
|
<form string="下游单据清单">
|
||||||
<group>
|
<group>
|
||||||
<field name="order_id" invisible="1"/>
|
<field name="order_id" invisible="1"/>
|
||||||
|
<field name="has_movement" invisible="1"/>
|
||||||
</group>
|
</group>
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
<span>弹窗描述:</span><br/>
|
<field name="display_message" readonly="1" nolabel="1"/>
|
||||||
<span>1) 若无异动,描述为: 确认所有下游单据全部取消?</span><br/>
|
|
||||||
<span>2) 若有异动,描述为: 部分或全部下游单据存在异动,无法取消,详情如下:</span>
|
|
||||||
</div>
|
</div>
|
||||||
<field name="related_docs">
|
<field name="related_docs">
|
||||||
<tree string="下游单据" create="false" edit="false" delete="false">
|
<tree string="下游单据" create="false" edit="false" delete="false">
|
||||||
@@ -31,7 +30,8 @@
|
|||||||
<button name="action_confirm_cancel"
|
<button name="action_confirm_cancel"
|
||||||
string="确认取消"
|
string="确认取消"
|
||||||
type="object"
|
type="object"
|
||||||
class="btn-primary"/>
|
class="btn-primary"
|
||||||
|
attrs="{'invisible': [('has_movement', '=', True)]}"/>
|
||||||
<button string="关闭"
|
<button string="关闭"
|
||||||
class="btn-secondary"
|
class="btn-secondary"
|
||||||
special="cancel"/>
|
special="cancel"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user