FIX Compatibility with modules without document generation

This commit is contained in:
Laurent Destailleur 2020-08-17 15:54:07 +02:00
parent 8e00c9c304
commit c3e3baaca0

View File

@ -245,7 +245,11 @@ if ($action == 'confirm_delete' && !empty($permissiontodelete))
// Remove a line // Remove a line
if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd)) if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissiontoadd))
{ {
$result = $object->deleteline($user, $lineid); if (method_exists('deleteline', $object)) {
$result = $object->deleteline($user, $lineid); // For backward compatibility
} else {
$result = $object->deleteLine($user, $lineid);
}
if ($result > 0) if ($result > 0)
{ {
// Define output language // Define output language
@ -264,8 +268,10 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$ret = $object->fetch($object->id); // Reload to get new records if (method_exists($object, 'generateDocument')) {
$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); $ret = $object->fetch($object->id); // Reload to get new records
$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
} }
setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
@ -283,8 +289,7 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd)
if ($result >= 0) if ($result >= 0)
{ {
// Define output language // Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
{
if (method_exists($object, 'generateDocument')) { if (method_exists($object, 'generateDocument')) {
$outputlangs = $langs; $outputlangs = $langs;
$newlang = ''; $newlang = '';
@ -312,20 +317,21 @@ if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd)
if ($result >= 0) if ($result >= 0)
{ {
// Define output language // Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
{ if (method_exists($object, 'generateDocument')) {
$outputlangs = $langs; $outputlangs = $langs;
$newlang = ''; $newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
if (!empty($newlang)) { if (!empty($newlang)) {
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
$model = $object->modelpdf; $model = $object->modelpdf;
$ret = $object->fetch($id); // Reload to get new records $ret = $object->fetch($id); // Reload to get new records
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
} }
} else { } else {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
@ -351,20 +357,21 @@ if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd)
if ($result >= 0) if ($result >= 0)
{ {
// Define output language // Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
{ if (method_exists($object, 'generateDocument')) {
$outputlangs = $langs; $outputlangs = $langs;
$newlang = ''; $newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
if (!empty($newlang)) { if (!empty($newlang)) {
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
} }
$model = $object->modelpdf; $model = $object->modelpdf;
$ret = $object->fetch($id); // Reload to get new records $ret = $object->fetch($id); // Reload to get new records
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
} }
} else { } else {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');