From a0c723970f797bd23a09b66956ea2beb51d32c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 17 Feb 2023 12:07:43 +0100 Subject: [PATCH] Test if Shopify attribute is not empty before using it Shopify seems to have changed from not setting empty attributes to setting them empty. Closes #12097 --- modules/web_shop_shopify/sale.py | 8 ++++---- modules/web_shop_shopify/web.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/web_shop_shopify/sale.py b/modules/web_shop_shopify/sale.py index daa4592f73..c8193eaa68 100644 --- a/modules/web_shop_shopify/sale.py +++ b/modules/web_shop_shopify/sale.py @@ -52,7 +52,7 @@ class Sale(IdentifierMixin, metaclass=PoolMeta): Currency = pool.get('currency.currency') Line = pool.get('sale.line') - if hasattr(order, 'customer'): + if getattr(order, 'customer', None): party = Party.get_from_shopify(shop, order.customer) party.save() party.set_shopify_identifier(shop, order.customer.id) @@ -74,10 +74,10 @@ class Sale(IdentifierMixin, metaclass=PoolMeta): ('code', '=', order.currency), ], limit=1) - if hasattr(order, 'shipping_address'): + if getattr(order, 'shipping_address', None): sale.shipment_address = party.get_address_from_shopify( order.shipping_address) - if hasattr(order, 'billing_address'): + if getattr(order, 'billing_address', None): sale.invoice_address = party.get_address_from_shopify( order.billing_address) @@ -337,7 +337,7 @@ class Line(IdentifierMixin, metaclass=PoolMeta): line.sale = sale line.shopify_identifier = line_item.id assert line.shopify_identifier == line_item.id - if hasattr(line_item, 'variant_id'): + if getattr(line_item, 'variant_id', None): line.product = Product.search_shopify_identifier( sale.web_shop, line_item.variant_id) else: diff --git a/modules/web_shop_shopify/web.py b/modules/web_shop_shopify/web.py index 97f1979053..5551066273 100644 --- a/modules/web_shop_shopify/web.py +++ b/modules/web_shop_shopify/web.py @@ -324,12 +324,12 @@ class Shop(metaclass=PoolMeta): template.set_shopify_identifier(self) for product in template.products: product.set_shopify_identifier(self) - if hasattr(template, 'images'): + if getattr(template, 'images', None): for image in template.images: image.set_shopify_identifier(self) def __shopify_update_images(self, template, shopify_product): - if not hasattr(template, 'images'): + if not getattr(template, 'images', None): return transaction = Transaction() image_ids = set()