解决采购申请创建的采购单取消后导致调拨单不能就绪的问题
This commit is contained in:
@@ -34,9 +34,43 @@ class PurchaseOrder(models.Model):
|
|||||||
将取消的采购订单关联的库存移动撤销
|
将取消的采购订单关联的库存移动撤销
|
||||||
"""
|
"""
|
||||||
move_ids = self.order_line.move_dest_ids.filtered(lambda move: move.state != 'done' and not move.scrapped)
|
move_ids = self.order_line.move_dest_ids.filtered(lambda move: move.state != 'done' and not move.scrapped)
|
||||||
|
move_line_ids = {}
|
||||||
|
move_states = { move_id.id: move_id.state for move_id in move_ids }
|
||||||
|
move_orig_ids = move_ids.move_orig_ids
|
||||||
|
move_dest_ids = move_ids.move_dest_ids
|
||||||
|
for move_line_id in move_ids.move_line_ids:
|
||||||
|
move_line_ids[move_line_id.move_id.id] = move_line_id.copy()
|
||||||
|
move_line_ids[move_line_id.move_id.id].move_id = False
|
||||||
|
move_line_ids[move_line_id.move_id.id].reserved_uom_qty = move_line_id.reserved_uom_qty
|
||||||
|
|
||||||
res =super(PurchaseOrder, self).button_cancel()
|
res =super(PurchaseOrder, self).button_cancel()
|
||||||
|
|
||||||
if move_ids.mapped('created_purchase_request_line_id'):
|
if move_ids.mapped('created_purchase_request_line_id'):
|
||||||
|
# 如果采购订单关联了采购申请,则将库存移动的状态设置为等待
|
||||||
move_ids.write({'state': 'waiting', 'is_done': False})
|
move_ids.write({'state': 'waiting', 'is_done': False})
|
||||||
|
move_ids.write({'move_orig_ids': [(4, move_orig_id.id, 0) for move_orig_id in move_orig_ids]})
|
||||||
|
move_ids.write({'move_dest_ids': [(4, move_dest_id.id, 0) for move_dest_id in move_dest_ids]})
|
||||||
|
for move_id in move_ids:
|
||||||
|
move_id.write({'procure_method': 'make_to_order', 'state': move_states[move_id.id]})
|
||||||
|
move_id.write({'move_line_ids': [(4, move_line_ids[move_id.id].id, 0)]})
|
||||||
|
move_id._action_assign()
|
||||||
|
origin_move_id = move_id
|
||||||
|
# 追回原mto的库存移动
|
||||||
|
link_move_ids = self.env['stock.move'].search([
|
||||||
|
('origin','=',move_id.origin),
|
||||||
|
('procure_method','=','make_to_stock'),
|
||||||
|
('product_id','=',move_id.product_id.id),
|
||||||
|
('id', '!=', move_id.id)
|
||||||
|
])
|
||||||
|
while link_move_ids:
|
||||||
|
link_move_id = link_move_ids.filtered(lambda move: move.location_id == origin_move_id.location_dest_id)
|
||||||
|
link_move_id.write({
|
||||||
|
'move_orig_ids': [(4, origin_move_id.id, 0)] if origin_move_id != link_move_id else [],
|
||||||
|
'procure_method': 'make_to_order',
|
||||||
|
})
|
||||||
|
origin_move_id = link_move_id
|
||||||
|
link_move_ids -= link_move_id
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
|||||||
Reference in New Issue
Block a user