Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2023-03-10 19:27:01 +01:00
commit f183f41ad3
5 changed files with 56 additions and 12 deletions

View File

@ -2089,10 +2089,6 @@ abstract class CommonObject
$id_field = 'rowid';
}
$error = 0;
$this->db->begin();
// Special case
if ($table == 'product' && $field == 'note_private') {
$field = 'note';
@ -2101,6 +2097,32 @@ abstract class CommonObject
$fk_user_field = 'fk_user_mod';
}
if ($trigkey) {
$oldvalue = null;
$sql = "SELECT " . $field;
$sql .= " FROM " . MAIN_DB_PREFIX . $table;
$sql .= " WHERE " . $id_field . " = " . ((int) $id);
$resql = $this->db->query($sql);
if ($resql) {
if ($obj = $this->db->fetch_object($resql)) {
if ($format == 'date') {
$oldvalue = $this->db->jdate($obj->$field);
} else {
$oldvalue = $obj->$field;
}
}
} else {
$this->error = $this->db->lasterror();
return -1;
}
}
$error = 0;
$this->db->begin();
$sql = "UPDATE ".$this->db->prefix().$table." SET ";
if ($format == 'text') {
@ -2133,6 +2155,11 @@ abstract class CommonObject
} else {
$result = $this->fetchCommon($id);
}
$this->oldcopy = clone $this;
if (property_exists($this->oldcopy, $field)) {
$this->oldcopy->$field = $oldvalue;
}
if ($result >= 0) {
$result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors
}

View File

@ -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++;
}
}

View File

@ -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;
}
}

View File

@ -207,7 +207,7 @@ if ($cancel) {
$action = '';
}
$createbarcode = empty($conf->barcode->enabled) ? 0 : 1;
$createbarcode = isModEnabled('barcode');
if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) {
$createbarcode = 0;
}
@ -1419,7 +1419,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
}
}
$showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
$showbarcode = isModEnabled('barcode');
if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
$showbarcode = 0;
}
@ -1984,7 +1984,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
}
// Barcode
$showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
$showbarcode = isModEnabled('barcode');
if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
$showbarcode = 0;
}
@ -2312,7 +2312,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
} else {
// Fiche en mode visu
$showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
$showbarcode = isModEnabled('barcode');
if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
$showbarcode = 0;
}

View File

@ -377,7 +377,7 @@ llxHeader("", $title);
if (!empty($id) || !empty($ref)) {
$showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
$showbarcode = isModEnabled('barcode');
if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
$showbarcode = 0;
}