diff --git a/shopify_integration/payouts.py b/shopify_integration/payouts.py index 56e7655..b528d6f 100644 --- a/shopify_integration/payouts.py +++ b/shopify_integration/payouts.py @@ -69,7 +69,8 @@ def create_shopify_payouts(shop_name: str, start_date: str = str()): **{"shop_name": shop_name, "payout_id": payout.id}, ) - frappe.db.set_value("Shopify Settings", shop_name, "last_sync_datetime", now()) + shopify_settings.last_sync_datetime = now() + shopify_settings.save() def create_shopify_payout(shop_name: str, payout_id: str): diff --git a/shopify_integration/shopify_integration/doctype/shopify_settings/shopify_settings.py b/shopify_integration/shopify_integration/doctype/shopify_settings/shopify_settings.py index 63620ac..d56b6de 100644 --- a/shopify_integration/shopify_integration/doctype/shopify_settings/shopify_settings.py +++ b/shopify_integration/shopify_integration/doctype/shopify_settings/shopify_settings.py @@ -176,12 +176,24 @@ def register_webhooks(self): SHOPIFY_WEBHOOK_TOPIC_MAPPER, ) - for topic in SHOPIFY_WEBHOOK_TOPIC_MAPPER: - with self.get_shopify_session(temp=True): - webhook = Webhook.create( - {"topic": topic, "address": get_webhook_url(), "format": "json"} - ) - + webhooks = [] + + try: + webhooks = self.get_webhooks() + except Exception as e: + make_shopify_log( + shop_name=self.name, status="Error", exception=e, rollback=True + ) + + if not webhooks: + for topic in SHOPIFY_WEBHOOK_TOPIC_MAPPER: + with self.get_shopify_session(temp=True): + webhooks.append(Webhook.create( + {"topic": topic, "address": get_webhook_url(), "format": "json"} + )) + + webhook: Webhook + for webhook in webhooks: if webhook.is_valid(): self.append( "webhooks", {"webhook_id": webhook.id, "method": webhook.topic}