picqer / exact-php-client

PHP Client library for Exact Online
MIT License
165 stars 202 forks source link

Exception "Error 500: Not allow to update in Basic : Warehouse." #639

Closed tuimz closed 1 month ago

tuimz commented 5 months ago

Hello,

I am currently receiving this error "Error 500: Not allow to update in Basic : Warehouse."

Even though I am not updating the warehouse at all. Or updating anything for that matter since this example code already fails.

        (new \Picqer\Financials\Exact\PurchaseOrder($this->connection))
            ->find('some-guid-of-purchase-order')->save();

Which is strange since we have one "default" warehouse in Exact and upon creation of the purchase order that gets initialized. But once I try to update the Purchase order in question even without changing the warehouseID value I get this error.

If I need to provide any more info, examples or anything let me know. This might be related to #492 but that got closed without a proper answer from the user that made it.

remkobrenters commented 5 months ago

Yes, looks like the same issue. I suspect that Exact attempts to update the inventory (or at least to verify if updates are necessary based on the purchase order executed) but lacks the necessary permissions because of the basic license, which then leads to an error being triggered.

tuimz commented 5 months ago

Ok I will contact Exact support and see what comes back.

I will reply here with a solution for future reference ;)

remkobrenters commented 5 months ago

That would be awesome. I will keep this issue open.

tuimz commented 5 months ago

Response from Exact:

If you have a "project license" you cannot PUT the WarehouseID parameter.

I am not 100% sure that leaving out the parameter on the object does not post the parameter? E.g:


$model = (new \Picqer\Financials\Exact\PurchaseOrder($this->connection))->find('some-guid-of-purchase-order');

$model->Description = "Test 123";

$model->save();

Does that still post the WarehouseID parameter but empty?

remkobrenters commented 5 months ago

That makes sense as I am pretty sure the package performs a PUT request based on the source objects contents plus your changes. In this case it will probably try to store an empty string for the warehouse while it is not allowed to. This is however something that you cannot easy change. Also it is not clear from the Exact Online documentation which properties are restricted by licenses and should be omitted in some cases. Tricky one. Someone else wants to chip in on this one?

tuimz commented 5 months ago

I could extends PurchaseOrder::class and override isFillable and then return false if we are doing anything with a key like 'WarehouseID'

I will try this and test if that works for us. Though it is not my preferred way to go but I might have no other choice.

tuimz commented 5 months ago

In the meantime I have a workaround

I extend your PurchaseOrder class with the following:


<?php

namespace App\Exact;

class PurchaseOrder extends \Picqer\Financials\Exact\PurchaseOrder
{

    private $hidden = [
        'Warehouse',
        'WarehouseCode',
        'WarehouseDescription',
    ];

    public function isFillable($key)
    {
        if (in_array($key, $this->hidden)) {
            return false;
        }

        return parent::isFillable($key);
    }

}

That solves the issue for now. It is unfortunate though since the Exact specification does not mention anything about this and even allows the setting of WarehouseID upon creation but no longer allows editing the value afterwards if you have the wrong licence.