FIX : object linked to stock movement + travis

This commit is contained in:
Gauthier PC portable 024 2021-10-08 13:33:19 +02:00
parent ca3899dbf1
commit ef6f7a619a
3 changed files with 14 additions and 13 deletions

View File

@ -505,7 +505,6 @@ class StockTransfer extends CommonObject
*/
public function deleteLine(User $user, $idline, $notrigger = false)
{
global $db;
if ($this->status < 0) {
$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
return -2;
@ -564,8 +563,8 @@ class StockTransfer extends CommonObject
$sql .= " SET ref = '".$this->db->escape($num)."',";
$sql .= " status = ".self::STATUS_VALIDATED;
if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',";
if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id;
$sql .= " WHERE rowid = ".$this->id;
if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".((int) $user->id);
$sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
$resql = $this->db->query($sql);
@ -590,7 +589,7 @@ class StockTransfer extends CommonObject
if (preg_match('/^[\(]?PROV/i', $this->ref)) {
// Now we rename also files into index
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransfer/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->error = $this->db->lasterror(); }

View File

@ -447,19 +447,21 @@ class StockTransferLine extends CommonObjectLine
public function doStockMovement($label, $code_inv, $fk_entrepot, $direction = 1)
{
global $db, $conf, $user, $langs;
global $conf, $user, $langs;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
include_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
include_once DOL_DOCUMENT_ROOT . '/product/stock/stocktransfer/class/stocktransfer.class.php';
$p = new Product($db);
$p = new Product($this->db);
$p->fetch($this->fk_product);
$op[0] = "+".trim($this->qty);
$op[1] = "-".trim($this->qty);
$movementstock = new MouvementStock($db);
$movementstock->origin = new StockTransfer($db);
$movementstock->origin->id = $this->fk_stocktransfer;
$movementstock = new MouvementStock($this->db);
$st = new StockTransfer($this->db);
$movementstock->origin_type = $st->origin_type;
$movementstock->origin_id = $this->fk_stocktransfer;
if (empty($this->batch)) { // no batch for line
/*$result = $p->correct_stock(
@ -586,8 +588,8 @@ class StockTransferLine extends CommonObjectLine
$sql .= " SET ref = '".$this->db->escape($num)."',";
$sql .= " status = ".self::STATUS_VALIDATED;
if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',";
if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".$user->id;
$sql .= " WHERE rowid = ".$this->id;
if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".((int) $user->id);
$sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
$resql = $this->db->query($sql);
@ -612,7 +614,7 @@ class StockTransferLine extends CommonObjectLine
if (preg_match('/^[\(]?PROV/i', $this->ref)) {
// Now we rename also files into index
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransferline/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->error = $this->db->lasterror(); }

View File

@ -215,7 +215,7 @@ if (empty($reshook)) {
if (empty($error)) {
$line = new StockTransferLine($db);
$records = $line->fetchAll('', '', 0, 0, array('customsql'=>' fk_stocktransfer = '.$id.' AND fk_product = '.$fk_product.' AND fk_warehouse_source = '.$fk_warehouse_source.' AND fk_warehouse_destination = '.$fk_warehouse_destination.' AND ('.(empty($batch) ? 'batch = "" or batch IS NULL' : 'batch = "'.$batch.'"' ).')'));
$records = $line->fetchAll('', '', 0, 0, array('customsql'=>' fk_stocktransfer = '.((int) $id).' AND fk_product = '.((int) $fk_product).' AND fk_warehouse_source = '.((int) $fk_warehouse_source).' AND fk_warehouse_destination = '.((int) $fk_warehouse_destination).' AND ('.(empty($batch) ? 'batch = "" or batch IS NULL' : "batch = '".$db->escape($batch)."'" ).')'));
if (!empty($records[key($records)])) $line = $records[key($records)];
$line->fk_stocktransfer = $id;
$line->qty += $qty;