Merge pull request #15144 from atm-maxime/fix_supp_inv_numbering

Fix #15064 : error when supplier invoice numbering module is not configured
This commit is contained in:
Laurent Destailleur 2020-10-25 13:58:48 +01:00 committed by GitHub
commit 02ef5ad3b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 41 deletions

View File

@ -2469,7 +2469,7 @@ class FactureFournisseur extends CommonInvoice
{ {
$this->error=$obj->error; $this->error=$obj->error;
//dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error); //dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error);
return false; return -1;
} }
} }

View File

@ -57,7 +57,7 @@ if (!empty($conf->variants->enabled)) {
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
$langs->loadLangs(array('bills', 'compta', 'suppliers', 'companies', 'products', 'banks')); $langs->loadLangs(array('bills', 'compta', 'suppliers', 'companies', 'products', 'banks', 'admin'));
if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
$id = (GETPOST('facid', 'int') ? GETPOST('facid', 'int') : GETPOST('id', 'int')); $id = (GETPOST('facid', 'int') ? GETPOST('facid', 'int') : GETPOST('id', 'int'));
@ -2329,11 +2329,9 @@ else
// Confirmation de la validation // Confirmation de la validation
if ($action == 'valid') if ($action == 'valid')
{ {
// on verifie si l'objet est en numerotation provisoire // We check if number is temporary number
$objectref = substr($object->ref, 1, 4); if (preg_match('/^[\(]?PROV/i', $object->ref) || empty($object->ref)) // empty should not happened, but when it occurs, the test save life
if ($objectref == 'PROV')
{ {
$savdate = $object->date;
$numref = $object->getNextNumRef($societe); $numref = $object->getNextNumRef($societe);
} }
else else
@ -2341,6 +2339,14 @@ else
$numref = $object->ref; $numref = $object->ref;
} }
if ($numref < 0)
{
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
}
else
{
$text = $langs->trans('ConfirmValidateBill', $numref); $text = $langs->trans('ConfirmValidateBill', $numref);
/*if (! empty($conf->notification->enabled)) /*if (! empty($conf->notification->enabled))
{ {
@ -2352,17 +2358,13 @@ else
$formquestion = array(); $formquestion = array();
$qualified_for_stock_change = 0; $qualified_for_stock_change = 0;
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
{
$qualified_for_stock_change = $object->hasProductsOrServices(2); $qualified_for_stock_change = $object->hasProductsOrServices(2);
} } else {
else
{
$qualified_for_stock_change = $object->hasProductsOrServices(1); $qualified_for_stock_change = $object->hasProductsOrServices(1);
} }
if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
{
$langs->load("stocks"); $langs->load("stocks");
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
$formproduct = new FormProduct($db); $formproduct = new FormProduct($db);
@ -2382,6 +2384,7 @@ else
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1);
} }
}
// Confirmation edit (back to draft) // Confirmation edit (back to draft)
if ($action == 'edit') if ($action == 'edit')