Merge pull request #18409 from vincentjdc/product-generate-ref-after-form
NEW : Allows product ref generation after the form is validated with PRODUCT_GENERATE_REF_AFTER_FORM
This commit is contained in:
commit
79f9b30f29
@ -88,8 +88,8 @@ $mesg = ''; $error = 0; $errors = array();
|
||||
$refalreadyexists = 0;
|
||||
|
||||
$id = GETPOST('id', 'int');
|
||||
$ref = GETPOST('ref', 'alpha');
|
||||
$type = (GETPOST('type', 'int') !== '') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT;
|
||||
$ref = (GETPOSTISSET('ref') ? GETPOST('ref', 'alpha') : null);
|
||||
$type = (GETPOSTISSET('type') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT);
|
||||
$action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
|
||||
$cancel = GETPOST('cancel', 'alpha');
|
||||
$backtopage = GETPOST('backtopage', 'alpha');
|
||||
@ -112,6 +112,16 @@ if (!empty($user->socid)) {
|
||||
$socid = $user->socid;
|
||||
}
|
||||
|
||||
// Load object modCodeProduct
|
||||
$module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard');
|
||||
if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') {
|
||||
$module = substr($module, 0, dol_strlen($module) - 4);
|
||||
}
|
||||
$result = dol_include_once('/core/modules/product/'.$module.'.php');
|
||||
if ($result > 0) {
|
||||
$modCodeProduct = new $module();
|
||||
}
|
||||
|
||||
$object = new Product($db);
|
||||
$object->type = $type; // so test later to fill $usercancxxx is correct
|
||||
$extrafields = new ExtraFields($db);
|
||||
@ -247,9 +257,11 @@ if (empty($reshook)) {
|
||||
$error++;
|
||||
}
|
||||
if (empty($ref)) {
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors');
|
||||
$action = "create";
|
||||
$error++;
|
||||
if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors');
|
||||
$action = "create";
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
if (!empty($duration_value) && empty($duration_unit)) {
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Unit')), null, 'errors');
|
||||
@ -431,6 +443,11 @@ if (empty($reshook)) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$ref && !empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
|
||||
// Generate ref...
|
||||
$ref = $modCodeProduct->getNextValue($object, $type);
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$id = $object->create($user);
|
||||
}
|
||||
@ -470,7 +487,9 @@ if (empty($reshook)) {
|
||||
if ($object->id > 0) {
|
||||
$object->oldcopy = clone $object;
|
||||
|
||||
$object->ref = $ref;
|
||||
if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
|
||||
$object->ref = $ref;
|
||||
}
|
||||
$object->label = GETPOST('label', $label_security_check);
|
||||
|
||||
$desc = dol_htmlcleanlastbr(preg_replace('/ $/', '', GETPOST('desc', 'restricthtml')));
|
||||
@ -1079,16 +1098,18 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
|
||||
|
||||
print '<table class="border centpercent">';
|
||||
|
||||
print '<tr>';
|
||||
$tmpcode = '';
|
||||
if (!empty($modCodeProduct->code_auto)) {
|
||||
$tmpcode = $modCodeProduct->getNextValue($object, $type);
|
||||
if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
|
||||
print '<tr>';
|
||||
$tmpcode = '';
|
||||
if (!empty($modCodeProduct->code_auto)) {
|
||||
$tmpcode = $modCodeProduct->getNextValue($object, $type);
|
||||
}
|
||||
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="ref" name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref', 'alphanohtml') : $tmpcode).'">';
|
||||
if ($refalreadyexists) {
|
||||
print $langs->trans("RefAlreadyExists");
|
||||
}
|
||||
print '</td></tr>';
|
||||
}
|
||||
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="ref" name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref', 'alphanohtml') : $tmpcode).'">';
|
||||
if ($refalreadyexists) {
|
||||
print $langs->trans("RefAlreadyExists");
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
// Label
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label', $label_security_check)).'"></td></tr>';
|
||||
@ -2416,16 +2437,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
|
||||
}
|
||||
}
|
||||
|
||||
// Load object modCodeProduct
|
||||
$module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard');
|
||||
if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') {
|
||||
$module = substr($module, 0, dol_strlen($module) - 4);
|
||||
}
|
||||
$result = dol_include_once('/core/modules/product/'.$module.'.php');
|
||||
if ($result > 0) {
|
||||
$modCodeProduct = new $module();
|
||||
}
|
||||
|
||||
$tmpcode = '';
|
||||
if (!empty($modCodeProduct->code_auto)) {
|
||||
$tmpcode = $modCodeProduct->getNextValue($object, $object->type);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user