From 8f115cac746c3eb15066fa43642adce507e54989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saucisse=20=C3=A0=20roulettes?= Date: Wed, 26 Apr 2023 17:16:21 +0200 Subject: [PATCH 1/8] refactor(Fulfillment): remove _prefix_source and override _prefix method to allow to use both /orders/ prefixed fulfillment endpoints and none prefixed fulfillment endpoints. --- shopify/resources/fulfillment.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index fcf74863..7cdc2fd1 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -3,7 +3,15 @@ class Fulfillment(ShopifyResource): - _prefix_source = "/orders/$order_id/" + @classmethod + def _prefix(cls, options=None): + if options is None: + options = {} + order_id = options.get("order_id") + if order_id: + return "%s/orders/%s" % (cls.site, order_id) + else: + return cls.site def cancel(self): self._load_attributes_from_response(self.post("cancel")) From 0e807bf04f4df5eaaa1f8c6c4ee47c89cdce2049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saucisse=20=C3=A0=20roulettes?= Date: Wed, 26 Apr 2023 17:18:42 +0200 Subject: [PATCH 2/8] refactor(FulfillmentOrder): remove _prefix_source and override _prefix method to allow to use both /orders/ prefixed FulfillmentOrder endpoints and none prefixed FulfillmentOrder endpoints. --- shopify/resources/fulfillment.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index 7cdc2fd1..c64e817f 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -29,7 +29,15 @@ def update_tracking(self, tracking_info, notify_customer): class FulfillmentOrders(ShopifyResource): - _prefix_source = "/orders/$order_id/" + @classmethod + def _prefix(cls, options=None): + if options is None: + options = {} + order_id = options.get("order_id") + if order_id: + return "%s/orders/%s" % (cls.site, order_id) + else: + return cls.site class FulfillmentV2(ShopifyResource): From 8ccfa00002fad310478765b16dd690287d3c016e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saucisse=20=C3=A0=20roulettes?= Date: Wed, 26 Apr 2023 17:21:07 +0200 Subject: [PATCH 3/8] refactor(Fulfillment): remove FulfillmentV2 and move update_tracking method to fulfillment because it is no more needed since i have removed _prefix_source attribute definition. --- shopify/resources/fulfillment.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index c64e817f..a1924fc5 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -23,9 +23,8 @@ def open(self): self._load_attributes_from_response(self.post("open")) def update_tracking(self, tracking_info, notify_customer): - fulfill = FulfillmentV2() - fulfill.id = self.id - self._load_attributes_from_response(fulfill.update_tracking(tracking_info, notify_customer)) + body = {"fulfillment": {"tracking_info": tracking_info, "notify_customer": notify_customer}} + return self.post("update_tracking", json.dumps(body).encode()) class FulfillmentOrders(ShopifyResource): @@ -38,12 +37,3 @@ def _prefix(cls, options=None): return "%s/orders/%s" % (cls.site, order_id) else: return cls.site - - -class FulfillmentV2(ShopifyResource): - _singular = "fulfillment" - _plural = "fulfillments" - - def update_tracking(self, tracking_info, notify_customer): - body = {"fulfillment": {"tracking_info": tracking_info, "notify_customer": notify_customer}} - return self.post("update_tracking", json.dumps(body).encode()) From 79d0ea2b23cc8345baa2a18e198d2c03666a0db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saucisse=20=C3=A0=20roulettes?= Date: Wed, 26 Apr 2023 19:09:18 +0200 Subject: [PATCH 4/8] replaced(Fulfillment): _prefix override by _split_options override allowing specifying optional and mutliple prefix sources --- shopify/resources/fulfillment.py | 40 ++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index a1924fc5..b9584059 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -1,17 +1,21 @@ -from ..base import ShopifyResource import json +from ..base import ShopifyResource + class Fulfillment(ShopifyResource): + _prefix_sources = { + ("order_id",): "/orders/$order_id/", + ("fulfillment_order_id",): "/fulfillment_orders/$fulfillment_order_id/", + } + @classmethod - def _prefix(cls, options=None): - if options is None: - options = {} - order_id = options.get("order_id") - if order_id: - return "%s/orders/%s" % (cls.site, order_id) - else: - return cls.site + def _split_options(cls, options): + if cls._prefix_sources and options: + if cls._prefix_sources.get(tuple(options)): + cls._prefix_source = cls._prefix_sources[tuple(options)] + + return super()._split_options(options) def cancel(self): self._load_attributes_from_response(self.post("cancel")) @@ -28,12 +32,14 @@ def update_tracking(self, tracking_info, notify_customer): class FulfillmentOrders(ShopifyResource): + _prefix_sources = { + ("order_id",): "/orders/$order_id/", + } + @classmethod - def _prefix(cls, options=None): - if options is None: - options = {} - order_id = options.get("order_id") - if order_id: - return "%s/orders/%s" % (cls.site, order_id) - else: - return cls.site + def _split_options(cls, options): + if cls._prefix_sources and options: + if cls._prefix_sources.get(tuple(options)): + cls._prefix_source = cls._prefix_sources[tuple(options)] + + return super()._split_options(options) From 8a4d9ddb3d121a2212a4a2f05fa003022f1825ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saucisse=20=C3=A0=20roulettes?= Date: Wed, 26 Apr 2023 19:11:21 +0200 Subject: [PATCH 5/8] replaced(Fulfillment): _prefix override by _split_options override allowing specifying optional and mutliple prefix sources --- shopify/resources/fulfillment.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index b9584059..b1f44785 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -12,8 +12,9 @@ class Fulfillment(ShopifyResource): @classmethod def _split_options(cls, options): if cls._prefix_sources and options: - if cls._prefix_sources.get(tuple(options)): - cls._prefix_source = cls._prefix_sources[tuple(options)] + options_tuples = tuple(options) + if options_tuples in cls._prefix_sources: + cls._prefix_source = cls._prefix_sources[options_tuples] return super()._split_options(options) @@ -39,7 +40,8 @@ class FulfillmentOrders(ShopifyResource): @classmethod def _split_options(cls, options): if cls._prefix_sources and options: - if cls._prefix_sources.get(tuple(options)): + options_tuples = tuple(options) + if options_tuples in cls._prefix_sources: cls._prefix_source = cls._prefix_sources[tuple(options)] return super()._split_options(options) From f9fe8a6fd5adb1fbb7b2d309936205aa15311092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saucisse=20=C3=A0=20roulettes?= Date: Wed, 26 Apr 2023 19:13:55 +0200 Subject: [PATCH 6/8] trigger cla --- shopify/resources/fulfillment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index b1f44785..244207ae 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -8,7 +8,7 @@ class Fulfillment(ShopifyResource): ("order_id",): "/orders/$order_id/", ("fulfillment_order_id",): "/fulfillment_orders/$fulfillment_order_id/", } - + # cla @classmethod def _split_options(cls, options): if cls._prefix_sources and options: From 8145fc22179a2e6e716cc8fbee6923062888c69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saucisse=20=C3=A0=20roulettes?= Date: Wed, 26 Apr 2023 19:13:55 +0200 Subject: [PATCH 7/8] trigger cla --- shopify/resources/fulfillment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index b1f44785..244207ae 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -8,7 +8,7 @@ class Fulfillment(ShopifyResource): ("order_id",): "/orders/$order_id/", ("fulfillment_order_id",): "/fulfillment_orders/$fulfillment_order_id/", } - + # cla @classmethod def _split_options(cls, options): if cls._prefix_sources and options: From bd3b6d04e526d2805f4d546f541925d52afe08dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saucisse=20=C3=A0=20roulettes?= Date: Wed, 26 Apr 2023 19:18:40 +0200 Subject: [PATCH 8/8] remove(Fulfillment): useless comment --- shopify/resources/fulfillment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shopify/resources/fulfillment.py b/shopify/resources/fulfillment.py index 244207ae..b1f44785 100644 --- a/shopify/resources/fulfillment.py +++ b/shopify/resources/fulfillment.py @@ -8,7 +8,7 @@ class Fulfillment(ShopifyResource): ("order_id",): "/orders/$order_id/", ("fulfillment_order_id",): "/fulfillment_orders/$fulfillment_order_id/", } - # cla + @classmethod def _split_options(cls, options): if cls._prefix_sources and options: