Link to Purchase Order code if records: # Get the active purchase order from context po_id = env.context.get('default_purchase_order_id') or env.context.get('active_id') if po_id: po = env['purchase.order'].browse(po_id) for record in records: po.link_selected_subcontracting_move(record.id) # Close the wizard window action = {'type': 'ir.actions.act_window_close'} stock.move.link.subcontracting.tree stock.move