changeset 8ed14173be3a in modules/currency:default
details: https://hg.tryton.org/modules/currency?cmd=changeset&node=8ed14173be3a
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
diffstat:

 currency.py                             |   3 ++-
 tests/scenario_currency_rate_update.rst |  12 ++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diffs (51 lines):

diff -r a7ee2b902d34 -r 8ed14173be3a 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 a7ee2b902d34 -r 8ed14173be3a 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

Reply via email to