import collections


def fetch_for_subscriptions(weboob_proxy, method, subscriptions, backend):
    """
    Fetch related items for a given list of subscriptions.

    :param weboob_proxy: An instance of ``WeboobProxy`` class.
    :param method: The method to call on the bakend to fetch items.
    :param subscriptions: A list of Weboob ``Subscription`` objects to fetch
        items from.
    :param backend: A valid built backend to use.
    :return The list of fetched items (Weboob objects).
    """
    items = collections.defaultdict(list)
    for subscription in subscriptions:
        for item in getattr(backend, method)(subscription.id.rsplit('@', 1)[0]):
            # Fetch all items for this subscriptions and ensure they have a
            # fully qualified id
            item.id = weboob_proxy._ensure_fully_qualified_id(
                item.id, backend
            )
            items[subscription.id].append(item)
    return items