changeset e27a0d84ba84 in modules/currency:6.0
details: https://hg.tryton.org/modules/currency?cmd=changeset&node=e27a0d84ba84
description:
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
(grafted from 8ed14173be3ae303854a267f6d5c23ed11e09b4f)
diffstat:
currency.py | 3 ++-
tests/scenario_currency_rate_update.rst | 12 ++++++------
2 files changed, 8 insertions(+), 7 deletions(-)
diffs (51 lines):
diff -r 4d69b2cec4b4 -r e27a0d84ba84 currency.py
--- a/currency.py Sat Jun 12 10:06:03 2021 +0200
+++ b/currency.py Thu Jun 17 09:24:19 2021 +0200
@@ -381,7 +381,8 @@
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 -r 4d69b2cec4b4 -r e27a0d84ba84 tests/scenario_currency_rate_update.rst
--- a/tests/scenario_currency_rate_update.rst Sat Jun 12 10:06:03 2021 +0200
+++ b/tests/scenario_currency_rate_update.rst Thu Jun 17 09:24:19 2021 +0200
@@ -9,8 +9,8 @@
>>> 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 @@
>>> 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