details:   https://code.tryton.org/tryton/commit/565575bb6976
branch:    8.0
user:      Cédric Krier <[email protected]>
date:      Thu Nov 12 10:42:23 2026 +0100
description:
        Use created date filter to fetch Shopify orders by cron

        The cron task is used to catchup missing orders as Shopify may publish 
some
        order with a delay compared to the created date.
        When run from the cron task, the filter is based on the last run of the 
cron.

        #15209
        (grafted from 79cab698dc8d43d91389a20589fc0d864353b4ac)
diffstat:

 modules/web_shop_shopify/web.py |  17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diffs (39 lines):

diff -r 2ffbe01bd29c -r 565575bb6976 modules/web_shop_shopify/web.py
--- a/modules/web_shop_shopify/web.py   Wed Nov 11 11:05:22 2026 +0100
+++ b/modules/web_shop_shopify/web.py   Thu Nov 12 10:42:23 2026 +0100
@@ -768,11 +768,24 @@
         pool = Pool()
         Sale = pool.get('sale.sale')
         Payment = pool.get('account.payment')
+        CronLog = pool.get('ir.cron.log')
         context = Transaction().context
         if shops is None:
             shops = cls.search([
                     ('type', '=', 'shopify'),
                     ])
+        created_at = None
+        if method := context.get('_cron'):
+            logs = CronLog.search([
+                    ('cron.method', '=', method),
+                    ],
+                order=[('started', 'DESC')],
+                limit=1)
+            if logs:
+                log, = logs
+                created_at = log.started
+                # add small gap to catch late publication
+                created_at -= dt.timedelta(seconds=60)
         fields = Sale.shopify_fields()
         cls.lock(shops)
         for shop in shops:
@@ -787,6 +800,10 @@
             if pool.test and 'shopify_orders' in context:
                 query = ' OR '.join(
                     f'id:{id}' for id in context['shopify_orders'])
+            elif created_at is not None and last_order_id:
+                query = (
+                    '-status:cancelled '
+                    f"AND created_at:>='{created_at.isoformat()}Z'")
             elif last_order_id:
                 query = f'-status:cancelled AND id:>{last_order_id}'
             else:

Reply via email to