Fix on first activate module it must create if needed the first currency rate from general settings

This commit is contained in:
phf 2016-10-25 13:31:36 +02:00
parent 6bd219b117
commit 3e2f39fbc0

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