Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Merge branch 'master' of github.com:mirumee/saleor into feature/unconfirmed-order-line-manipulation
Tomasz Szymanski6db4f879c329
diff --cc CHANGELOG.mdindex bf27d8bded,0b09784df8..c2ecf7264e--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -23,8 -34,23 +34,24 @@@ All notable, unreleased changes to thi- Drop `apply_taxes_to_shipping_price_range` plugin hook - #6746 by @maarcingebala- Drop `CHECKOUT_QUANTITY_CHANGED` webhook - #6797 by @d-wysocki- Drop deprecated `taxRate` field from `ProductType` - #6795 by @d-wysocki+- Unconfirmed order manipulation - #6829 by @tomaszszymanski129- Remove resolving user's location from GeoIP; drop `PaymentInput.billingAddress` input field - #6784 by @maarcingebala+ - Change the payload of the order webhook to handle discounts list, added fields: `Order.discounts`,+ `OrderLine.unit_discount_amount`,`OrderLine.unit_discount_type`, `OrderLine.unit_discount_reason` , remove fields:+ `Order.discount_amount`, `Order.discount_name`, `Order.translated_discount_name`- #6874 by @korycins+ - Update checkout performance - introduce `CheckoutInfo` data class - #6958 by @IKarbowiak; Introduced changes in plugin methods definitions:+ - in the following methods, the `checkout` parameter changed to `checkout_info`:+ - `calculate_checkout_total`+ - `calculate_checkout_subtotal`+ - `calculate_checkout_shipping`+ - `get_checkout_shipping_tax_rate`+ - `calculate_checkout_line_total`+ - `calculate_checkout_line_unit_price`+ - `get_checkout_line_tax_rate`+ - `preprocess_order_creation`+ - additionally, `preprocess_order_creation` was extend with `lines_info` parameter+ - Remove triggering a webhook event `PRODUCT_UPDATED` when calling `ProductVariantCreate` mutation. Use `PRODUCT_VARIANT_CREATED` instead - #6963 by @piotrgrundas+ - Remove triggering a webhook event `PRODUCT_UPDATED` when calling `ProductVariantChannelListingUpdate` mutation. Use `PRODUCT_VARIANT_UPDATED` instead - #6963 by @piotrgrundas### Otherdiff --cc saleor/graphql/order/mutations/orders.pyindex 8b0b5cf043,05ed6273f9..f2d0cd43bd--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@@ -206,7 -188,6 +206,11 @@@ class OrderUpdate(DraftOrderCreate)user = User.objects.filter(email=instance.user_email).first()instance.user = userinstance.save()- update_order_prices(instance, info.context.discounts)++ update_order_prices(++ instance,++ info.context.plugins,++ info.context.site.settings.include_taxes_in_prices,++ )info.context.plugins.order_updated(instance)@@@ -294,7 -280,7 +303,11 @@@ class OrderUpdateShipping(BaseMutation)"shipping_tax_rate",])- update_order_prices(order, info.context.discounts)- update_order_prices(order, info.context.plugins, info.context.site.settings)++ update_order_prices(++ order,++ info.context.plugins,++ info.context.site.settings.include_taxes_in_prices,++ )# Post-process the resultsorder_shipping_updated(order)return OrderUpdateShipping(order=order)diff --cc saleor/graphql/order/schema.pyindex edfe5c3394,3b444494e1..a0f12b6bf6--- a/saleor/graphql/order/schema.py+++ b/saleor/graphql/order/schema.py@@@ -166,9 -176,13 +173,17 @@@ class OrderMutations(graphene.ObjectTyporder_fulfillment_refund_products = FulfillmentRefundProducts.Field()order_fulfillment_return_products = FulfillmentReturnProducts.Field()+ order_lines_create = OrderLinesCreate.Field()+ order_line_delete = OrderLineDelete.Field()+ order_line_update = OrderLineUpdate.Field()+++ order_discount_add = OrderDiscountAdd.Field()+ order_discount_update = OrderDiscountUpdate.Field()+ order_discount_delete = OrderDiscountDelete.Field()++ order_line_discount_update = OrderLineDiscountUpdate.Field()+ order_line_discount_remove = OrderLineDiscountRemove.Field()+order_mark_as_paid = OrderMarkAsPaid.Field()order_refund = OrderRefund.Field()order_update = OrderUpdate.Field()diff --cc saleor/graphql/schema.graphqlindex 90473f324f,7040053946..edcec22eb1--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@@ -2682,9 -2719,11 +2695,14 @@@ type MutationorderFulfillmentUpdateTracking(id: ID!, input: FulfillmentUpdateTrackingInput!): FulfillmentUpdateTrackingorderFulfillmentRefundProducts(input: OrderRefundProductsInput!, order: ID!): FulfillmentRefundProductsorderFulfillmentReturnProducts(input: OrderReturnProductsInput!, order: ID!): FulfillmentReturnProducts+ orderLinesCreate(id: ID!, input: [OrderLineCreateInput]!): OrderLinesCreate+ orderLineDelete(id: ID!): OrderLineDelete+ orderLineUpdate(id: ID!, input: OrderLineInput!): OrderLineUpdate+ orderDiscountAdd(input: OrderDiscountCommonInput!, orderId: ID!): OrderDiscountAdd+ orderDiscountUpdate(discountId: ID!, input: OrderDiscountCommonInput!): OrderDiscountUpdate+ orderDiscountDelete(discountId: ID!): OrderDiscountDelete+ orderLineDiscountUpdate(input: OrderDiscountCommonInput!, orderLineId: ID!): OrderLineDiscountUpdate+ orderLineDiscountRemove(orderLineId: ID!): OrderLineDiscountRemoveorderMarkAsPaid(id: ID!, transactionReference: String): OrderMarkAsPaidorderRefund(amount: PositiveDecimal!, id: ID!): OrderRefundorderUpdate(id: ID!, input: OrderUpdateInput!): OrderUpdate@@@ -3140,13 -3245,20 +3224,27 @@@ input OrderLineCreateInputvariantId: ID!}+type OrderLineDelete {+ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")+ order: Order+ orderLine: OrderLine+ orderErrors: [OrderError!]!+}++ type OrderLineDiscountRemove {+ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")+ orderLine: OrderLine+ order: Order+ orderErrors: [OrderError!]!+ }++ type OrderLineDiscountUpdate {+ errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")+ orderLine: OrderLine+ order: Order+ orderErrors: [OrderError!]!+ }+input OrderLineInput {quantity: Int!}diff --cc saleor/order/migrations/0102_auto_20210316_0919.pyindex b817beaba4,0000000000..71faee5eb7mode 100644,000000..100644--- a/saleor/order/migrations/0102_auto_20210316_0919.py+++ b/saleor/order/migrations/0102_auto_20210316_0919.py@@@ -1,72 -1,0 +1,64 @@@- # Generated by Django 3.1.5 on 2021-01-26 14:48++# Generated by Django 3.1.7 on 2021-03-16 09:19++from django.db import migrations, models++- def rename_draft_events_type(apps, schema_editor):- OLD_ADDED_PRODUCTS_NAME = "draft_added_products"- OLD_REMOVED_PRODUCTS_NAME = "draft_removed_products"- NEW_ADDED_PRODUCTS_NAME = "added_products"- NEW_REMOVED_PRODUCTS_NAME = "removed_products"-- OrderEvent = apps.get_model("order", "OrderEvent")-- OrderEvent.objects.filter(type=OLD_ADDED_PRODUCTS_NAME).update(- type=NEW_ADDED_PRODUCTS_NAME- )- OrderEvent.objects.filter(type=OLD_REMOVED_PRODUCTS_NAME).update(- type=NEW_REMOVED_PRODUCTS_NAME- )--+class Migration(migrations.Migration):++ dependencies = [- ("order", "0097_auto_20210107_1148"),++ ("order", "0101_auto_20210308_1213"),+ ]++ operations = [+ migrations.AlterField(+ model_name="orderevent",+ name="type",+ field=models.CharField(+ choices=[+ ("DRAFT_CREATED", "draft_created"),+ ("DRAFT_CREATED_FROM_REPLACE", "draft_created_from_replace"),+ ("ADDED_PRODUCTS", "added_products"),+ ("REMOVED_PRODUCTS", "removed_products"),+ ("PLACED", "placed"),+ ("PLACED_FROM_DRAFT", "placed_from_draft"),+ ("OVERSOLD_ITEMS", "oversold_items"),+ ("CANCELED", "canceled"),+ ("ORDER_MARKED_AS_PAID", "order_marked_as_paid"),+ ("ORDER_FULLY_PAID", "order_fully_paid"),+ ("ORDER_REPLACEMENT_CREATED", "order_replacement_created"),++ ("ORDER_DISCOUNT_ADDED", "order_discount_added"),++ (++ "ORDER_DISCOUNT_AUTOMATICALLY_UPDATED",++ "order_discount_automatically_updated",++ ),++ ("ORDER_DISCOUNT_UPDATED", "order_discount_updated"),++ ("ORDER_DISCOUNT_DELETED", "order_discount_deleted"),++ ("ORDER_LINE_DISCOUNT_UPDATED", "order_line_discount_updated"),++ ("ORDER_LINE_DISCOUNT_REMOVED", "order_line_discount_removed"),+ ("UPDATED_ADDRESS", "updated_address"),+ ("EMAIL_SENT", "email_sent"),+ ("CONFIRMED", "confirmed"),+ ("PAYMENT_AUTHORIZED", "payment_authorized"),+ ("PAYMENT_CAPTURED", "payment_captured"),+ ("EXTERNAL_SERVICE_NOTIFICATION", "external_service_notification"),+ ("PAYMENT_REFUNDED", "payment_refunded"),+ ("PAYMENT_VOIDED", "payment_voided"),+ ("PAYMENT_FAILED", "payment_failed"),+ ("INVOICE_REQUESTED", "invoice_requested"),+ ("INVOICE_GENERATED", "invoice_generated"),+ ("INVOICE_UPDATED", "invoice_updated"),+ ("INVOICE_SENT", "invoice_sent"),+ ("FULFILLMENT_CANCELED", "fulfillment_canceled"),+ ("FULFILLMENT_RESTOCKED_ITEMS", "fulfillment_restocked_items"),+ ("FULFILLMENT_FULFILLED_ITEMS", "fulfillment_fulfilled_items"),+ ("FULFILLMENT_REFUNDED", "fulfillment_refunded"),+ ("FULFILLMENT_RETURNED", "fulfillment_returned"),+ ("FULFILLMENT_REPLACED", "fulfillment_replaced"),+ ("TRACKING_UPDATED", "tracking_updated"),+ ("NOTE_ADDED", "note_added"),+ ("OTHER", "other"),+ ],+ max_length=255,+ ),+ ),- migrations.RunPython(rename_draft_events_type, migrations.RunPython.noop),+ ]diff --cc saleor/order/tests/test_order.pyindex 8953566b38,92dc44ea0f..3649cb4cf1--- a/saleor/order/tests/test_order.py+++ b/saleor/order/tests/test_order.py@@@ -477,7 -490,7 +490,9 @@@ def test_update_order_prices).priceshipping_price = TaxedMoney(net=shipping_price, gross=shipping_price)- update_order_prices(order_with_lines, None)- update_order_prices(order_with_lines, manager, site_settings)++ update_order_prices(++ order_with_lines, manager, site_settings.include_taxes_in_prices++ )line_1.refresh_from_db()line_2.refresh_from_db()@@@ -515,7 -534,7 +536,9 @@@ def test_update_order_prices_tax_includchannel_id=order_with_lines.channel_id).price- update_order_prices(order_with_lines, None)- update_order_prices(order_with_lines, manager, site_settings)++ update_order_prices(++ order_with_lines, manager, site_settings.include_taxes_in_prices++ )line_1.refresh_from_db()line_2.refresh_from_db()diff --cc saleor/tests/fixtures.pyindex e84f8a2675,571b4020dc..afb53b702b--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@@ -55,7 -55,11 +55,11 @@@ from ..giftcard.models import GiftCarfrom ..menu.models import Menu, MenuItem, MenuItemTranslationfrom ..order import OrderLineData, OrderStatusfrom ..order.actions import cancel_fulfillment, fulfill_order_lines- from ..order.events import OrderEvents+ from ..order.events import (+ OrderEvents,- draft_order_added_products_event,+ fulfillment_refunded_event,++ order_added_products_event,+ )from ..order.models import FulfillmentStatus, Order, OrderEvent, OrderLinefrom ..order.utils import recalculate_orderfrom ..page.models import Page, PageTranslation, PageType@@@ -2265,6 -2269,33 +2269,33 @@@ def order_with_linesreturn order+ @pytest.fixture+ def order_with_lines_and_events(order_with_lines, staff_user):+ events = []+ for event_type, _ in OrderEvents.CHOICES:+ events.append(+ OrderEvent(+ type=event_type,+ order=order_with_lines,+ user=staff_user,+ )+ )+ OrderEvent.objects.bulk_create(events)+ fulfillment_refunded_event(+ order=order_with_lines,+ user=staff_user,+ refunded_lines=[(1, order_with_lines.lines.first())],+ amount=Decimal("10.0"),+ shipping_costs_included=False,+ )- draft_order_added_products_event(++ order_added_products_event(+ order=order_with_lines,+ user=staff_user,+ order_lines=[(1, order_with_lines.lines.first())],+ )+ return order_with_lines++@pytest.fixturedef order_with_lines_channel_PLN(customer_user,