修复完善取消订单问题

This commit is contained in:
mgw
2025-02-19 15:14:05 +08:00
parent a4b40bee16
commit 0969967570
4 changed files with 70 additions and 17 deletions

View File

@@ -72,7 +72,7 @@ class StatusChange(models.Model):
logging.info('函数已经执行=============')
# 使用super()来调用原始方法(在本例中为'sale.order'模型的'action_cancel'方法)
res = super(StatusChange, self).action_cancel()
res = super(StatusChange, self.with_context(disable_cancel_warning=True)).action_cancel()
# 原有方法执行后进行额外的操作如调用外部API
logging.info('函数已经执行=============2')

View File

@@ -40,6 +40,12 @@
type="object"
attrs="{'invisible': [('state', 'not in', ['sale', 'processing'])]}"
/>
<button
name="action_show_cancel_wizard"
string="取消清单"
type="object"
attrs="{'invisible': [('state', 'not in', ['cancel'])]}"
/>
</xpath>
</field>
</record>

View File

@@ -25,11 +25,23 @@ class SFSaleOrderCancelWizard(models.TransientModel):
@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)
docs_has_movement = any(doc.cancel_reason for doc in wizard.related_docs)
order_canceled = wizard.order_id.state == 'cancel'
wizard.has_movement = docs_has_movement or order_canceled
@api.depends('has_movement')
@api.depends('has_movement', 'related_docs', 'related_docs.doc_state')
def _compute_display_message(self):
for wizard in self:
# 如果没有相关记录,显示为空
if not wizard.related_docs:
wizard.display_message = '无下游单据'
continue
# 检查是否所有记录都是已取消状态
all_canceled = all(doc.doc_state == '已取消' for doc in wizard.related_docs)
if all_canceled:
wizard.display_message = '取消的下游单据如下:'
else:
wizard.display_message = '部分或全部下游单据存在异动,无法取消,详情如下:' if wizard.has_movement else '确认所有下游单据全部取消?'
def action_confirm_cancel(self):
@@ -110,7 +122,7 @@ class SFSaleOrderCancelLine(models.TransientModel):
'confirmed': '已确认',
'pending': '等待其他工单',
'none': '待处理',
'draft': '',
'draft': '',
'cancel': '已取消',
'pass': '通过的',
'fail': '失败的',
@@ -125,14 +137,17 @@ class SFSaleOrderCancelLine(models.TransientModel):
# 检查销售订单
if order.invoice_ids:
a = 0
for invoice in order.invoice_ids:
a += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '销售',
'doc_name': '销售订单',
'operation_type': '销售',
'operation_type': '',
'doc_number': invoice.name,
'line_number': a,
'product_name': invoice.product_id.name,
'quantity': invoice.quantity,
'doc_state': invoice.state,
@@ -143,7 +158,9 @@ class SFSaleOrderCancelLine(models.TransientModel):
# 检查交货单
if order.picking_ids:
b = 0
for picking in order.picking_ids:
b += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
@@ -151,6 +168,7 @@ class SFSaleOrderCancelLine(models.TransientModel):
'doc_name': '交货单',
'operation_type': '调拨',
'doc_number': picking.name,
'line_number': b,
'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]),
@@ -165,14 +183,17 @@ class SFSaleOrderCancelLine(models.TransientModel):
('origin', '=', order.name)
])
if purchase_orders:
c = 0
for po in purchase_orders:
c += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '采购',
'doc_name': '采购',
'operation_type': '销售采购',
'doc_name': '询价',
'operation_type': po.picking_type_id.name,
'doc_number': po.name,
'line_number': c,
'product_name': po.order_line[0].product_id.name if po.order_line else '',
'quantity': po.order_line[0].product_qty if po.order_line else 0,
'doc_state': map_dict.get(po.state, po.state),
@@ -185,15 +206,18 @@ class SFSaleOrderCancelLine(models.TransientModel):
manufacturing_orders = self.env['mrp.production'].search([
('origin', '=', order.name)
])
d = 0
for mo in manufacturing_orders:
# 添加制造订单本身
d += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '制造订单',
'doc_number': mo.name,
'operation_type': '制造',
'operation_type': '',
'line_number': d,
'product_name': mo.product_id.name,
'quantity': mo.product_qty,
'doc_state': map_dict.get(mo.state, mo.state),
@@ -207,14 +231,17 @@ class SFSaleOrderCancelLine(models.TransientModel):
('origin', '=', mo.name)
])
if purchase_orders:
e = 0
for po in purchase_orders:
e += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '采购',
'doc_name': '询价',
'doc_number': po.name,
'operation_type': '制造采购',
'line_number': e,
'operation_type': po.picking_type_id.name,
'product_name': po.order_line[0].product_id.name if po.order_line else '',
'quantity': po.order_line[0].product_qty if po.order_line else 0,
'doc_state': map_dict.get(po.state, po.state),
@@ -225,13 +252,16 @@ class SFSaleOrderCancelLine(models.TransientModel):
# 检查制造订单的领料单
if mo.picking_ids:
f = 0
for picking in mo.picking_ids:
f += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '领料单',
'doc_name': '库存移动',
'doc_number': picking.name,
'line_number': f,
'operation_type': picking.picking_type_id.name,
'product_name': picking.product_id.name if picking.product_id else '',
'quantity': sum(picking.move_ids.mapped('product_uom_qty') or [0]),
@@ -243,13 +273,16 @@ class SFSaleOrderCancelLine(models.TransientModel):
# 检查制造订单的工单
if mo.workorder_ids:
g = 0
for workorder in mo.workorder_ids:
g += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '工单',
'doc_number': workorder.name,
'line_number': g,
'operation_type': workorder.workcenter_id.name,
'product_name': mo.product_id.name,
'quantity': workorder.qty_production,
@@ -288,14 +321,17 @@ class SFSaleOrderCancelLine(models.TransientModel):
('origin', '=', mo.name),
('product_id', '=', move.product_id.id)
])
h = 0
for comp_mo in component_mos:
h += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '组件制造单',
'operation_type': '组件制造',
'operation_type': '',
'doc_number': comp_mo.name,
'line_number': h,
'product_name': move.product_id.name,
'quantity': comp_mo.product_qty,
'doc_state': map_dict.get(comp_mo.state, comp_mo.state),
@@ -309,14 +345,17 @@ class SFSaleOrderCancelLine(models.TransientModel):
('production_id', '=', mo.id)
])
if quality_checks:
i = 0
for check in quality_checks:
i += 1
vals = {
'wizard_id': wizard_id,
'sequence': sequence,
'category': '制造',
'doc_name': '质检单',
'operation_type': '质检',
'operation_type': '',
'doc_number': check.name,
'line_number': i,
'product_name': check.product_id.name,
'quantity': 1,
'doc_state': map_dict.get(check.quality_state, check.quality_state),
@@ -333,8 +372,9 @@ class SFSaleOrderCancelLine(models.TransientModel):
'sequence': sequence,
'category': '编程',
'doc_name': '编程单',
'operation_type': '编程',
'operation_type': '',
'doc_number': cloud_programming['programming_no'],
'line_number': 1,
'product_name': cloud_programming['production_order_no'],
'quantity': 1,
'doc_state': cloud_programming['programming_state'],
@@ -343,4 +383,11 @@ class SFSaleOrderCancelLine(models.TransientModel):
lines.append(self.create(vals))
sequence += 1
return lines
unique_lines = {}
for line in lines:
doc_number = line.doc_number
if doc_number not in unique_lines:
unique_lines[doc_number] = line
# 返回去重后的记录列表
return list(unique_lines.values())

View File

@@ -14,7 +14,7 @@
</div>
<field name="related_docs">
<tree string="下游单据" create="false" edit="false" delete="false">
<field name="sequence" string="序号"/>
<!-- <field name="sequence" string="序号"/> -->
<field name="category" string="大类"/>
<field name="doc_name" string="单据名称"/>
<field name="operation_type" string="作业类型"/>