diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 562c42fa..8470530c 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -292,7 +292,7 @@ class ResMrpWorkOrder(models.Model): surface_technics_parameters_id = fields.Many2one('sf.production.process.parameter', string="表面工艺可选参数") picking_ids = fields.Many2many('stock.picking', string='外协出入库单', - compute='_compute_surface_technics_picking_ids') + compute='_compute_surface_technics_picking_ids', store=True) purchase_id = fields.Many2many('purchase.order', string='外协采购单') surface_technics_picking_count = fields.Integer("外协出入库", compute='_compute_surface_technics_picking_ids') diff --git a/sf_manufacturing/wizard/sale_order_cancel.py b/sf_manufacturing/wizard/sale_order_cancel.py index 0799c805..b9e879d8 100644 --- a/sf_manufacturing/wizard/sale_order_cancel.py +++ b/sf_manufacturing/wizard/sale_order_cancel.py @@ -87,6 +87,12 @@ class SFSaleOrderCancelWizard(models.TransientModel): for child_mo in child_mo_ids: child_mo.action_cancel() + # 取消工单的外协单 + for workorder in mo.workorder_ids: + if workorder.picking_ids: + for pkd in workorder.picking_ids: + pkd.write({'state': 'cancel'}) + # 取消制造订单 mo.action_cancel() @@ -261,22 +267,23 @@ class SFSaleOrderCancelLine(models.TransientModel): if purchase_orders: e = 0 for po in purchase_orders: - e += 1 - vals = { - 'wizard_id': wizard_id, - 'sequence': sequence, - 'category': '制造', - 'doc_name': '询价单', - 'doc_number': po.name, - 'line_number': e, - 'operation_type': '', - '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: + e += 1 + vals = { + 'wizard_id': wizard_id, + 'sequence': sequence, + 'category': '制造', + 'doc_name': '询价单', + 'doc_number': po.name, + 'line_number': e, + 'operation_type': '', + 'product_name': order_line.product_id.name if order_line else '', + '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 # 检查制造订单的领料单 @@ -329,6 +336,27 @@ class SFSaleOrderCancelLine(models.TransientModel): lines.append(self.create(vals)) sequence += 1 + # 工艺外协处理 + if workorder.picking_ids: + for pkd in workorder.picking_ids: + z = 0 + for move in pkd.move_ids: + z += 1 + vals = { + 'wizard_id': wizard_id, + 'sequence': sequence, + 'category': '工艺外协', + 'doc_name': '库存移动', + 'doc_number': f'{mo.name}-{workorder.name}-{pkd.name}', + 'line_number': z, + '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 ['cancel', 'waiting'] else '' + } + lines.append(self.create(vals)) + # 检查制造订单组件的采购单和制造单 for move in mo.move_raw_ids: # # 检查组件的采购单