Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Extend order with origin and original order values (#7326)
Iga Karbowiak7a70453b16a1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b5698216a4..668331446b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -71,6 +71,7 @@ All notable, unreleased changes to this project will be documented in this file.- Fix draft order tax mismatch - #7226 by @IKarbowiak- Introduce `calculate_order_line_total` plugin method- Raise ValidationError when refund cannot be performed - #7260 by @IKarbowiak+- Extend order with origin and original order values - #7326 by @IKarbowiak### Breaking- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysockidiff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.pyindex e1d2875e93..dcb1c42cc9 100644--- a/saleor/checkout/complete_checkout.py+++ b/saleor/checkout/complete_checkout.py@@ -26,7 +26,7 @@ from ..discount.utils import (from ..graphql.checkout.utils import (prepare_insufficient_stock_checkout_validation_error,)-from ..order import OrderLineData, OrderStatus+from ..order import OrderLineData, OrderOrigin, OrderStatusfrom ..order.actions import order_createdfrom ..order.models import Order, OrderLinefrom ..order.notifications import send_order_confirmation@@ -367,6 +367,7 @@ def _create_order(**order_data,checkout_token=checkout.token,status=status,+ origin=OrderOrigin.CHECKOUT,channel=checkout_info.channel,)if checkout.discount:diff --git a/saleor/graphql/checkout/tests/test_checkout_complete.py b/saleor/graphql/checkout/tests/test_checkout_complete.pyindex 5a31dff6e4..57e0072c90 100644--- a/saleor/graphql/checkout/tests/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/test_checkout_complete.py@@ -10,7 +10,7 @@ from ....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ....checkout.models import Checkoutfrom ....core.exceptions import InsufficientStock, InsufficientStockDatafrom ....core.taxes import zero_money-from ....order import OrderStatus+from ....order import OrderOrigin, OrderStatusfrom ....order.models import Orderfrom ....payment import ChargeStatus, PaymentError, TransactionKindfrom ....payment.gateways.dummy_credit_card import TOKEN_VALIDATION_MAPPING@@ -26,6 +26,8 @@ MUTATION_CHECKOUT_COMPLETE = """order {id,token+ original+ origin},errors {field,@@ -81,9 +83,11 @@ def test_checkout_complete_order_already_exists(data = content["data"]["checkoutComplete"]assert not data["errors"]- order_token = data["order"]["token"]+ order_data = data["order"]assert Order.objects.count() == orders_count- assert order_with_lines.token == order_token+ assert order_with_lines.token == order_data["token"]+ assert order_data["origin"] == order_with_lines.origin.upper()+ assert not order_data["original"]def test_checkout_complete_with_inactive_channel_order_already_exists(@@ -218,6 +222,8 @@ def test_checkout_complete(assert Order.objects.count() == orders_count + 1order = Order.objects.first()assert order.status == OrderStatus.UNFULFILLED+ assert order.origin == OrderOrigin.CHECKOUT+ assert not order.originalassert order.token == order_tokenassert order.redirect_url == redirect_urlassert order.total.gross == total.grossdiff --git a/saleor/graphql/order/enums.py b/saleor/graphql/order/enums.pyindex 9b3c17aae2..1ae5fde196 100644--- a/saleor/graphql/order/enums.py+++ b/saleor/graphql/order/enums.py@@ -1,10 +1,11 @@import graphenefrom ...graphql.core.enums import to_enum-from ...order import OrderEvents, OrderEventsEmails+from ...order import OrderEvents, OrderEventsEmails, OrderOriginOrderEventsEnum = to_enum(OrderEvents)OrderEventsEmailsEnum = to_enum(OrderEventsEmails)+OrderOriginEnum = to_enum(OrderOrigin)class OrderStatusFilter(graphene.Enum):diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex 86f2ca6be5..4812f8f172 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -9,7 +9,7 @@ from ....core.exceptions import InsufficientStockfrom ....core.permissions import OrderPermissionsfrom ....core.taxes import TaxError, zero_taxed_moneyfrom ....core.utils.url import validate_storefront_url-from ....order import OrderLineData, OrderStatus, events, models+from ....order import OrderLineData, OrderOrigin, OrderStatus, events, modelsfrom ....order.actions import order_createdfrom ....order.error_codes import OrderErrorCodefrom ....order.utils import (@@ -171,6 +171,7 @@ class DraftOrderCreate(ModelMutation, I18nMixin):cleaned_input["quantities"] = quantitiescleaned_input["status"] = OrderStatus.DRAFT+ cleaned_input["origin"] = OrderOrigin.DRAFTdisplay_gross_prices = info.context.site.settings.display_gross_pricescleaned_input["display_gross_prices"] = display_gross_pricesdiff --git a/saleor/graphql/order/tests/test_fulfillment_return_products.py b/saleor/graphql/order/tests/test_fulfillment_return_products.pyindex 1ec10d71c0..1422f74cc5 100644--- a/saleor/graphql/order/tests/test_fulfillment_return_products.py+++ b/saleor/graphql/order/tests/test_fulfillment_return_products.py@@ -5,7 +5,7 @@ import graphenefrom prices import Money, TaxedMoneyfrom ....core.prices import quantize_price-from ....order import OrderStatus+from ....order import OrderOrigin, OrderStatusfrom ....order.error_codes import OrderErrorCodefrom ....order.models import FulfillmentStatus, Orderfrom ....payment import ChargeStatus, PaymentError@@ -49,6 +49,8 @@ mutation OrderFulfillmentReturnProducts(replaceOrder{idstatus+ original+ origin}errors {field@@ -238,6 +240,8 @@ def test_fulfillment_return_products_order_lines(assert replace_fulfillment["lines"][0]["quantity"] == line_quantity_to_replaceassert replace_order["status"] == OrderStatus.DRAFT.upper()+ assert replace_order["origin"] == OrderOrigin.REISSUE.upper()+ assert replace_order["original"] == order_idreplace_order = Order.objects.get(status=OrderStatus.DRAFT)assert replace_order.lines.count() == 1replaced_line = replace_order.lines.get()@@ -453,6 +457,9 @@ def test_fulfillment_return_products_fulfillment_lines(assert replace_fulfillment["lines"][0]["quantity"] == quantity_to_replaceassert replace_order["status"] == OrderStatus.DRAFT.upper()+ assert replace_order["origin"] == OrderOrigin.REISSUE.upper()+ assert replace_order["original"] == order_id+replace_order = Order.objects.get(status=OrderStatus.DRAFT)assert replace_order.lines.count() == 1replaced_line = replace_order.lines.get()@@ -717,6 +724,9 @@ def test_fulfillment_return_products_fulfillment_lines_and_order_lines(assert replace_fulfillment["lines"][0]["quantity"] == 1assert replace_order["status"] == OrderStatus.DRAFT.upper()+ assert replace_order["origin"] == OrderOrigin.REISSUE.upper()+ assert replace_order["original"] == order_id+replace_order = Order.objects.get(status=OrderStatus.DRAFT)assert replace_order.lines.count() == 1replaced_line = replace_order.lines.get()diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex db706e3118..8010c140c4 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -20,7 +20,7 @@ from ....core.notify_events import NotifyEventTypefrom ....core.prices import quantize_pricefrom ....core.taxes import TaxError, zero_taxed_moneyfrom ....discount.models import OrderDiscount-from ....order import FulfillmentStatus, OrderStatus+from ....order import FulfillmentStatus, OrderOrigin, OrderStatusfrom ....order import events as order_eventsfrom ....order.error_codes import OrderErrorCodefrom ....order.events import order_replacement_created@@ -2598,6 +2598,7 @@ DRAFT_ORDER_COMPLETE_MUTATION = """}order {status+ origin}}}@@ -2627,6 +2628,53 @@ def test_draft_order_complete(data = content["data"]["draftOrderComplete"]["order"]order.refresh_from_db()assert data["status"] == order.status.upper()+ assert data["origin"] == OrderOrigin.DRAFT.upper()++ for line in order.lines.all():+ allocation = line.allocations.get()+ assert allocation.quantity_allocated == line.quantity_unfulfilled++ # ensure there are only 2 events with correct types+ event_params = {+ "user": staff_user,+ "type__in": [+ order_events.OrderEvents.PLACED_FROM_DRAFT,+ order_events.OrderEvents.CONFIRMED,+ ],+ "parameters": {},+ }+ matching_events = OrderEvent.objects.filter(**event_params)+ assert matching_events.count() == 2+ assert matching_events[0].type != matching_events[1].type+ assert not OrderEvent.objects.exclude(**event_params).exists()+++def test_draft_order_from_reissue_complete(+ staff_api_client,+ permission_manage_orders,+ staff_user,+ draft_order,+):+ order = draft_order+ order.origin = OrderOrigin.REISSUE+ order.save(update_fields=["origin"])++ # Ensure no events were created+ assert not OrderEvent.objects.exists()++ # Ensure no allocation were created+ assert not Allocation.objects.filter(order_line__order=order).exists()++ order_id = graphene.Node.to_global_id("Order", order.id)+ variables = {"id": order_id}+ response = staff_api_client.post_graphql(+ DRAFT_ORDER_COMPLETE_MUTATION, variables, permissions=[permission_manage_orders]+ )+ content = get_graphql_content(response)+ data = content["data"]["draftOrderComplete"]["order"]+ order.refresh_from_db()+ assert data["status"] == order.status.upper()+ assert data["origin"] == OrderOrigin.REISSUE.upper()for line in order.lines.all():allocation = line.allocations.get()@@ -2751,6 +2799,7 @@ def test_draft_order_complete_product_without_inventory_tracking(order.refresh_from_db()assert data["status"] == order.status.upper()+ assert data["origin"] == OrderOrigin.DRAFT.upper()assert not Allocation.objects.filter(order_line__order=order).exists()@@ -2827,6 +2876,7 @@ def test_draft_order_complete_out_of_stock_variant(error = content["data"]["draftOrderComplete"]["errors"][0]order.refresh_from_db()assert order.status == OrderStatus.DRAFT+ assert order.origin == OrderOrigin.DRAFTassert error["field"] == "lines"assert error["code"] == OrderErrorCode.INSUFFICIENT_STOCK.name@@ -2908,6 +2958,7 @@ def test_draft_order_complete_drops_shipping_address(order.refresh_from_db()assert data["status"] == order.status.upper()+ assert data["origin"] == OrderOrigin.DRAFT.upper()assert order.shipping_address is None@@ -2938,6 +2989,7 @@ def test_draft_order_complete_unavailable_for_purchase(error = content["data"]["draftOrderComplete"]["errors"][0]order.refresh_from_db()assert order.status == OrderStatus.DRAFT+ assert order.origin == OrderOrigin.DRAFTassert error["field"] == "lines"assert error["code"] == OrderErrorCode.PRODUCT_UNAVAILABLE_FOR_PURCHASE.namediff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 06c23e285b..880d63c593 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -67,7 +67,7 @@ from .dataloaders import (OrderLineByIdLoader,OrderLinesByOrderIdLoader,)-from .enums import OrderEventsEmailsEnum, OrderEventsEnum+from .enums import OrderEventsEmailsEnum, OrderEventsEnum, OrderOriginEnumfrom .utils import validate_draft_order@@ -579,6 +579,10 @@ class Order(CountableDjangoObjectType):Invoice, required=False, description="List of order invoices.")number = graphene.String(description="User-friendly number of an order.")+ original = graphene.ID(+ description="The ID of the order that was the base for this order."+ )+ origin = OrderOriginEnum(description="The order origin.", required=True)is_paid = graphene.Boolean(description="Informs if an order is fully paid.", required=True)@@ -1082,3 +1086,10 @@ class Order(CountableDjangoObjectType):@traced_resolverdef resolve_language_code_enum(root, _info, **_kwargs):return LanguageCodeEnum[str_to_enum(root.language_code)]++ @staticmethod+ @traced_resolver+ def resolve_original(root, info, **_kwargs):+ if not root.original_id:+ return None+ return graphene.Node.to_global_id("Order", root.original_id)diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex ab92033226..7ee2294ef4 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2974,6 +2974,8 @@ type Order implements Node & ObjectWithMetadata {availableShippingMethods: [ShippingMethod]invoices: [Invoice]number: String+ original: ID+ origin: OrderOriginEnum!isPaid: Boolean!paymentStatus: PaymentChargeStatusEnum!paymentStatusDisplay: String!@@ -3358,6 +3360,12 @@ type OrderMarkAsPaid {errors: [OrderError!]!}+enum OrderOriginEnum {+ CHECKOUT+ DRAFT+ REISSUE+}+type OrderRefund {order: OrderorderErrors: [OrderError!]! @deprecated(reason: "Use errors field instead. This field will be removed in Saleor 4.0.")diff --git a/saleor/order/__init__.py b/saleor/order/__init__.pyindex b037d00db3..f000a17990 100644--- a/saleor/order/__init__.py+++ b/saleor/order/__init__.py@@ -35,6 +35,18 @@ class OrderStatus:]+class OrderOrigin:+ CHECKOUT = "checkout" # order created from checkout+ DRAFT = "draft" # order created from draft order+ REISSUE = "reissue" # order created from reissue existing one++ CHOICES = [+ (CHECKOUT, "Checkout"),+ (DRAFT, "Draft"),+ (REISSUE, "Reissue"),+ ]++class FulfillmentStatus:FULFILLED = "fulfilled" # group of products in an order marked as fulfilledREFUNDED = "refunded" # group of refunded productsdiff --git a/saleor/order/actions.py b/saleor/order/actions.pyindex 290e1e32e4..3b7b42282b 100644--- a/saleor/order/actions.py+++ b/saleor/order/actions.py@@ -31,6 +31,7 @@ from . import (FulfillmentLineData,FulfillmentStatus,OrderLineData,+ OrderOrigin,OrderStatus,events,utils,@@ -753,6 +754,8 @@ def _populate_replace_order_fields(original_order: "Order"):replace_order.channel = original_order.channelreplace_order.display_gross_prices = original_order.display_gross_pricesreplace_order.redirect_url = original_order.redirect_url+ replace_order.original = original_order+ replace_order.origin = OrderOrigin.REISSUEif original_order.billing_address:original_order.billing_address.pk = None@@ -780,7 +783,7 @@ def create_replace_order(order_line_to_create: Dict[OrderLineIDType, OrderLine] = dict()# iterate over lines without fulfillment to get the items for replace.- # deepcopy to not lose the refence for lines assigned to original order+ # deepcopy to not lose the reference for lines assigned to original orderfor line_data in deepcopy(order_lines_to_replace):order_line = line_data.lineorder_line_id = order_line.pkdiff --git a/saleor/order/migrations/0106_auto_20210511_0825.py b/saleor/order/migrations/0106_auto_20210511_0825.pynew file mode 100644index 0000000000..dd59a2adce--- /dev/null+++ b/saleor/order/migrations/0106_auto_20210511_0825.py@@ -0,0 +1,72 @@+# Generated by Django 3.1.8 on 2021-05-11 08:25++import django.db.models.deletion+from django.db import migrations, models+++def set_origin_and_original_order_values(apps, schema_editor):+ Order = apps.get_model("order", "Order")+ draft_events = ["placed_from_draft", "draft_created"]+ Order.objects.filter(events__type__in=draft_events).update(origin="draft")+ orders = []+ for order in Order.objects.filter(+ events__type="draft_created_from_replace"+ ).iterator():+ order.origin = "reissue"+ order.original_id = order.events.get(+ type="draft_created_from_replace"+ ).parameters.get("related_order_pk")+ orders.append(order)+ Order.objects.bulk_update(orders, ["origin", "original"])+ Order.objects.exclude(+ events__type__in=draft_events + ["draft_created_from_replace"]+ ).update(origin="checkout")+++class Migration(migrations.Migration):++ dependencies = [+ ("order", "0105_order_total_paid_amount"),+ ]++ operations = [+ migrations.AddField(+ model_name="order",+ name="origin",+ field=models.CharField(+ blank=True,+ choices=[+ ("checkout", "Checkout"),+ ("draft", "Draft"),+ ("reissue", "Reissue"),+ ],+ max_length=32,+ null=True,+ ),+ ),+ migrations.AddField(+ model_name="order",+ name="original",+ field=models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ to="order.order",+ ),+ ),+ migrations.RunPython(+ set_origin_and_original_order_values, migrations.RunPython.noop+ ),+ migrations.AlterField(+ model_name="order",+ name="origin",+ field=models.CharField(+ choices=[+ ("checkout", "Checkout"),+ ("draft", "Draft"),+ ("reissue", "Reissue"),+ ],+ max_length=32,+ ),+ ),+ ]diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 074b556f48..0c1864dc32 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -31,7 +31,7 @@ from ..payment import ChargeStatus, TransactionKindfrom ..payment.model_helpers import get_subtotal, get_total_authorizedfrom ..payment.models import Paymentfrom ..shipping.models import ShippingMethod-from . import FulfillmentStatus, OrderEvents, OrderStatus+from . import FulfillmentStatus, OrderEvents, OrderOrigin, OrderStatusclass OrderQueryset(models.QuerySet):@@ -107,6 +107,10 @@ class Order(ModelWithMetadata):Address, related_name="+", editable=False, null=True, on_delete=models.SET_NULL)user_email = models.EmailField(blank=True, default="")+ original = models.ForeignKey(+ "self", null=True, blank=True, on_delete=models.SET_NULL+ )+ origin = models.CharField(max_length=32, choices=OrderOrigin.CHOICES)currency = models.CharField(max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,diff --git a/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py b/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.pyindex c07233eebb..02329a8ef4 100644--- a/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py+++ b/saleor/order/tests/test_order_actions_create_fulfillments_for_returned_products.py@@ -6,7 +6,13 @@ from prices import Money, TaxedMoneyfrom ...plugins.manager import get_plugins_managerfrom ...tests.utils import flush_post_commit_hooksfrom ...warehouse.models import Allocation, Stock-from .. import FulfillmentLineData, FulfillmentStatus, OrderEvents, OrderLineData+from .. import (+ FulfillmentLineData,+ FulfillmentStatus,+ OrderEvents,+ OrderLineData,+ OrderOrigin,+)from ..actions import create_fulfillments_for_returned_productsfrom ..models import Fulfillment, FulfillmentLine@@ -273,6 +279,8 @@ def test_create_return_fulfillment_only_order_lines_with_replace_request(replace_order.billing_address.id = Noneorder_with_lines.billing_address.id = Noneassert replace_order.billing_address == order_with_lines.billing_address+ assert replace_order.original == order_with_lines+ assert replace_order.origin == OrderOrigin.REISSUEexpected_replaced_line = order_lines_to_return[0]diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex 69cbf7ed3f..6e99b70cb3 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -57,7 +57,7 @@ from ..discount.models import ()from ..giftcard.models import GiftCardfrom ..menu.models import Menu, MenuItem, MenuItemTranslation-from ..order import OrderLineData, OrderStatus+from ..order import OrderLineData, OrderOrigin, OrderStatusfrom ..order.actions import cancel_fulfillment, fulfill_order_linesfrom ..order.events import (OrderEvents,@@ -577,6 +577,7 @@ def order(customer_user, channel_USD):shipping_address=address,user_email=customer_user.email,user=customer_user,+ origin=OrderOrigin.CHECKOUT,)@@ -1999,6 +2000,7 @@ def order_list(customer_user, channel_USD):"user": customer_user,"user_email": customer_user.email,"channel": channel_USD,+ "origin": OrderOrigin.CHECKOUT,}order = Order.objects.create(**data)order1 = Order.objects.create(**data)@@ -2213,6 +2215,7 @@ def order_line_with_allocation_in_many_stocks(user_email=customer_user.email,user=customer_user,channel=channel_USD,+ origin=OrderOrigin.CHECKOUT,)product = variant.product@@ -2257,6 +2260,7 @@ def order_line_with_one_allocation(user_email=customer_user.email,user=customer_user,channel=channel_USD,+ origin=OrderOrigin.CHECKOUT,)product = variant.product@@ -2480,6 +2484,7 @@ def order_with_lines_channel_PLN(shipping_address=address,user_email=customer_user.email,user=customer_user,+ origin=OrderOrigin.CHECKOUT,)product = Product.objects.create(name="Test product in PLN channel",@@ -2708,7 +2713,8 @@ def fulfillment(fulfilled_order):def draft_order(order_with_lines):Allocation.objects.filter(order_line__order=order_with_lines).delete()order_with_lines.status = OrderStatus.DRAFT- order_with_lines.save(update_fields=["status"])+ order_with_lines.origin = OrderOrigin.DRAFT+ order_with_lines.save(update_fields=["status", "origin"])return order_with_lines@@ -2731,7 +2737,8 @@ def draft_order_with_fixed_discount_order(draft_order):@pytest.fixturedef draft_order_without_inventory_tracking(order_with_line_without_inventory_tracking):order_with_line_without_inventory_tracking.status = OrderStatus.DRAFT- order_with_line_without_inventory_tracking.save(update_fields=["status"])+ order_with_line_without_inventory_tracking.origin = OrderStatus.DRAFT+ order_with_line_without_inventory_tracking.save(update_fields=["status", "origin"])return order_with_line_without_inventory_trackingdiff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.pyindex a183787b33..05d8299e64 100644--- a/saleor/webhook/payloads.py+++ b/saleor/webhook/payloads.py@@ -50,6 +50,7 @@ ADDRESS_FIELDS = (ORDER_FIELDS = ("created","status",+ "origin","user_email","shipping_method_name","shipping_price_net_amount",@@ -147,7 +148,10 @@ def generate_order_payload(order: "Order"):"fulfillments": (lambda o: o.fulfillments.all(), fulfillment_fields),"discounts": (lambda o: o.discounts.all(), discount_fields),},- extra_dict_data={"lines": json.loads(generate_order_lines_payload(lines))},+ extra_dict_data={+ "original": graphene.Node.to_global_id("Order", order.original_id),+ "lines": json.loads(generate_order_lines_payload(lines)),+ },)return order_datadiff --git a/saleor/webhook/tests/test_webhook_payloads.py b/saleor/webhook/tests/test_webhook_payloads.pyindex a4ac2c6a2c..a2904709af 100644--- a/saleor/webhook/tests/test_webhook_payloads.py+++ b/saleor/webhook/tests/test_webhook_payloads.py@@ -6,6 +6,8 @@ from unittest.mock import ANYimport graphenefrom ...discount import DiscountValueType, OrderDiscountType+from ...order import OrderOrigin+from ...order.models import Orderfrom ...product.models import ProductVariantfrom ..payloads import (ORDER_FIELDS,@@ -19,6 +21,14 @@ from ..payloads import (def test_generate_order_payload(order_with_lines, fulfilled_order, payment_txn_captured):+ new_order = Order.objects.create(+ channel=order_with_lines.channel,+ billing_address=order_with_lines.billing_address,+ )+ order_with_lines.origin = OrderOrigin.REISSUE+ order_with_lines.original = new_order+ order_with_lines.save(update_fields=["origin", "original"])+order_with_lines.discounts.create(type=OrderDiscountType.MANUAL,value_type=DiscountValueType.PERCENTAGE,@@ -49,6 +59,7 @@ def test_generate_order_payload(assert payload.get("billing_address")assert payload.get("fulfillments")assert payload.get("discounts")+ assert payload.get("original") == graphene.Node.to_global_id("Order", new_order.pk)def test_order_lines_have_all_required_fields(order, order_line_with_one_allocation):@@ -186,6 +197,8 @@ def test_generate_product_variant_deleted_payload(def test_generate_invoice_payload(fulfilled_order):+ fulfilled_order.origin = OrderOrigin.CHECKOUT+ fulfilled_order.save(update_fields=["origin"])invoice = fulfilled_order.invoices.first()payload = json.loads(generate_invoice_payload(invoice))[0]@@ -199,6 +212,7 @@ def test_generate_invoice_payload(fulfilled_order):"metadata": {},"created": ANY,"status": "fulfilled",+ "origin": OrderOrigin.CHECKOUT,"user_email": "[email protected]","shipping_method_name": "DHL","shipping_price_net_amount": "10.000",