From 3e2f39fbc042788b60e7abab2752904a519e0d58 Mon Sep 17 00:00:00 2001 From: phf Date: Tue, 25 Oct 2016 13:31:36 +0200 Subject: [PATCH] Fix on first activate module it must create if needed the first currency rate from general settings --- .../core/modules/modMultiCurrency.class.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/modMultiCurrency.class.php b/htdocs/core/modules/modMultiCurrency.class.php index 7ae613edd49..4928ab5edf4 100644 --- a/htdocs/core/modules/modMultiCurrency.class.php +++ b/htdocs/core/modules/modMultiCurrency.class.php @@ -265,8 +265,14 @@ class modMultiCurrency extends DolibarrModules $sql = array(); //$this->_load_tables('/multicurrency/sql/'); - - return $this->_init($sql, $options); + $res = $this->_init($sql, $options); + + if ($res) + { + $this->createFirstCurrency(); + } + + return $res; } /** @@ -284,5 +290,27 @@ class modMultiCurrency extends DolibarrModules return $this->_remove($sql, $options); } + /** + * Function called when module is enabled + * Create the currency from general setting + * + * @return int 1 if OK, 0 if KO + */ + private function createFirstCurrency() + { + global $conf,$user,$langs; + + if (!MultiCurrency::checkCodeAlreadyExists($conf->currency)) + { + $langs->loadCacheCurrencies(''); + + $multicurrency = new MultiCurrency($this->db); + $multicurrency->code = $conf->currency; + $multicurrency->name = $langs->cache_currencies[$conf->currency]['label'].' ('.$langs->getCurrencySymbol($conf->currency).')'; + $r = $multicurrency->create($user); + + if ($r > 0) $multicurrency->addRate(1); + } + } }