2
0
forked from Wavyzz/dolibarr

FIX setup of default doc template for supplier proposal when none.

This commit is contained in:
ldestailleur
2025-09-01 11:10:36 +02:00
parent 83dcc8fb54
commit c1fb41e5d9
5 changed files with 41 additions and 21 deletions

View File

@@ -1961,11 +1961,13 @@ function version_webserver()
* @param DoliDB $db Database handler
* @param string $type Type of models (company, invoice, ...)
* @param int $maxfilenamelength Max length of value to show
* @param int $showempty Add an empty record if 1
* @return string[]|int<-1,0> 0 if no module is activated, or array(key=>label). For modules that need directory scan, key is completed with ":filename", -1 if error
*/
function getListOfModels($db, $type, $maxfilenamelength = 0)
function getListOfModels($db, $type, $maxfilenamelength = 0, $showempty = 0)
{
global $conf, $langs;
$liste = array();
$found = 0;
$dirtoscan = '';
@@ -1973,19 +1975,30 @@ function getListOfModels($db, $type, $maxfilenamelength = 0)
$sql = "SELECT nom as id, nom as doc_template_name, libelle as label, description as description";
$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
$sql .= " WHERE type = '".$db->escape($type)."'";
$sql .= " AND entity IN (0,".$conf->entity.")";
$sql .= " AND entity IN (0,".((int) $conf->entity).")";
$sql .= " ORDER BY description DESC";
dol_syslog('/core/lib/function2.lib.php::getListOfModels', LOG_DEBUG);
$resql_models = $db->query($sql);
if ($resql_models) {
$num = $db->num_rows($resql_models);
if ($showempty) {
$liste[0] = '&nbsp;';
}
$i = 0;
while ($i < $num) {
$found = 1;
$obj = $db->fetch_object($resql_models);
if ($obj->id == '0') { // We discard bad record (should not happen)
$i++;
continue;
}
// If this generation module needs to scan a directory, then description field is filled
// with the constant that contains list of directories to scan (COMPANY_ADDON_PDF_ODT_PATH, ...).
if (!empty($obj->description)) { // A list of directories to scan is defined
@@ -2034,6 +2047,7 @@ function getListOfModels($db, $type, $maxfilenamelength = 0)
$liste[$obj->id] = $obj->label ? $obj->label : $obj->doc_template_name;
}
}
$i++;
}
} else {