Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter or get multiple invoices #267

Open
kiranpvsr opened this issue Jul 9, 2019 · 2 comments
Open

Filter or get multiple invoices #267

kiranpvsr opened this issue Jul 9, 2019 · 2 comments

Comments

@kiranpvsr
Copy link

How do you retrieve multiple invoices using InvoiceID ?

I expected the below syntax to work but obviously it doesn't.

invoices = xero.invoices.get('f3ecf55f-b7b0-47d2-a0f3-97df84890af2', 'f3ecf55f-b7b0-47d2-a0f3-95af84890af2')

@IdlePhysicist
Copy link

Hi there,

I don't think the get method actually accepts anything other than a string currently. A good future feature would be to allow it to accept a list object (containing InvoiceIDs).

What you could do to fetch multiple invoices by InvoiceID is something like this:

def getInvoiceByID(listOfInvoiceIDs):
    invoices = []
    for invoice in listOfInvoiceIDs:
        invoices.extend(self.xero.invoices.get(invoice))
    return invoices

This comes with a warning though! Xero is quite strict on rate limiting and using individual requests to fetch individual invoices is quite inefficient. It's OK for two or three, but if you're needing to retrieve more, or several times a day you should investigate other ways of retrieving your invoices.

I have also attached the code that I use to get invoices which match a query parameter.
So the raw_query variable could be:

  • 'Date >= DateTime(2019,07,09) && Date >= DateTime(2019,07,12)' For retrieving all the invoices between 2019/07/09 and 2019/07/12.
  • 'InvoiceNumber="INV-000001"'
  • 'InvoiceNumber>="INV-0001" && InvoiceNumber<="INV-0005' - For fetching a range of invoices, NB I haven't tried this one but it might work.
def getInvoices(self, raw_query):
    """
        This method pulls the draft invoices from Xero. Because of the quantity it
        paginated the results.

        Returns: list of invoices OR False
    """
    try:
        invoices, i = [], 1
        resp = xero.invoices.filter(raw=raw_query, order='Date DESC',
            type='ACCREC', page=i, status='DRAFT')
        while resp != []:
            invoices.extend(resp); i += 1
            resp = xero.invoices.filter(raw=raw_query, order='Date DESC',
                type='ACCREC', page=i, status='DRAFT')
        log.info('Retrieved draft invoices.')
        return invoices
    except Exception as e:
        log.error('Error fetching invoices {}'.format(e))
        return False

I hope this was helpful in some way.

@kiranpvsr
Copy link
Author

Thank you for that suggestion IdlePhysicist. My list of invoices will be random. It basically queries Payments made on a certain date. From those Payments, I will pull the list of invoices to find out if they are fully paid. As you can see, the list of invoices will not follow any order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants