Skip to content

Order line deletion always fails on Dolibarr ≥ 22 — deleteItem() sets the deprecated ->statut #19

Description

@Pichinov-Jose

Repository: SplashSync/Dolibarr
Module version: 2.23.3 (also present in 2.21.0 — file unchanged between the two)
Dolibarr: 23.0.0

Summary

deleteItem() forces the order into draft state so Dolibarr will accept a line deletion, but it
sets the deprecated $object->statut property. Since Dolibarr renamed the property to
$object->status, Commande::deleteLine() no longer reads what Splash sets, and every line
deletion is refused.

Error

Splash\Local\Objects\Order::deleteItem() => Error :
  Supprimer une ligne n'est pas autorisée par l'état actuel de l'objet
  (ErrorDeleteLineNotAllowedByObjectStatus)

Root cause

src/Objects/Order/ItemsTrait.php:52-65

protected function deleteItem(OrderLine $orderLine): bool
{
    global $user;
    //====================================================================//
    // Force Order Status To Draft
    $this->object->statut = 0;          // <-- deprecated property
    //====================================================================//
    // Perform Line Delete
    if ($this->object->deleteline($user, $orderLine->id) <= 0) {
        return $this->catchDolibarrErrors();
    }

    return true;
}

Dolibarr 23 — htdocs/commande/class/commande.class.php:2489:

public function deleteLine($user = null, $lineid = 0, $id = 0)
{
    if ($this->status == self::STATUS_DRAFT) {   // <-- reads ->status, not ->statut
        ...
    } else {
        $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
        return -1;
    }
}

->statut is still declared for backward compatibility but is no longer what the guard reads, so
the forced draft state has no effect.

Consequence

Extra lines in Dolibarr can never be removed by a sync. On our instance, WooCommerce orders whose
fee lines had been recalculated at checkout kept their obsolete lines in Dolibarr permanently — the
Dolibarr order total stayed above the real WooCommerce total, and no re-sync could fix it.

Steps to reproduce

  1. Dolibarr 22 or 23.
  2. Sync an order, then remove a line on the shop side.
  3. Re-sync: Splash tries to delete the extra line and is refused.

Suggested fix

 // Force Order Status To Draft
 $this->object->statut = 0;
+$this->object->status = 0;

Setting both keeps compatibility with older Dolibarr versions that still read ->statut.
A broader sweep for ->statut = assignments elsewhere in the module may be worthwhile.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions