From 64739098ae31d8277a145784fa45863f7f65baf7 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio Date: Tue, 5 Feb 2019 11:58:49 +0100 Subject: [PATCH] FIX: expedition: reset status on rollback + replace hardcoded status with const --- htdocs/expedition/class/expedition.class.php | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index b4e4e0c8614..d7960d6ff52 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -538,7 +538,7 @@ class Expedition extends CommonObject $this->db->free($result); - if ($this->statut == 0) $this->brouillon = 1; + if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; // Tracking url $this->GetUrlTrackingStatus($obj->tracking_number); @@ -783,7 +783,7 @@ class Expedition extends CommonObject if (! $error) { $this->ref = $numref; - $this->statut = 1; + $this->statut = self::STATUS_VALIDATED; } if (! $error) @@ -816,7 +816,7 @@ class Expedition extends CommonObject if ($conf->livraison_bon->enabled) { - if ($this->statut == 1 || $this->statut == 2) + if ($this->statut == self::STATUS_VALIDATED || $this->statut == self::STATUS_CLOSED) { // Expedition validee include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php'; @@ -1111,7 +1111,7 @@ class Expedition extends CommonObject $this->db->begin(); // Stock control - if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0) + if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) { require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"); @@ -1663,7 +1663,7 @@ class Expedition extends CommonObject $this->id=0; $this->ref = 'SPECIMEN'; $this->specimen=1; - $this->statut = 1; + $this->statut = self::STATUS_VALIDATED; $this->livraison_id = 0; $this->date = $now; $this->date_creation = $now; @@ -2037,6 +2037,7 @@ class Expedition extends CommonObject } else { + $this->statut = self::STATUS_VALIDATED; $this->db->rollback(); return -1; } @@ -2060,7 +2061,7 @@ class Expedition extends CommonObject $resql=$this->db->query($sql); if ($resql) { - $this->statut=2; + $this->statut=self::STATUS_CLOSED; $this->billed=1; // Call trigger @@ -2080,6 +2081,8 @@ class Expedition extends CommonObject } else { + $this->statut=self::STATUS_VALIDATED; + $this->billed=0; $this->db->rollback(); return -1; } @@ -2104,13 +2107,15 @@ class Expedition extends CommonObject $this->db->begin(); + $oldbilled=$this->billed; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; $resql=$this->db->query($sql); if ($resql) { - $this->statut=1; + $this->statut=self::STATUS_VALIDATED; $this->billed=0; // If stock increment is done on closing @@ -2208,6 +2213,8 @@ class Expedition extends CommonObject } else { + $this->statut=self::STATUS_CLOSED; + $this->billed=$oldbilled; $this->db->rollback(); return -1; }