Merge pull request #5926 from atm-ph/fix_4.0_create_first_currency

Fix on first activate module it must create if needed the first curre…
This commit is contained in:
Laurent Destailleur 2016-10-26 10:58:02 +02:00 committed by GitHub
commit 413796f1ee

View File

@ -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);
}
}
}