From bafc53ad958e869813b1e28948d728f227e10962 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sun, 11 May 2014 19:05:51 +0200
Subject: [PATCH] Fix: [ bug #1367 ] "Show invoice" link after a POS sell
 throws an error

---
 htdocs/compta/facture.php | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index a3d5067bfa8..29f4e61c7c7 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;
+		}
 	}
 }
 
-- 
GitLab