From 436ec9308400d7e264dd7158c8c3bdd1018449ed Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Oct 2017 03:22:41 +0200 Subject: [PATCH] FIX is_erasable report bad value when thirdparty was not loaded --- htdocs/compta/facture/class/facture.class.php | 9 ++++++--- htdocs/core/lib/functions2.lib.php | 4 +++- test/phpunit/FactureTest.php | 1 - 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7ae8ea29740..d853ea03138 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1753,9 +1753,9 @@ class Facture extends CommonInvoice global $langs,$conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - if (empty($rowid)) $rowid=$this->id; + $rowid=$this->id; - dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG); + dol_syslog(get_class($this)."::delete rowid=".$rowid.", ref=".$this->ref.", thirdparty=".$this->thirdparty->name, LOG_DEBUG); // Test to avoid invoice deletion (allowed if draft) $test = $this->is_erasable(); @@ -3227,7 +3227,7 @@ class Facture extends CommonInvoice if (! empty($conf->global->FACTURE_ADDON)) { - dol_syslog("Call getNextNumRef with FACTURE_ADDON = ".$conf->global->FACTURE_ADDON); + dol_syslog("Call getNextNumRef with FACTURE_ADDON = ".$conf->global->FACTURE_ADDON.", thirdparty=".$soc->nom.", type=".$soc->typent_code, LOG_DEBUG); $mybool=false; @@ -3399,6 +3399,9 @@ class Facture extends CommonInvoice // If not a draft invoice and not temporary invoice if ($tmppart !== 'PROV') { + // We need to have this->thirdparty defined, in case of numbering rule use tags that depend on thirdparty (like {t} tag). + if (empty($this->thirdparty)) $this->fetch_thirdparty(); + $maxfacnumber = $this->getNextNumRef($this->thirdparty,'last'); $ventilExportCompta = $this->getVentilExportCompta(); diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index d794c8e1eca..3d2e2bb359b 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -723,7 +723,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m // but we should use local year and month of user // For debugging - dol_syslog("mask=".$mask); + //dol_syslog("mask=".$mask, LOG_DEBUG); //include_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'); //$mask='FA{yy}{mm}-{0000@99}'; //$date=dol_mktime(12, 0, 0, 1, 1, 1900); @@ -1148,6 +1148,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m dol_syslog("functions2::get_next_value return ".$numFinal,LOG_DEBUG); return $numFinal; } + function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); @@ -1156,6 +1157,7 @@ function get_string_between($string, $start, $end){ $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } + /** * Check value * diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php index b6c7218680c..d3e202f33c2 100644 --- a/test/phpunit/FactureTest.php +++ b/test/phpunit/FactureTest.php @@ -135,7 +135,6 @@ class FactureTest extends PHPUnit_Framework_TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); $result=$localobject->create($user); - $this->assertLessThan($result, 0); print __METHOD__." result=".$result."\n"; return $result;