FIX delete of warehouse

This commit is contained in:
Laurent Destailleur 2023-05-21 15:16:45 +02:00
parent 6e0c57263c
commit 5e4edac94d
4 changed files with 27 additions and 11 deletions

View File

@ -317,3 +317,4 @@ StockTransferRightRead=Read stocks transfers
StockTransferRightCreateUpdate=Create/Update stocks transfers
StockTransferRightDelete=Delete stocks transfers
BatchNotFound=Lot / serial not found for this product
WarningThisWIllAlsoDeleteStock=Warning, this will also destroy all quantities in stock in the warehouse

View File

@ -391,7 +391,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// ));
// }
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToRefuse'), $text, 'confirm_refuse', $formquestion, '', 1, 250);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToRefuse'), '', 'confirm_refuse', $formquestion, '', 1, 250);
}
// Call Hook formConfirm

View File

@ -413,7 +413,10 @@ if ($action == 'create') {
// Confirm delete warehouse
if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteAWarehouse"), $langs->trans("ConfirmDeleteWarehouse", $object->label), "confirm_delete", '', 0, 2);
$formquestion = array(
array('type' => 'other', 'name' => 'info', 'label' => img_warning('').$langs->trans("WarningThisWIllAlsoDeleteStock"), 'morecss'=>'warning')
);
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteAWarehouse"), $langs->trans("ConfirmDeleteWarehouse", $object->label), "confirm_delete", $formquestion, 0, 2);
}
// Call Hook formConfirm

View File

@ -367,16 +367,28 @@ class Entrepot extends CommonObject
// End call triggers
}
$elements = array('stock_mouvement', 'product_stock', 'product_warehouse_properties');
foreach ($elements as $table) {
if (!$error) {
$sql = "DELETE FROM ".$this->db->prefix().$table;
$sql .= " WHERE fk_entrepot = ".((int) $this->id);
if (!$error) {
$sql = "DELETE FROM ".$this->db->prefix()."product_batch";
$sql .= " WHERE fk_product_stock IN (SELECT rowid FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_entrepot = ".((int) $this->id).")";
$result = $this->db->query($sql);
if (!$result) {
$error++;
$this->errors[] = $this->db->lasterror();
}
}
$result = $this->db->query($sql);
if (!$result) {
$error++;
$this->errors[] = $this->db->lasterror();
if (!$error) {
$elements = array('stock_mouvement', 'product_stock');
foreach ($elements as $table) {
if (!$error) {
$sql = "DELETE FROM ".$this->db->prefix().$table;
$sql .= " WHERE fk_entrepot = ".((int) $this->id);
$result = $this->db->query($sql);
if (!$result) {
$error++;
$this->errors[] = $this->db->lasterror();
}
}
}
}