Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Updated the docs and fixed the build

NyanKiyoshica618dedd517
diff --git a/docs/architecture/events.rst b/docs/architecture/events.rst
index 7ceed4dd57..42dda74013 100644
--- a/docs/architecture/events.rst
+++ b/docs/architecture/events.rst
@@ -9,46 +9,65 @@ Events
Order Events
------------
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| Code | GraphQL API value | Description |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``placed`` | ``PLACED`` | An order was placed by the customer. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``draft_placed`` | ``PLACED_FROM_DRAFT`` | An order was created from draft by the staff user. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``oversold_items`` | ``OVERSOLD_ITEMS`` | An order was created from draft, but some line items were oversold. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``canceled`` | ``CANCELED`` | The order was cancelled. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``order_paid`` | ``ORDER_PAID`` | The order was fully paid by the customer. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``marked_as_paid`` | ``MARKED_AS_PAID`` | The order was manually marked as fully paid by the staff user. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``updated`` | ``UPDATED`` | The order was updated. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``email_sent`` | ``EMAIL_SENT`` | An email was sent to the customer. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``captured`` | ``CAPTURED`` | The payment was captured. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``refunded`` | ``REFUNDED`` | The payment was refunded. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``voided`` | ``VOIDED`` | The payment was voided. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``fulfillment_canceled`` | ``FULFILLMENT_CANCELED`` | Fulfillment for one or more of the items was canceled. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``restocked_items`` | ``RESTOCKED_ITEMS`` | One or more of the order's items have been resocked |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``fulfilled_items`` | ``FULFILLED_ITEMS`` | One or more of the order's items have been fulfilled. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``note_added`` | ``NOTE_ADDED`` | A note was added to the order by the staff. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
-| ``other`` | ``OTHER`` | Status used during reimporting of the legacy events. |
-+--------------------------+--------------------------+---------------------------------------------------------------------+
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| Code | GraphQL API value | Description | Additional Parameters (GraphQL) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``draft_created`` | ``DRAFT_CREATED`` | A draft order was created by the staff user. | None. |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``draft_added_products`` | ``DRAFT_ADDED_PRODUCTS`` | The staff user added products to a draft order. | ``lines`` a list of objects containing a ``quantity`` (int) and a ``item`` (string) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``draft_removed_products`` | ``DRAFT_REMOVED_PRODUCTS`` | The staff user removed products from a draft order. | ``lines`` a list of objects containing a ``quantity`` (int) and a ``item`` (string) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``placed`` | ``PLACED`` | An order was placed by the customer. | None. |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``draft_placed`` | ``PLACED_FROM_DRAFT`` | An order was created from draft by the staff user. | None. |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``oversold_items`` | ``OVERSOLD_ITEMS`` | An order was created from draft, but some line items were oversold. | ``oversold_items`` a list of items (strings) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``canceled`` | ``CANCELED`` | The order was cancelled. | None. |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``order_paid`` | ``ORDER_PAID`` | The order was fully paid by the customer. | ``amount`` (float), ``payment_id`` (string), ``payment_gateway`` (string) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``marked_as_paid`` | ``MARKED_AS_PAID`` | The order was manually marked as fully paid by the staff user. | None. |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``email_sent`` | ``EMAIL_SENT`` | An email was sent to the customer. | ``email`` (string), ``email_type`` (``OrderEventsEmailsEnum``) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``captured`` | ``CAPTURED`` | The payment was captured. | ``amount`` (float), ``payment_id`` (string), ``payment_gateway`` (string) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``refunded`` | ``REFUNDED`` | The payment was refunded. | ``amount`` (float), ``payment_id`` (string), ``payment_gateway`` (string) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``voided`` | ``VOIDED`` | The payment was voided. | ``amount`` (float), ``payment_id`` (string), ``payment_gateway`` (string) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``payment_failed`` | ``PAYMENT_FAILED`` | The payment failed. | ``message`` (string), ``payment_id`` (string, optional), ``payment_gateway`` (string, optional) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``fulfillment_canceled`` | ``FULFILLMENT_CANCELED`` | Fulfillment for one or more of the items was canceled. | ``composed_id`` (int) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``restocked_items`` | ``RESTOCKED_ITEMS`` | One or more of the order's items have been resocked | ``quantity`` (int) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``fulfilled_items`` | ``FULFILLED_ITEMS`` | One or more of the order's items have been fulfilled. | ``fulfilled_items`` a list of objects containing a ``quantity`` (int) and a ``item`` (string) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``note_added`` | ``NOTE_ADDED`` | A note was added to the order by the staff. | ``message`` (string) |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
+| ``other`` | ``OTHER`` | Status used during reimporting of the legacy events. | None. |
++----------------------------+----------------------------+---------------------------------------------------------------------+-------------------------------------------------------------------------------------------------+
Email Event Types
-----------------
-Fill me...
++------------------------------+----------------------+----------------------------------------------------------------------------------+
+| ``payment_confirmation`` | ``PAYMENT`` | The order has been fully paid. |
++------------------------------+----------------------+----------------------------------------------------------------------------------+
+| ``shipping_confirmation`` | ``SHIPPING`` | The order has been shipped. |
++------------------------------+----------------------+----------------------------------------------------------------------------------+
+| ``tracking_updated`` | ``TRACKING_UPDATED`` | The shipping tracking number has been updated. |
++------------------------------+----------------------+----------------------------------------------------------------------------------+
+| ``order_confirmation`` | ``ORDER`` | The order has been placed. |
++------------------------------+----------------------+----------------------------------------------------------------------------------+
+| ``fulfillment_confirmation`` | ``FULFILLMENT`` | One or more of the order's items have been fulfilled (both physical or digital) |
++------------------------------+----------------------+----------------------------------------------------------------------------------+
+| ``digital_links`` | ``DIGITAL_LINKS`` | The links to the order's digital goods have been sent. |
++------------------------------+----------------------+----------------------------------------------------------------------------------+
+
Events Design
-------------
@@ -74,6 +93,7 @@ Sending Events
To send an event, simply do the following:
.. code-block:: python
+
event = OrderEvent.note_added_event(
order=order, source=user, message='hello world!')
event.save()
@@ -81,6 +101,7 @@ To send an event, simply do the following:
If now you want to send a 'sent email' event you would do the following:
.. code-block:: python
+
event = OrderEvent.email_sent_event(
order=order, email_type=OrderEventsEmails.TRACKING_UPDATED,
source=user)
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 638a3319ee..249cae67df 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -585,7 +585,7 @@ class AddVariantToOrderForm(forms.Form):
quantity = self.cleaned_data.get('quantity')
line = add_variant_to_order(
self.order, variant, quantity, self.discounts, self.taxes)
- OrderEvent.draft_added_products(
+ OrderEvent.draft_added_products_event(
order=self.order, source=user,
order_lines=[(line.quantity, line)]).save()
recalculate_order(self.order)
diff --git a/saleor/events/models/OrderEvent.py b/saleor/events/models/OrderEvent.py
index 4750799a00..5adf48390c 100644
--- a/saleor/events/models/OrderEvent.py
+++ b/saleor/events/models/OrderEvent.py
@@ -84,7 +84,7 @@ class OrderEvent(models.Model):
order=order, type=OrderEvents.DRAFT_CREATED.value, user=source)
@classmethod
- def draft_added_products(
+ def draft_added_products_event(
cls, *,
order: Order, source: User,
order_lines: List[Tuple[int, ProductVariant]]) -> models.Model:
@@ -97,7 +97,7 @@ class OrderEvent(models.Model):
})
@classmethod
- def draft_removed_products(
+ def draft_removed_products_event(
cls, *,
order: Order, source: User,
order_lines: List[Tuple[int, ProductVariant]]
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.py
index b3242fd68b..e646a6ae7b 100644
--- a/saleor/graphql/order/mutations/draft_orders.py
+++ b/saleor/graphql/order/mutations/draft_orders.py
@@ -124,17 +124,19 @@ class DraftOrderCreate(ModelMutation, I18nMixin):
track_inventory=False)
# Add event
- events.append(OrderEvent.draft_added_products(
+ events.append(OrderEvent.draft_added_products_event(
order=instance, source=info.context.user, order_lines=lines))
@classmethod
def _commit_changes(cls, info, instance, cleaned_input, events):
+ created = instance.pk
+ super().save(info, instance, cleaned_input)
+
# Create draft created event if the instance is from scratch
- if not instance.pk:
+ if not created:
events.append(OrderEvent.draft_created_event(
order=instance, source=info.context.user))
- super().save(info, instance, cleaned_input)
instance.save(update_fields=['billing_address', 'shipping_address'])
@classmethod
@@ -287,7 +289,7 @@ class DraftOrderLinesCreate(BaseMutation):
for quantity, variant in lines_to_add]
# Create the event
- OrderEvent.draft_added_products(
+ OrderEvent.draft_added_products_event(
order=order, source=info.context.user, order_lines=lines_to_add)
recalculate_order(order)
@@ -319,7 +321,7 @@ class DraftOrderLineDelete(BaseMutation):
line.id = db_id
# Create the removal event
- OrderEvent.draft_removed_products(
+ OrderEvent.draft_removed_products_event(
order=order, source=info.context.user,
order_lines=[(line.quantity, line)]).save()
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 079f75fbfe..2d5a496a56 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -300,11 +300,11 @@ def change_order_line_quantity(user, line, old_quantity, new_quantity):
# Create the removal event
if quantity_diff > 0:
- OrderEvent.draft_removed_products(
+ OrderEvent.draft_removed_products_event(
order=line.order, source=user,
order_lines=[(quantity_diff, line)]).save()
elif quantity_diff < 0:
- OrderEvent.draft_added_products(
+ OrderEvent.draft_added_products_event(
order=line.order, source=user,
order_lines=[(quantity_diff * -1, line)]).save()