void insertarTipoCambio(TransDate _fechadesde,
amount _tipoCambio)
{
ExchangeRate exchangeRate;
//TmpExchangeRate currentTmpExchangeRate = this.cursor();
ExchangeRateCurrencyPair selectedCurrencyPair;
ExchangeRateType ExchangeRateType = ExchangeRateType::findByName('Tipo de cambio');
;
select forUpdate firstOnly selectedCurrencyPair
where selectedCurrencyPair.ExchangeRateType == ExchangeRateType.RecId &&
selectedCurrencyPair.FromCurrencyCode == 'USD' &&
selectedCurrencyPair.ToCurrencyCode == 'MXN';
if(selectedCurrencyPair)
{
select forUpdate firstOnly * from exchangeRate
where exchangeRate.ValidFrom == _fechadesde &&
exchangeRate.ExchangeRateCurrencyPair == selectedCurrencyPair.RecId;
//exchangeRate = exchangeRate::findByDate(selectedCurrencyPair.RecId,_fechadesde,true);
//exchangeRate = ExchangeRate::find(currentTmpExchangeRate.ExchangeRateRecId, true);
ttsbegin;
exchangeRate.ExchangeRate = ExchangeRateHelper::prepareExchangeRateForStorage_Static(
_tipoCambio,
selectedCurrencyPair.ExchangeRateDisplayFactor);
if (exchangeRate)
{
exchangeRate.update();
}
else
{
// Insert into the ExchangeRate table
exchangeRate.ExchangeRateCurrencyPair = selectedCurrencyPair.RecId;
exchangeRate.ValidFrom = _fechadesde;
exchangeRate.insert();
//currentTmpExchangeRate.ExchangeRateRecId = exchangeRate.RecId;
}
ttsCommit;
info("Tipo de cambio actualizado ",con2Str([_fechadesde,_tipoCambio]));
}
}