diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a3d5067bfa80aba0b9f0ccad992f3c659087e931..29f4e61c7c767b48d088162bb679eae0278fa2be 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1855,21 +1855,25 @@ else if ($action == 'builddoc') // En get ou en post if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); if (GETPOST('fk_bank')) $object->fk_bank=GETPOST('fk_bank'); - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) + // object->modelpdf can be empty when we are using odt template by default and builddoc is called by POS module (invoice was just created and no template ODT template was selected). + if (! empty($object->modelpdf)) { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - $result=facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + $result=facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } } }