Fix shipment delete

This commit is contained in:
Francis Appels 2021-12-06 14:43:11 +01:00
parent 259b7dfe5a
commit 5803060caf

View File

@ -1403,6 +1403,9 @@ class Expedition extends CommonObject
$langs->load("agenda"); $langs->load("agenda");
// we try deletion of batch line even if module batch not enabled in case of the module were enabled and disabled previously
$shipmentlinebatch = new ExpeditionLineBatch($this->db);
// Loop on each product line to add a stock movement // Loop on each product line to add a stock movement
$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id"; $sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
@ -1422,12 +1425,9 @@ class Expedition extends CommonObject
// we do not log origin because it will be deleted // we do not log origin because it will be deleted
$mouvS->origin = null; $mouvS->origin = null;
// get lot/serial // get lot/serial
$lotArray = null; $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id);
if ($conf->productbatch->enabled) { if (!is_array($lotArray)) {
$lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id); $error++; $this->errors[] = "Error ".$this->db->lasterror();
if (!is_array($lotArray)) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
} }
if (empty($lotArray)) { if (empty($lotArray)) {
// no lot/serial // no lot/serial
@ -1458,9 +1458,8 @@ class Expedition extends CommonObject
} }
} }
// delete batch expedition line (we try deletion even if module not enabled in case of the module were enabled and disabled previously) // delete batch expedition line
if (!$error) { if (!$error) {
$shipmentlinebatch = ExpeditionLineBatch($this->db);
if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) { if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) {
$error++; $this->errors[] = "Error ".$this->db->lasterror(); $error++; $this->errors[] = "Error ".$this->db->lasterror();
} }