This commit is contained in:
ldestailleur
2025-06-19 15:58:23 +02:00
parent ec8a87a3cb
commit 2cfa986ad5
3 changed files with 20 additions and 19 deletions

View File

@@ -149,8 +149,8 @@ if ($action == 'add_currency') { // Manual insertion of a rate
setEventMessages($langs->trans("SetupSaved"), null);
} else {
// Run the update
$result = $multicurrency->syncRates();
// Run the update o currency rate (this may updates database)
$result = $multicurrency->syncRates(0, 0, '');
if ($result > 0) {
setEventMessages($langs->trans("CurrencyRateSyncSucceed"), null, "mesgs");
} else {

View File

@@ -145,19 +145,19 @@ class modMultiCurrency extends DolibarrModules
$this->cronjobs = array(
0 => array(
'priority'=>61,
'label'=>$langs->trans('MutltiCurrencyAutoUpdateCurrencies'),
'jobtype'=>'method',
'class'=>'multicurrency/class/multicurrency.class.php',
'objectname'=>'MultiCurrency',
'method'=>'syncRates',
'parameters'=>'0,0,cron',
'comment'=>'Update all the currencies using the currencylayer API. An API key needs to be given in the multi-currency module config page to have this job working.<br>First param is not used, Second parameter is 0 to update only already existing currency defined into the Multicurrency module or 1 to add any currency. Third parameter must be "cron".',
'frequency'=>1,
'unitfrequency'=>2678400,
'status'=>$statusatinstall,
'test'=>'isModEnabled("cron")',
'datestart'=>$datestart
'priority' => 61,
'label' => $langs->trans('MutltiCurrencyAutoUpdateCurrencies'),
'jobtype' => 'method',
'class' => 'multicurrency/class/multicurrency.class.php',
'objectname' => 'MultiCurrency',
'method' => 'syncRates',
'parameters' => '0,0,cron',
'comment' => 'Update all the currencies using the currencylayer API. An API key needs to be given in the multi-currency module config page to have this job working.<br>First param is not used, Second parameter is 0 to update only already existing currency defined into the Multicurrency module or 1 to add any currency. Third parameter must be "cron".',
'frequency' => 1,
'unitfrequency' => 2678400,
'status' => $statusatinstall,
'test' => 'isModEnabled("cron")',
'datestart' => $datestart
),
);

View File

@@ -627,10 +627,10 @@ class MultiCurrency extends CommonObject
}
/**
* With free account we can't set source then recalcul all rates to force another source.
* With free account we can't set source to something else than US, to we recalculate all rates to force another source.
* This modify the array &$TRate.
*
* @param stdClass $TRate Object containing all currencies rates
* @param stdClass $TRate Object containing all currencies rates to recalculate
* @return int -1 if KO, 0 if nothing, 1 if OK
*/
public function recalculRates(&$TRate)
@@ -657,12 +657,12 @@ class MultiCurrency extends CommonObject
/**
* Sync rates from API
*
* @param int|string $key No more used
* @param int $nu No more used
* @param int $addifnotfound Add if not found
* @param string $mode "" for standard use, "cron" to use it in a cronjob
* @return int Return integer <0 if KO, >0 if OK, if mode = "cron" OK is 0
*/
public function syncRates($key = '', $addifnotfound = 0, $mode = "")
public function syncRates($nu = 0, $addifnotfound = 0, $mode = "")
{
global $db, $langs;
@@ -698,6 +698,7 @@ class MultiCurrency extends CommonObject
$TRate = $response->quotes;
//$timestamp = $response->timestamp;
// Recalculate rate and update it (or add it) into database
if ($this->recalculRates($TRate) >= 0) {
foreach ($TRate as $currency_code => $rate) {
$code = substr($currency_code, 3, 3);