From d1a71e1a05eaa9a8636e291db9c6447a89c845f3 Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Thu, 27 Feb 2025 10:58:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8D=95=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/wizard/sale_order_cancel.py | 106 ++++++++++++++++--- 1 file changed, 90 insertions(+), 16 deletions(-) diff --git a/sf_manufacturing/wizard/sale_order_cancel.py b/sf_manufacturing/wizard/sale_order_cancel.py index 792947bf..98347a2e 100644 --- a/sf_manufacturing/wizard/sale_order_cancel.py +++ b/sf_manufacturing/wizard/sale_order_cancel.py @@ -209,6 +209,31 @@ class SFSaleOrderCancelLine(models.TransientModel): lines.append(self.create(vals)) sequence += 1 + # 成品质检单 + fin_quality_checks = self.env['quality.check'].search([ + ('picking_id', '=', picking.id) + ]) + if fin_quality_checks: + b1 = 0 + for fin_qc in fin_quality_checks: + b1 += 1 + vals = { + 'wizard_id': wizard_id, + 'sequence': sequence, + 'category': '制造', + 'doc_name': '质检单', + 'operation_type': '', + 'doc_number': fin_qc.name, + 'line_number': b1, + 'product_name': f'[{fin_qc.product_id.default_code}] {fin_qc.product_id.name}', + 'quantity': 1, + 'doc_state': map_dict.get(fin_qc.quality_state, fin_qc.quality_state), + 'cancel_reason': '已有异动' if fin_qc.quality_state not in ['none', 'cancel', 'waiting'] else '' + } + lines.append(self.create(vals)) + + + # 检查销售订单直接关联的采购单 purchase_orders = self.env['purchase.order'].search([ ('origin', '=', order.name) @@ -216,22 +241,71 @@ class SFSaleOrderCancelLine(models.TransientModel): 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_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), - 'cancel_reason': '已有异动' if po.state not in ['draft', 'cancel'] else '' - } - lines.append(self.create(vals)) - sequence += 1 + for order_line in po.order_line: + c += 1 + vals = { + 'wizard_id': wizard_id, + 'sequence': sequence, + 'category': '采购', + 'doc_name': '询价单', + 'operation_type': '', + 'doc_number': po.name, + 'line_number': c, + 'product_name': f'[{order_line.product_id.default_code}] {order_line.product_id.name}', + 'quantity': order_line.product_qty if order_line else 0, + 'doc_state': map_dict.get(po.state, po.state), + 'cancel_reason': '已有异动' if po.state not in ['draft', 'cancel'] else '' + } + lines.append(self.create(vals)) + sequence += 1 + + # 客供料的入库单 + for pod in purchase_orders: + pkds = self.env['stock.picking'].search([ + ('origin', '=', pod.name) + ]) + if pkds: + for pkd in pkds: + x3 = 0 + for move in pkd.move_ids: + x3 += 1 + vals = { + 'wizard_id': wizard_id, + 'sequence': sequence, + 'category': '客供料收货', + 'doc_name': '库存移动', + 'doc_number': pkd.name, + 'line_number': x3, + 'operation_type': pkd.picking_type_id.name, + 'product_name': move.product_id.name if move.product_id else '', + 'quantity': move.product_uom_qty, + 'doc_state': map_dict.get(pkd.state, pkd.state), + 'cancel_reason': '已有异动' if pkd.state not in ['draft', 'cancel'] else '' + } + lines.append(self.create(vals)) + + # + for child_pkd in self.env['stock.picking'].search([ + ('origin', '=', pkd.name) + ]): + x4 = 0 + for child_move in child_pkd.move_ids: + x4 += 1 + vals = { + 'wizard_id': wizard_id, + 'sequence': sequence, + 'category': '客供料调拨', + 'doc_name': '库存移动', + 'doc_number': child_pkd.name, + 'line_number': x4, + 'operation_type': child_pkd.picking_type_id.name, + 'product_name': child_move.product_id.name if child_move.product_id else '', + 'quantity': child_move.product_uom_qty, + 'doc_state': map_dict.get(child_pkd.state, child_pkd.state), + 'cancel_reason': '已有异动' if child_pkd.state not in ['draft', + 'cancel'] else '' + } + lines.append(self.create(vals)) # 检查制造订单 manufacturing_orders = self.env['mrp.production'].search([