exactonline/api/invoices.py
def map_foreign2exact_invoice_numbers(self, foreign_invoice_numbers=None):
        """
        Optionally supply a list of foreign (your) invoice numbers.

        Returns a dictionary of your invoice numbers (YourRef) to Exact
        Online invoice numbers.
        """
        # Quick, select all. Not the most nice to the server though.
        if foreign_invoice_numbers is None:
            ret = self.filter(select='InvoiceNumber,YourRef')
            return dict((i['YourRef'], i['InvoiceNumber']) for i in ret)

        # Slower, select what we want to know. More work for us.
        foreign_to_exact_map = {}

        # Do it in batches. If we append 300 InvoiceNumbers at once, we
        # get a 12kB URI. (If the list is empty, we skip the entire
        # forloop and correctly return the empty dict.)
        foreign_invoice_numbers = list(set(foreign_invoice_numbers))  # unique
        for offset in range(0, len(foreign_invoice_numbers), 40):
            batch = foreign_invoice_numbers[offset:(offset + 40)]
            filter_ = ' or '.join(
                'YourRef eq %s' % (self._remote_invoice_number(i),)
                for i in batch)
            assert filter_  # if filter was empty, we'd get all!
            ret = self.filter(filter=filter_, select='InvoiceNumber,YourRef')
            foreign_to_exact_map.update(
                dict((i['YourRef'], i['InvoiceNumber']) for i in ret))

        # Any values we missed?
        for foreign_invoice_number in foreign_invoice_numbers:
            if foreign_invoice_number not in foreign_to_exact_map:
                foreign_to_exact_map[foreign_invoice_number] = None

        return foreign_to_exact_map
def map_foreign2exact_invoice_numbers(self, foreign_invoice_numbers=None):
        """
        Optionally supply a list of foreign (your) invoice numbers.

        Returns a dictionary of your invoice numbers (YourRef) to Exact
        Online invoice numbers.
        """
        # Quick, select all. Not the most nice to the server though.
        if foreign_invoice_numbers is None:
            ret = self.filter(select='InvoiceNumber,YourRef')
            return dict((i['YourRef'], i['InvoiceNumber']) for i in ret)

        # Slower, select what we want to know. More work for us.
        foreign_to_exact_map = {}

        # Do it in batches. If we append 300 InvoiceNumbers at once, we
        # get a 12kB URI. (If the list is empty, we skip the entire
        # forloop and correctly return the empty dict.)
        foreign_invoice_numbers = list(set(foreign_invoice_numbers))  # unique
        for offset in range(0, len(foreign_invoice_numbers), 40):
            batch = foreign_invoice_numbers[offset:(offset + 40)]
            filter_ = ' or '.join(
                'YourRef eq %s' % (self._remote_invoice_number(i),)
                for i in batch)
            assert filter_  # if filter was empty, we'd get all!
            ret = self.filter(filter=filter_, select='InvoiceNumber,YourRef')
            foreign_to_exact_map.update(
                dict((i['YourRef'], i['InvoiceNumber']) for i in ret))

        # Any values we missed?
        for foreign_invoice_number in foreign_invoice_numbers:
            if foreign_invoice_number not in foreign_to_exact_map:
                foreign_to_exact_map[foreign_invoice_number] = None

        return foreign_to_exact_map
Optionally supply a list of foreign (your) invoice numbers.

        Returns a dictionary of your invoice numbers (YourRef) to Exact
        Online invoice numbers.