From 16249b7e19d0cb129cae41aae00fba75ce135b7d Mon Sep 17 00:00:00 2001 From: Vincent Maury Date: Mon, 1 Jul 2024 01:50:25 +0200 Subject: [PATCH] NEW Add option to clone its default BOM when cloning a product (#30088) * Add option to clone its default BOM when cloning a product * Improved label of cloned BOM ("BOM of cloned_product_ref") * - option "clone default BOM" not checked by default ( can be pre-checked with constant BOM_CLONE_DEFBOM) - add another option to clone all BOMs linked to a product (not checked by default) * - option "clone default BOM" not checked by default ( can be pre-checked with constant BOM_CLONE_DEFBOM) - add another option to clone all BOMs linked to a product (not checked by default) * Update mrp.lang * Update mrp.lang --------- Co-authored-by: Laurent Destailleur --- htdocs/langs/en_US/mrp.lang | 4 +++ htdocs/product/card.php | 49 ++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/mrp.lang b/htdocs/langs/en_US/mrp.lang index f80abce4316..f305107210b 100644 --- a/htdocs/langs/en_US/mrp.lang +++ b/htdocs/langs/en_US/mrp.lang @@ -15,6 +15,10 @@ ListOfBOMs=Bills of material - BOM ListOfManufacturingOrders=Manufacturing Orders NewBOM=New bill of materials ProductBOMHelp=Product to create (or disassemble) with this BOM.
Note: Products with the property 'Nature of product' = 'Raw material' are not visible into this list. +CloneDefBomProduct=Clone the default BOM to use to manufacture the product +CloneOtherBomsProduct=Clone all BOMs that can be used to manufacture the product +BOMofRef=BOM of %s +ErrorProductCloneBom=Error: Failed to clone a BOM BOMsNumberingModules=BOM numbering templates BOMsModelModule=BOM document templates MOsNumberingModules=MO numbering templates diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 89370e2abc3..267fdc49bfc 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -74,6 +74,7 @@ if (isModEnabled('accounting')) { } if (isModEnabled('bom')) { require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; + $langs->load("mrp"); } if (isModEnabled('workstation')) { require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php'; @@ -964,6 +965,43 @@ if (empty($reshook)) { } } + if (!$error && isModEnabled('bom') && $user->hasRight('bom', 'write')) { + $defbomidac = 0; // to avoid cloning same BOM twice + if (GETPOST('clone_defbom') && $object->fk_default_bom > 0) { + $bomstatic = new BOM($db); + $bomclone = $bomstatic->createFromClone($user, $object->fk_default_bom); + if ((int) $bomclone < 0) { + setEventMessages($langs->trans('ErrorProductClone').' : '.$langs->trans('ErrorProductCloneBom'), null, 'warnings'); + } else { + $defbomidac = $object->fk_default_bom; + $clone->fk_default_bom = $bomclone->id; + $clone->update($id, $user); + $bomclone->fk_product = $id; + $bomclone->label = $langs->trans('BOMofRef', $clone->ref); + $bomclone->update($user); + $bomclone->validate($user); + } + } + if (GETPOST('clone_otherboms')) { + $bomstatic = new BOM($db); + $bomlist = $bomstatic->fetchAll("", "", 0, 0, 'fk_product:=:'.(int) $object->id); + if (is_array($bomlist)) { + foreach ($bomlist as $bom2clone) { + if ($bom2clone->id != $defbomidac) { // to avoid cloning same BOM twice + $bomclone = $bomstatic->createFromClone($user, $bom2clone->id); + if ((int) $bomclone < 0) { + setEventMessages($langs->trans('ErrorProductClone').' : '.$langs->trans('ErrorProductCloneBom'), null, 'warnings'); + } else { + $bomclone->fk_product = $id; + $bomclone->label = $langs->trans('BOMofRef', $clone->ref); + $bomclone->update($user); + $bomclone->validate($user); + } + } + } + } + } + } // $clone->clone_fournisseurs($object->id, $id); } else { if ($clone->error == 'ErrorProductAlreadyExists') { @@ -2889,7 +2927,16 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->d if (getDolGlobalString('PRODUIT_SOUSPRODUITS')) { $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1); } - + if (isModEnabled('bom') && $user->hasRight('bom', 'write')) { + if ($object->fk_default_bom > 0) { + $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_defbom', 'label' => $langs->trans("CloneDefBomProduct"), 'value' => getDolGlobalInt('BOM_CLONE_DEFBOM')); + } + $bomstatic = new BOM($db); + $bomlist = $bomstatic->fetchAll("", "", 0, 0, 'fk_product:=:'.(int) $object->id); + if (is_array($bomlist) && count($bomlist) > 0) { + $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_otherboms', 'label' => $langs->trans("CloneOtherBomsProduct"), 'value' => 0); + } + } $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneProduct', $object->ref), 'confirm_clone', $formquestionclone, 'yes', 'action-clone', 350, 600); }