From 2cae99ea4219b52d28c12a255e3582a67a0d38a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 17 Jun 2021 09:24:19 +0200 Subject: [PATCH] Ignore missing rate for date before today The test scenario is updated also to ensure that cron is run at least one day that is not an bank holiday. issue10511 review336421002 --- currency.py | 3 ++- tests/scenario_currency_rate_update.rst | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/currency.py b/currency.py index 164b340012..1cd020b833 100644 --- a/currency.py +++ b/currency.py @@ -381,7 +381,8 @@ class Cron(ModelSQL, ModelView): yield from self._rates(date) except CronFetchError: logger.warning("Could not fetch rates temporary") - break + if date >= datetime.date.today(): + break except Exception: logger.error("Fail to fetch rates", exc_info=True) break diff --git a/tests/scenario_currency_rate_update.rst b/tests/scenario_currency_rate_update.rst index 4cf3ddfe8d..231cbc3904 100644 --- a/tests/scenario_currency_rate_update.rst +++ b/tests/scenario_currency_rate_update.rst @@ -9,8 +9,8 @@ Imports:: >>> from trytond.tests.tools import activate_modules >>> today = dt.date.today() - >>> yesterday = today - dt.timedelta(days=1) - >>> before_yesterday = yesterday - dt.timedelta(days=1) + >>> previous_week = today - dt.timedelta(days=7) + >>> before_previous_week = previous_week - dt.timedelta(days=1) Activate modules:: @@ -36,19 +36,19 @@ Setup cron:: >>> cron.day = None >>> cron.currency = eur >>> cron.currencies.append(Currency(usd.id)) - >>> cron.last_update = before_yesterday + >>> cron.last_update = before_previous_week >>> cron.save() Run update:: >>> cron.click('run') - >>> cron.last_update >= yesterday + >>> cron.last_update >= previous_week True >>> eur.reload() - >>> rate, = [r for r in eur.rates if r.date == yesterday] + >>> rate = [r for r in eur.rates if r.date < today][0] >>> rate.rate Decimal('1.000000') - >>> rate, = [r for r in usd.rates if r.date == yesterday] + >>> rate = [r for r in usd.rates if r.date < today][0] >>> bool(rate.rate) True