Skip to content
This repository was archived by the owner on Oct 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- Added support for Fulfillment.update_tracking ([#432](https://github.com/Shopify/shopify_python_api/pull/432))
- Add FulfillmentEvent resource ([#454](https://github.com/Shopify/shopify_python_api/pull/454))

== Version 8.2.0
- [Feature] Add support for Dynamic API Versioning. When the library is initialized, it will now make a request to
Expand Down
1 change: 1 addition & 0 deletions shopify/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .country import Country
from .refund import Refund
from .fulfillment import Fulfillment, FulfillmentOrders
from .fulfillment_event import FulfillmentEvent
from .fulfillment_service import FulfillmentService
from .carrier_service import CarrierService
from .transaction import Transaction
Expand Down
21 changes: 21 additions & 0 deletions shopify/resources/fulfillment_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from ..base import ShopifyResource

class FulfillmentEvent(ShopifyResource):
_prefix_source = "/orders/$order_id/fulfillments/$fulfillment_id/"
_singular = 'event'
_plural = 'events'

@classmethod
def _prefix(cls, options={}):
order_id = options.get("order_id")
fulfillment_id = options.get('fulfillment_id')
event_id = options.get("event_id")

return "%s/orders/%s/fulfillments/%s" % (
cls.site, order_id, fulfillment_id)

def save(self):
status = self.attributes['status']
if status not in ['label_printed', 'label_purchased', 'attempted_delivery', 'ready_for_pickup', 'picked_up', 'confirmed', 'in_transit', 'out_for_delivery', 'delivered', 'failure']:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if hardcoding a list of accepted status' is the best way to go about this

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for whether to hard code them: Are these likely to change in the future at all/frequently? And is there another way to reference them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No other way to reference status as far as I know

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I didn't think so, but wanted to ask. I would maybe just assign a variable for the array but otherwise if that's the only option, that's the only option 🤷

raise AttributeError("Invalid status")
return super(ShopifyResource, self).save()
22 changes: 22 additions & 0 deletions test/fixtures/fulfillment_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"fulfillment_event": {
"id": 12584341209251,
"fulfillment_id": 2608403447971,
"status": "label_printed",
"message": null,
"happened_at": "2021-01-25T16:32:23-05:00",
"city": null,
"province": null,
"country": null,
"zip": null,
"address1": null,
"latitude": null,
"longitude": null,
"shop_id": 49144037539,
"created_at": "2021-01-25T16:32:23-05:00",
"updated_at": "2021-01-25T16:32:23-05:00",
"estimated_delivery_at": null,
"order_id": 2776493818019,
"admin_graphql_api_id": "gid://shopify/FulfillmentEvent/12584341209251"
}
}
24 changes: 24 additions & 0 deletions test/fulfillment_event_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import shopify
from test.test_helper import TestCase
from pyactiveresource.activeresource import ActiveResource

class FulFillmentEventTest(TestCase):
def test_get_fulfillment_event(self):
self.fake("orders/2776493818019/fulfillments/2608403447971/events", method='GET', body=self.load_fixture('fulfillment_event'))
fulfillment_event = shopify.FulfillmentEvent.find(order_id=2776493818019, fulfillment_id=2608403447971)
self.assertEqual(1, len(fulfillment_event))

def test_create_fulfillment_event(self):
self.fake("orders/2776493818019/fulfillments/2608403447971/events", method='POST', body=self.load_fixture('fulfillment_event'), headers={'Content-type': 'application/json'})
new_fulfillment_event = shopify.FulfillmentEvent({'order_id': '2776493818019', 'fulfillment_id': '2608403447971'})
new_fulfillment_event.status = 'ready_for_pickup'
new_fulfillment_event.save()

def test_error_on_incorrect_status(self):
with self.assertRaises(AttributeError):
self.fake("orders/2776493818019/fulfillments/2608403447971/events/12584341209251", method='GET', body=self.load_fixture('fulfillment_event'))
incorrect_status = 'asdf'
fulfillment_event = shopify.FulfillmentEvent.find(12584341209251, order_id='2776493818019', fulfillment_id='2608403447971')
fulfillment_event.status = incorrect_status
fulfillment_event.save()