Fix PROPAL_ENABLE_NEGATIVE_QTY and ORDER_ENABLE_NEGATIVE_QTY

This commit is contained in:
Laurent Destailleur 2026-01-20 02:11:14 +01:00
parent a42ce189ea
commit cba8ccaa32
4 changed files with 35 additions and 10 deletions

View file

@ -207,6 +207,7 @@ if (empty($reshook)) {
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
include DOL_DOCUMENT_ROOT . '/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
if (!($socid > 0)) {
@ -1278,6 +1279,13 @@ if (empty($reshook)) {
}
}
$price_to_test_sign = ($price_ht ? $price_ht : $price_ttc);
if ((empty($idprod) || $idprod < 0) && ($price_to_test_sign < 0) && ($qty < 0)) {
$langs->load("errors");
setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
$error++;
}
if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
$error++;
@ -1287,6 +1295,10 @@ if (empty($reshook)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
$error++;
}
if ($qty < 0 && !getDolGlobalString('PROPAL_ENABLE_NEGATIVE_QTY')) {
setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
$error++;
}
if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
$error++;
@ -1306,8 +1318,7 @@ if (empty($reshook)) {
}
}
$propal_qty_requirement = (getDolGlobalString('PROPAL_ENABLE_NEGATIVE_QTY') ? ($qty >= 0 || $qty <= 0) : $qty >= 0);
if (!$error && $propal_qty_requirement && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
if (!$error && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
$pu_ht = 0;
$pu_ttc = 0;
$pu_ht_devise = 0;

View file

@ -1016,7 +1016,10 @@ if (empty($reshook)) {
}
}
if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
$price_to_test_sign = ($price_ht ? $price_ht : $price_ttc);
if ((empty($idprod) || $idprod < 0) && ($price_to_test_sign < 0) && ($qty < 0)) {
$langs->load("errors");
setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
$error++;
}
@ -1032,10 +1035,12 @@ if (empty($reshook)) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
$error++;
}
if ($qty < 0) {
if ($qty < 0 && !getDolGlobalString('ORDER_ENABLE_NEGATIVE_QTY')) {
setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
$error++;
}
if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
$error++;
@ -1055,7 +1060,7 @@ if (empty($reshook)) {
}
}
if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
if (!$error && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
// Clean parameters
$date_start = dol_mktime(GETPOSTINT('date_start' . $predef . 'hour'), GETPOSTINT('date_start' . $predef . 'min'), GETPOSTINT('date_start' . $predef . 'sec'), GETPOSTINT('date_start' . $predef . 'month'), GETPOSTINT('date_start' . $predef . 'day'), GETPOSTINT('date_start' . $predef . 'year'));
$date_end = dol_mktime(GETPOSTINT('date_end' . $predef . 'hour'), GETPOSTINT('date_end' . $predef . 'min'), GETPOSTINT('date_end' . $predef . 'sec'), GETPOSTINT('date_end' . $predef . 'month'), GETPOSTINT('date_end' . $predef . 'day'), GETPOSTINT('date_end' . $predef . 'year'));
@ -1673,7 +1678,7 @@ if (empty($reshook)) {
}
}
if ($qty < 0) {
if ($qty < 0 && !getDolGlobalString('ORDER_ENABLE_NEGATIVE_QTY')) {
setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
$error++;
$action = 'editline';

View file

@ -1232,6 +1232,7 @@ class Form
if (empty($hidetext)) {
print $langs->trans("Type").'...';
}
print '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="select_' . $htmlname . '" name="' . $htmlname . '">';
if ($showempty) {
print '<option value="-1" class="opacitymedium"'.($useajaxcombo ? '' : ' disabled="disabled"');
@ -1252,12 +1253,14 @@ class Form
print ' selected';
}
print '>' . $langs->trans("Product");
print '</option>';
print '<option value="1"';
if (1 == $selected || ($selected == -1 && getDolGlobalString('MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT') == 'service')) {
print ' selected';
}
print '>' . $langs->trans("Service");
print '</option>';
print '</select>';

View file

@ -246,7 +246,10 @@ if ($nolinesbefore) {
if ($forceall >= 0 && (isModEnabled("product") || isModEnabled("service"))) {
print '<label for="prod_entry_mode_free">';
}
// Select type of line
$form->select_type_of_lines(GETPOSTISSET("type") ? GETPOST("type", 'alpha', 2) : -1, 'type', $labelforempty, 1, $forceall, 'minwidth200', 0);
if ($forceall >= 0 && (isModEnabled("product") || isModEnabled("service"))) {
print '</label>';
}
@ -804,11 +807,11 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
}
if (jQuery("#select_type").val() != '-1') {
console.log("we remove class");
console.log("we remove class placeholder");
jQuery("#select_type").removeClass("placeholder");
setFocusOnDescription();
} else {
console.log("we add class");
console.log("we add class placeholder");
jQuery("#select_type").addClass("placeholder");
}
});
@ -826,9 +829,12 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
<?php
if (!$freelines) { ?>
console.log("emulate click on prod_entry_mode_predef");
jQuery("#prod_entry_mode_predef").click();
<?php
} else { ?>
} elseif (!GETPOSTISSET("type")) { // If not a type selected from previous page
?>
console.log("add class placeholder");
jQuery("#select_type").addClass("placeholder");
<?php
}
@ -846,7 +852,7 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
}
}
});
<?php
<?php
} ?>
/* When changing predefined product, we reload list of supplier prices required for margin combo */