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 not working for purchase orders #246

Open
tecwiz99 opened this issue Dec 17, 2018 · 3 comments
Open

Filter not working for purchase orders #246

tecwiz99 opened this issue Dec 17, 2018 · 3 comments

Comments

@tecwiz99
Copy link

I'm having trouble filtering purchase orders. I can filter contacts just fine:

xero.purchaseorders.filter(PurchaseOrderNumber='PO-0014')

xero.purchaseorders.filter(Contact_ContactID=contact)
where contact equals: contact = xero.contacts.filter(Name=request.POST['supplier'])[0]['ContactID']

The contact filter is working fine. however the purchase order filter is just returning a list of all purchase orders, no matter what filter I try

@MattHealy
Copy link
Contributor

It turns out you actually don't want to filter the results, you want to get a single record. The URI for this request changes from

https://api.xero.com/api.xro/2.0/PurchaseOrders?where='PurchaseOrderNumber=PO-0014'

to:

https://api.xero.com/api.xro/2.0/PurchaseOrders/PO-0014

Yes, this endpoint works for both PurchaseOrderNumber and PurchaseOrderID values.

So your code should simply look like:

xero.purchaseorders.get('PO-0014')

@tecwiz99
Copy link
Author

Hey Matt,

Thanks for the quick reply. Those were just one of the examples I'm using. I'll update the code for that one. But that was just one of the two examples given. The second one should return a list of POs right?

xero.purchaseorders.filter(Contact_ContactID=contact)

The following isn't working either:
xero.purchaseorders.filter(Contact_ContactID=contact, Status='AUTHORISED')

Neither is this one:
xero.purchaseorders.filter(Status='AUTHORISED')

They all just return a list of all of my purchase orders.

Thank you for any help you can provide.

@jarekwg
Copy link
Contributor

jarekwg commented Mar 27, 2020

Looks like Xero implements filtering completely differently for POs than it does for, say, Invoices.

POs:
image
ie. api.xero.com/api.xro/2.0/PurchaseOrders?Status=DRAFT

Invoices:
image
ie. api.xero.com/api.xro/2.0/Invoices?Statuses==AUTHORISED
or api.xero.com/api.xro/2.0/Invoices?where=Status=="AUTHORISED"

Gross! Means we either can't have a single, neat filter builder in this package to cover all endpoints consistently -- or we have to make it incredibly generic. ;/

Quick soln to get it working in this package -- stop wrapping PO filters in that extra where clause.

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

Successfully merging a pull request may close this issue.

3 participants