NEW - Add a trigger when create a shipping line batch and fix propagate missing errors
This commit is contained in:
parent
c9d869f837
commit
f4e1ce4c73
@ -530,6 +530,7 @@ class Expedition extends CommonObject
|
||||
foreach ($tab as $detbatch) {
|
||||
if ($detbatch->entrepot_id == $stockLocation) {
|
||||
if (!($detbatch->create($line_id) > 0)) { // Create an ExpeditionLineBatch
|
||||
$this->errors = $detbatch->errors;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
@ -3020,7 +3021,7 @@ class ExpeditionLigne extends CommonObjectLine
|
||||
$shipmentLot->qty = $this->detail_batch->qty;
|
||||
$shipmentLot->fk_origin_stock = $batch_id;
|
||||
if ($shipmentLot->create($this->id) < 0) {
|
||||
$this->errors[] = $shipmentLot->errors;
|
||||
$this->errors = $shipmentLot->errors;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,11 +103,16 @@ class ExpeditionLineBatch extends CommonObject
|
||||
* Create an expeditiondet_batch DB record link to an expedtiondet record
|
||||
*
|
||||
* @param int $id_line_expdet rowid of expedtiondet record
|
||||
* @param User $f_user User that create
|
||||
* @param int $notrigger 1 = disable triggers
|
||||
* @return int <0 if KO, Id of record (>0) if OK
|
||||
*/
|
||||
public function create($id_line_expdet)
|
||||
public function create($id_line_expdet, $f_user = null, $notrigger = 0)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$error = 0;
|
||||
if (!is_object($f_user)) $f_user = $user;
|
||||
|
||||
$id_line_expdet = (int) $id_line_expdet;
|
||||
|
||||
@ -137,13 +142,24 @@ class ExpeditionLineBatch extends CommonObject
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
|
||||
|
||||
$this->fk_expeditiondet = $id_line_expdet;
|
||||
}
|
||||
|
||||
if (!$error && !$notrigger) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('EXPEDITIONLINEBATCH_CREATE', $f_user);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
return $this->id;
|
||||
} else {
|
||||
foreach ($this->errors as $errmsg) {
|
||||
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
|
||||
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1 * $error;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user