diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index b055e1a3be29f..d1a20313977e8 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1291,6 +1291,8 @@ public function create($user, $notrigger = 0) { global $langs, $conf, $hookmanager; + $this->oldcopy = dol_clone($this, 2); + $this->db->begin(); $error = 0; @@ -1322,6 +1324,8 @@ public function create($user, $notrigger = 0) // We set order into draft status $this->brouillon = 1; + $this->statut = self::STATUS_DRAFT; + $this->status = self::STATUS_DRAFT; $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur ("; $sql .= "ref"; @@ -1410,6 +1414,8 @@ public function create($user, $notrigger = 0) ); if ($result < 0) { dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); // do not use dol_print_error here as it may be a functionnal error + $this->statut = $this->oldcopy->statut; + $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; } @@ -1463,6 +1469,8 @@ public function create($user, $notrigger = 0) // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_CREATE', $user); if ($result < 0) { + $this->statut = $this->oldcopy->statut; + $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; } @@ -1473,12 +1481,16 @@ public function create($user, $notrigger = 0) return $this->id; } else { $this->error = $this->db->lasterror(); + $this->statut = $this->oldcopy->statut; + $this->status = $this->oldcopy->status; $this->db->rollback(); return -2; } } } else { $this->error = $this->db->lasterror(); + $this->statut = $this->oldcopy->statut; + $this->status = $this->oldcopy->status; $this->db->rollback(); return -1; }