NEW #35700 : Throw an error when validating a propal, order, supplier with a product no more in sale/purchase… (#35709)

* Fix #35700 : Throw an error when validating a propal, order, supplier proposal, supplier order if some products doesn't have the good status (on sale, on buy)

* Fix #35700 : Throw an error when validating a propal, order, supplier proposal, supplier order if some products doesn't have the good status (on sale, on buy)

* Fix #35700 : Throw an error when validating a propal, order, supplier proposal, supplier order if some products doesn't have the good status (on sale, on buy)

* Fix #35700 : Throw an error when validating a propal, order, supplier proposal, supplier order if some products doesn't have the good status (on sale, on buy)

* Fix #35700 : Throw an error when validating a propal, order, supplier proposal, supplier order if some products doesn't have the good status (on sale, on buy)

* Update commonobject.class.php

* Refactor checkActiveProductInLines method

* Fix comment formatting in commonobject.class.php

* Update commonobject.class.php

---------

Co-authored-by: vmaury <vmaury@vmaury-Lafite-Pro-16-AMD>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Vincent Maury 2025-10-18 11:19:31 +02:00 committed by GitHub
parent f0c61790eb
commit b28b94821f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 60 additions and 3 deletions

View file

@ -2102,6 +2102,11 @@ class Propal extends CommonObject
return -1;
}
if (!getDolGlobalBool('PROPALE_NOCHECK_ONSALE_PRODUCTS_ONVALID') && !$this->checkActiveProductInLines()) {
dol_syslog(get_class($this)."::valid checkActiveProductInLines ".$this->error, LOG_INFO);
return -1;
}
$now = dol_now();
$this->db->begin();

View file

@ -529,7 +529,10 @@ class Commande extends CommonOrder
$this->error = 'ErrorWrongParameters';
return -1;
}
if (!getDolGlobalBool('ORDER_NOCHECK_ONSALE_PRODUCTS_ONVALID') && !$this->checkActiveProductInLines()) {
dol_syslog(get_class($this)."::valid checkActiveProductInLines ".$this->error, LOG_INFO);
return -1;
}
$now = dol_now();
$this->db->begin();

View file

@ -20,7 +20,8 @@
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
* Copyright (C) 2025 Alexandre Janniaux <alexandre.janniaux@gmail.com>
*
* Copyright (C) 2025 Vincent Maury <vmaury@timgroup.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
@ -11619,4 +11620,43 @@ abstract class CommonObject
$this->db->commit();
return true;
}
/**
* Check if all products have the right status (on sale, on buy) called
* during validation of propal, order, supplier proposal, supplier order
*
* @global object $langs
* @param string $status onsale or onbuy
* @return bool
*/
public function checkActiveProductInLines($status = 'onsale')
{
global $langs;
if (isModEnabled('product') || isModEnabled('service')) {
include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$ret = true;
$tmpproduct = new Product($this->db);
foreach ($this->lines as $line) {
if ($line->fk_product > 0) {
$tmpproduct->fetch($line->fk_product);
$statustotest = ($status == 'onsale' ? 'status' : 'status_buy');
if (!$tmpproduct->$statustotest) {
$langs->load('products');
$statuskey4lang = ($status == 'onsale' ? 'ProductStatusNotOnSell' : 'ProductStatusNotOnBuy');
$ret = false;
$this->errors[] = $langs->trans('ProductRef').' '.$tmpproduct->ref.' '.$langs->trans($statuskey4lang);
break;
}
}
}
if (!$ret) {
$this->error = 'ErrorOneLineContainsADisactivatedProduct';
}
return $ret;
} else {
return true;
}
}
}

View file

@ -800,6 +800,10 @@ class CommandeFournisseur extends CommonOrder
|| (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_order_advance", "validate"))) {
$this->db->begin();
if (!getDolGlobalBool('SUPPLIER_ORDER_NOCHECK_ONBUY_PRODUCTS_ONVALID') && !$this->checkActiveProductInLines('onbuy')) {
dol_syslog(get_class($this)."::valid checkActiveProductInLines ".$this->error, LOG_INFO);
return -1;
}
// Definition of supplier order numbering model name
$soc = new Societe($this->db);
$soc->fetch($this->fourn_id);

View file

@ -364,6 +364,7 @@ ErrorIsNotInError=%s is not in error
ErrorFilenameExtensionNotAllowed=File %s has a forbidden file extension
ErrorNoValueForSelectListType=Error, a value for this type of field is mandatory
ErrorPaymentAmountMustNotBeNull=Error, payment amount must be defined and not zero
ErrorOneLineContainsADisactivatedProduct=Error, at least one product is not or no more on sale or for purchase
ErrorCalendarIsNotYetOpenOrHasBeenClosed=This calendar is not yet open or has been closed
# Warnings

View file

@ -361,6 +361,7 @@ ErrorThisGroupIsAlreadyDefinedAsThisType=Les contacts avec ce groupe sont déjà
ErrorIsNotInError=%s n'est pas en erreur
ErrorFilenameExtensionNotAllowed=Le fichier %s a une extension interdite
ErrorNoValueForSelectListType=Erreur, une valeur pour ce type de champ est obligatoire
ErrorOneLineContainsADisactivatedProduct=Erreur, au moins un produit n'a pas le bon statut
# Warnings
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Votre paramètre PHP upload_max_filesize (%s) est supérieur au paramètre PHP post_max_size (%s). Ceci n'est pas une configuration cohérente.

View file

@ -1497,7 +1497,10 @@ class SupplierProposal extends CommonObject
if ($result < 0) {
return -1;
}
if (!getDolGlobalBool('SUPPLIER_PROPOSAL_NOCHECK_ONBUY_PRODUCTS_ONVALID') && !$this->checkActiveProductInLines('onbuy')) {
dol_syslog(get_class($this)."::valid checkActiveProductInLines ".$this->error, LOG_INFO);
return -1;
}
// Define new ref
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$num = $this->getNextNumRef($soc);