Merge pull request #6141 from atm-ph/fix_develop_multicurrency_historisation_rate

Fix no historisation of rate
This commit is contained in:
Laurent Destailleur 2016-12-11 13:18:35 +01:00 committed by GitHub
commit 6fa84206aa

View File

@ -451,24 +451,16 @@ class MultiCurrency extends CommonObject
} }
/** /**
* Update rate in database * Add new entry into llx_multicurrency_rate to historise
* *
* @param double $rate rate value * @param double $rate rate value
* *
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
public function updateRate($rate) public function updateRate($rate)
{
if (is_object($this->rate))
{
$this->rate->rate = $rate;
return $this->rate->update();
}
else
{ {
return $this->addRate($rate); return $this->addRate($rate);
} }
}
/** /**
* Fetch CurrencyRate object in $this->rate * Fetch CurrencyRate object in $this->rate
@ -480,7 +472,7 @@ class MultiCurrency extends CommonObject
$sql = 'SELECT cr.rowid'; $sql = 'SELECT cr.rowid';
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as cr'; $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as cr';
$sql.= ' WHERE cr.fk_multicurrency = '.$this->id; $sql.= ' WHERE cr.fk_multicurrency = '.$this->id;
$sql.= ' AND cr.date_sync >= ALL (SELECT cr2.date_sync FROM '.MAIN_DB_PREFIX.$this->table_element_line.' AS cr2 WHERE cr.rowid = cr2.rowid)'; $sql.= ' AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM '.MAIN_DB_PREFIX.$this->table_element_line.' AS cr2 WHERE cr2.fk_multicurrency = '.$this->id.')';
dol_syslog(__METHOD__,LOG_DEBUG); dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);