NEW add recursive deletion option for child m os (#26102)
* added recursive deletion option for child MOs + added recursive recovery method for child MOs * add number of MOs in form_confirm * update to delete number of mo childs if is null * added checking of an infinity loop * review PR
This commit is contained in:
parent
e308e0046f
commit
cfdc3d1af3
4 changed files with 112 additions and 2 deletions
|
|
@ -37,6 +37,8 @@ ConfirmCancelMo=Are you sure you want to cancel this Manufacturing Order?
|
|||
DeleteMo=Delete Manufacturing Order
|
||||
ConfirmDeleteBillOfMaterials=Are you sure you want to delete this Bill Of Materials?
|
||||
ConfirmDeleteMo=Are you sure you want to delete this Manufacturing Order?
|
||||
DeleteMoChild = Delete the child OFs linked to this OF %s
|
||||
MoChildsDeleted = All child OFs have been deleted
|
||||
MenuMRP=Manufacturing Orders
|
||||
NewMO=New Manufacturing Order
|
||||
QtyToProduce=Qty to produce
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ ConfirmCancelMo=Êtes-vous sûr de vouloir annuler cet ordre de fabrication ?
|
|||
DeleteMo=Supprimer l'ordre de fabrication
|
||||
ConfirmDeleteBillOfMaterials=Êtes-vous sûr de vouloir supprimer cette nomenclature?
|
||||
ConfirmDeleteMo=Êtes-vous sûr de vouloir supprimer cet ordre de fabrication ?
|
||||
DeleteMoChild = Supprimer les OFs enfants liés à cet OF %s
|
||||
MoChildsDeleted = Tous les OFs enfants ont été supprimés
|
||||
MenuMRP=Ordres de fabrication
|
||||
NewMO=Nouvel Ordre de fabrication
|
||||
QtyToProduce=Quantité à produire
|
||||
|
|
|
|||
|
|
@ -1816,6 +1816,46 @@ class Mo extends CommonObject
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used to return all child MOs recursively
|
||||
*
|
||||
* @param int $depth Depth for recursing loop count
|
||||
* @return Mo[]|int[] array of MOs if OK, -1 if KO
|
||||
*/
|
||||
public function getAllMoChilds($depth = 0)
|
||||
{
|
||||
if ($depth > 1000) return -1;
|
||||
|
||||
$TMoChilds = array();
|
||||
$error = 0;
|
||||
|
||||
$childMoList = $this->getMoChilds();
|
||||
|
||||
if ($childMoList == -1) return -1;
|
||||
|
||||
foreach ($childMoList as $childMo) $TMoChilds[$childMo->id] = $childMo;
|
||||
|
||||
foreach ($childMoList as $childMo) {
|
||||
$childMoChildren = $childMo->getAllMoChilds($depth + 1);
|
||||
|
||||
if ($childMoChildren == -1) {
|
||||
$error++;
|
||||
} else {
|
||||
foreach ($childMoChildren as $child) {
|
||||
$TMoChilds[$child->id] = $child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return -1;
|
||||
} else {
|
||||
return $TMoChilds;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Function used to return childs of Mo
|
||||
*
|
||||
|
|
|
|||
|
|
@ -196,6 +196,66 @@ if (empty($reshook)) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
|
||||
if (!($object->id > 0)) {
|
||||
dol_print_error('', 'Error, object must be fetched before being deleted');
|
||||
exit;
|
||||
}
|
||||
|
||||
$error = 0;
|
||||
$deleteChilds = GETPOST('deletechilds', 'boolean');
|
||||
|
||||
// Start the database transaction
|
||||
$db->begin();
|
||||
|
||||
if ($deleteChilds === 'on') {
|
||||
$TMoChildren = $object->getAllMoChilds();
|
||||
|
||||
foreach ($TMoChildren as $id => $childObject) {
|
||||
if ($childObject->delete($user) == -1) {
|
||||
$error++;
|
||||
if (!empty($childObject->errors)) {
|
||||
setEventMessages(null, $childObject->errors, 'errors');
|
||||
} else {
|
||||
setEventMessages($childObject->error, null, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$result = $object->delete($user);
|
||||
|
||||
if ($result > 0) {
|
||||
setEventMessages("RecordDeleted", null, 'mesgs');
|
||||
|
||||
if ($deleteChilds === 'on') {
|
||||
setEventMessages("MoChildsDeleted", null, 'mesgs');
|
||||
}
|
||||
|
||||
if (empty($noback)) {
|
||||
header("Location: " . $backurlforlist);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
if (!empty($object->errors)) {
|
||||
setEventMessages(null, $object->errors, 'errors');
|
||||
} else {
|
||||
setEventMessages($object->error, null, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Commit or rollback the database transaction based on whether there was an error
|
||||
if ($error) {
|
||||
$db->rollback();
|
||||
} else {
|
||||
$db->commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
|
||||
|
||||
|
|
@ -434,15 +494,21 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||
|
||||
// Confirmation to delete
|
||||
if ($action == 'delete') {
|
||||
$numberofmochilds = count($object->getAllMoChilds());
|
||||
|
||||
if ($numberofmochilds > 0)$label = $langs->trans("DeleteMoChild", '('.strval($numberofmochilds).')');
|
||||
else $label = $langs->trans("DeleteMoChild");
|
||||
|
||||
$formquestion = array(
|
||||
array('type' => 'checkbox', 'name' => 'deletechilds', 'label' => $label, 'value' => 0),
|
||||
array(
|
||||
'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
|
||||
'name' => 'alsoCancelConsumedAndProducedLines',
|
||||
'type' => 'checkbox',
|
||||
'value' => empty($conf->global->MO_ALSO_CANCEL_CONSUMED_AND_PRODUCED_LINES_BY_DEFAULT) ? 0 : 1
|
||||
),
|
||||
)
|
||||
);
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', $formquestion, 0, 1);
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', $formquestion, 0, 1);
|
||||
}
|
||||
// Confirmation to delete line
|
||||
if ($action == 'deleteline') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue