details:   https://code.tryton.org/tryton/commit/14ad0898b7bb
branch:    default
user:      Cédric Krier <[email protected]>
date:      Tue Nov 10 17:08:57 2026 +0100
description:
        Filter out Shopify order id already created when fetching new orders

        It may happen that Shopify returns an order with a lower ID than the 
requested
        ID. This lower ID may already be created as sale in Tryton. So we must 
skip the
        order with ID already set on a sale.

        Closes #15209
diffstat:

 modules/web_shop_shopify/web.py |  20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diffs (40 lines):

diff -r b14ee8eb3def -r 14ad0898b7bb modules/web_shop_shopify/web.py
--- a/modules/web_shop_shopify/web.py   Tue Nov 24 10:19:24 2026 +0100
+++ b/modules/web_shop_shopify/web.py   Tue Nov 10 17:08:57 2026 +0100
@@ -771,12 +771,24 @@
                 QUERY_ORDERS % {
                     'query': query,
                     'fields': graphql.selection(fields),
-                    }).data['orders']
+                    }).data['orders']['nodes']
+
+            # Shopify order by ID using the createAt first
+            # so we must deduplicate existing ids.
+            order_ids = [gid2id(o['id']) for o in orders]
+            existing_sales = Sale.search([
+                    ('web_shop', '=', shop.id),
+                    ('shopify_identifier', 'in', order_ids),
+                    ])
+            existing_order_ids = {s.shopify_identifier for s in existing_sales}
+            orders = [
+                o for o in orders if gid2id(o['id']) not in existing_order_ids]
+
             sales = []
-            for order in orders['nodes']:
+            for order in orders:
                 sales.append(Sale.get_from_shopify(shop, order))
             Sale.save(sales)
-            for sale, order in zip(sales, orders['nodes']):
+            for sale, order in zip(sales, orders):
                 total_price = Decimal(
                     order['currentTotalPriceSet']['presentmentMoney'][
                         'amount'])
@@ -787,7 +799,7 @@
                 s for s in sales if s.party != s.web_shop.guest_party]
             if to_quote:
                 Sale.quote(to_quote)
-            for sale, order in zip(sales, orders['nodes']):
+            for sale, order in zip(sales, orders):
                 if sale.state != 'draft':
                     Payment.get_from_shopify(sale, order)
             Sale.payment_confirm(sales)

Reply via email to