Skip to content

Commit

Permalink
Merge pull request #78 from onesteinbv/16.0-fix-currency_rate_update_…
Browse files Browse the repository at this point in the history
…coingecko

[FIX] currency_rate_update_coingecko : Changes to handle scenarios when proper data is not received from the api
  • Loading branch information
ByteMeAsap authored Feb 6, 2025
2 parents 5da4584 + 09ceca2 commit 3489bd1
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _get_historical_rate_from_coingecko(self, date_from, date_to, base_currency)
while current_date <= date_to:
content[current_date] = {}
for (
currency
currency
) in self.currency_ids.res_currency_rate_provider_mapping_ids.filtered(
lambda rpm: rpm.provider_service == self.service
):
Expand All @@ -68,19 +68,20 @@ def _get_historical_rate_from_coingecko(self, date_from, date_to, base_currency)
body=_(
'Currency Rate Provider "%(name)s" failed to obtain data(check the rate provider mapping on the currency) :\n%(error)s'
)
% {
"name": self.name,
"currency": currency.currency_id.name,
"error": str(e) if e else _("N/A"),
},
% {
"name": self.name,
"currency": currency.currency_id.name,
"error": str(e) if e else _("N/A"),
},
)
continue
rate = (
coin_data.get("market_data")
.get("current_price")
.get(base_currency.lower(), 0)
)
if rate:
content[current_date].update({currency.currency_id.name: 1 / rate})
if coin_data:
rate = (
coin_data.get("market_data", {})
.get("current_price", {})
.get(base_currency.lower(), 0)
)
if rate:
content[current_date].update({currency.currency_id.name: 1 / rate})
current_date += timedelta(days=1)
return content

0 comments on commit 3489bd1

Please sign in to comment.