Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX update status on create supplier order for trigger #1181

Open
wants to merge 1 commit into
base: 2022.5.3_rc
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions htdocs/fourn/class/fournisseur.commande.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down