FIX : Bug when updateing availability and demand reason because $user

is not passed to trigger.
This commit is contained in:
florian HENRY 2016-12-10 12:21:48 +01:00
parent bd1d076753
commit 9e8991f7fa
2 changed files with 67 additions and 47 deletions

View File

@ -1070,17 +1070,17 @@ if (empty($reshook))
// Set project // Set project
else if ($action == 'classin' && $user->rights->propal->creer) { else if ($action == 'classin' && $user->rights->propal->creer) {
$object->setProject($_POST['projectid']); $object->setProject(GETPOST('projectid','int'));
} }
// Delai de livraison // Delai de livraison
else if ($action == 'setavailability' && $user->rights->propal->creer) { else if ($action == 'setavailability' && $user->rights->propal->creer) {
$result = $object->availability($_POST['availability_id']); $result = $object->set_availability($user, GETPOST('availability_id','int'));
} }
// Origine de la propale // Origine de la propale
else if ($action == 'setdemandreason' && $user->rights->propal->creer) { else if ($action == 'setdemandreason' && $user->rights->propal->creer) {
$result = $object->demand_reason($_POST['demand_reason_id']); $result = $object->set_demand_reason($user, GETPOST('demand_reason_id','int'));
} }
// Conditions de reglement // Conditions de reglement

View File

@ -1839,7 +1839,7 @@ class Propal extends CommonObject
*/ */
function set_availability($user, $id, $notrigger=0) function set_availability($user, $id, $notrigger=0)
{ {
if (! empty($user->rights->propal->creer)) if (! empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT)
{ {
$error=0; $error=0;
@ -1849,7 +1849,7 @@ class Propal extends CommonObject
$sql.= " SET fk_availability = '".$id."'"; $sql.= " SET fk_availability = '".$id."'";
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__.' availability('.$availability_id.')', LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (!$resql) if (!$resql)
{ {
@ -1861,6 +1861,7 @@ class Propal extends CommonObject
{ {
$this->oldcopy= clone $this; $this->oldcopy= clone $this;
$this->fk_availability = $id; $this->fk_availability = $id;
$this->availability_id = $availability_id;
} }
if (! $notrigger && empty($error)) if (! $notrigger && empty($error))
@ -1887,6 +1888,14 @@ class Propal extends CommonObject
return -1*$error; return -1*$error;
} }
} }
else
{
$error_str='Propal status do not meet requirement '.$this->statut;
dol_syslog(__METHOD__.$error_str, LOG_ERR);
$this->error=$error_str;
$this->errors[]= $this->error;
return -2;
}
} }
/** /**
@ -1899,14 +1908,14 @@ class Propal extends CommonObject
*/ */
function set_demand_reason($user, $id, $notrigger=0) function set_demand_reason($user, $id, $notrigger=0)
{ {
if (! empty($user->rights->propal->creer)) if (! empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT)
{ {
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
$sql.= " SET fk_input_reason = '".$id."'"; $sql.= " SET fk_input_reason = ".$id;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
@ -1922,6 +1931,7 @@ class Propal extends CommonObject
{ {
$this->oldcopy= clone $this; $this->oldcopy= clone $this;
$this->fk_input_reason = $id; $this->fk_input_reason = $id;
$this->demand_reason_id = $id;
} }
@ -1949,6 +1959,14 @@ class Propal extends CommonObject
return -1*$error; return -1*$error;
} }
} }
else
{
$error_str='Propal status do not meet requirement '.$this->statut;
dol_syslog(__METHOD__.$error_str, LOG_ERR);
$this->error=$error_str;
$this->errors[]= $this->error;
return -2;
}
} }
/** /**
@ -2733,6 +2751,7 @@ class Propal extends CommonObject
* @param int $availability_id Id of new delivery time * @param int $availability_id Id of new delivery time
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int >0 if OK, <0 if KO * @return int >0 if OK, <0 if KO
* @deprecated use set_availability
*/ */
function availability($availability_id, $notrigger=0) function availability($availability_id, $notrigger=0)
{ {
@ -2800,6 +2819,7 @@ class Propal extends CommonObject
* @param int $demand_reason_id Id of new source demand * @param int $demand_reason_id Id of new source demand
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int >0 si ok, <0 si ko * @return int >0 si ok, <0 si ko
* @deprecated use set_demand_reason
*/ */
function demand_reason($demand_reason_id, $notrigger=0) function demand_reason($demand_reason_id, $notrigger=0)
{ {