xero-php icon indicating copy to clipboard operation
xero-php copied to clipboard

Purchase Order Where Clause not applying

Open matthewhutchings opened this issue 4 years ago • 12 comments

When using the Purchase Order endpoint, setting the where status does not apply to the request.

       $purchaseOrders = $xero->load(PurchaseOrder::class)
            ->where('Status', PurchaseOrder::PURCHASE_ORDER_STATUS_AUTHORISED)
            ->where('PurchaseOrderNumber', 'PO-0002')
            ->execute();

The query still returns invoices outside of the above parameters, including the status

matthewhutchings avatar Aug 19 '20 18:08 matthewhutchings

Can you try this again please? I also had clients with the set parameters not being followed, and some of them said that other products using the Xero API were also returning things they shouldn't have, but it appears to have resolved itself.

Healyhatman avatar Aug 20 '20 01:08 Healyhatman

Just tried again and the same result.

matthewhutchings avatar Aug 20 '20 07:08 matthewhutchings

I'm having the same issue. The following code should only be displaying one result and seems to be displaying all of them:

$purchase_orders = $xero->load(PurchaseOrder::class)
        ->where('Date >= DateTime(2020, 09, 16)')
        ->execute();

Note: I'm using the latest stable release 2.2.1

matthewknill avatar Sep 16 '20 00:09 matthewknill

@matthewknill What happens if you make this request in the API Previewer?

calcinai avatar Sep 16 '20 20:09 calcinai

Sorry for taking quite a while to respond. Yes it seems to be working fine from the API Previewer (from my knowledge at least - I hadn't ever used the API Previewer before).

matthewknill avatar Sep 20 '20 23:09 matthewknill

FYI the Xero API PurchaseOrders endpoint doesn't support a where clause, unlike the Invoices endpoint.

See https://community.xero.com/developer/discussion/14123353

chriswheeler avatar Sep 21 '20 15:09 chriswheeler

@matthewknill this suggests it can't be done via the API, closing for now.

calcinai avatar Sep 21 '20 21:09 calcinai

It is mentioned that DateFrom, DateTo and Status are supported. How can I do this if not using the above (these are in fact all I need)?

matthewknill avatar Sep 21 '20 21:09 matthewknill

@matthewknill OK, maybe it needs to be a parameter rather than a where? i.e. using ->addParameter() to the request

calcinai avatar Sep 21 '20 21:09 calcinai

Hmm seems like ->addParameter() function does not exist in the library... Am I doing it right (obviously would need to add parameter):

/** @var PurchaseOrder[] $purchase_orders */
$purchase_orders = $xero->load(PurchaseOrder::class)
    ->addParameter()
    ->execute();

matthewknill avatar Sep 21 '20 22:09 matthewknill

@matthewknill have a look inside the $xero->load() method, that's how the request is actually constructed.

calcinai avatar Sep 21 '20 22:09 calcinai

Holy moly. Thanks for continuing to look into this one. I've been developing a feature in an app that updates line items within a purchase order under certain conditions. It's a pretty curly feature so I've been working on it for weeks. And it's just become clear that Xero appear to disallow filtering/finding on this endpoint where other endpoints are fine with it.

Should we possibly pop an exception within \XeroPHP\Remote\Query::addWhere to pick out if $this->from_class is PurchaseOrder, explaining that filtering on this endpoint is currently disallowed? I'm fairly sure it would have saved me this heartache.. :)

ok200paul avatar Dec 15 '20 00:12 ok200paul