Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Send fulfillment email when automatic fulfillment is enabled
Maciej Korycinski114a12a521fe
diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 371c98703b..f88eaf3158 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -12,7 +12,7 @@ from ..core.utils.taxes import (from ..core.weight import zero_weightfrom ..dashboard.order.utils import get_voucher_discount_for_orderfrom ..discount.models import NotApplicable-from ..order import FulfillmentStatus, OrderStatus+from ..order import FulfillmentStatus, OrderStatus, emailsfrom ..order.models import Fulfillment, FulfillmentLine, Order, OrderLinefrom ..payment import ChargeStatusfrom ..payment.utils import gateway_refund, gateway_void@@ -57,14 +57,14 @@ def fulfill_order_line(order_line, quantity):def automatically_fulfill_digital_lines(order: Order):"""Fulfill all digital lines which have enabled automatic fulfillment- setting"""+ setting and send confirmation email."""digital_lines = order.lines.filter(is_shipping_required=False, variant__digital_content__isnull=False)digital_lines = digital_lines.prefetch_related('variant__digital_content')if not digital_lines:return- fulfilment, _ = Fulfillment.objects.get_or_create(order=order)+ fulfillment, _ = Fulfillment.objects.get_or_create(order=order)for line in digital_lines:if not order_line_needs_automatic_fulfillment(line):continue@@ -72,10 +72,10 @@ def automatically_fulfill_digital_lines(order: Order):digital_content.urls.create(line=line)quantity = line.quantityFulfillmentLine.objects.create(- fulfillment=fulfilment, order_line=line,+ fulfillment=fulfillment, order_line=line,quantity=quantity)fulfill_order_line(order_line=line, quantity=quantity)-+ emails.send_fulfillment_confirmation.delay(order.pk, fulfillment.pk)def check_order_status(func):"""Check if order meets preconditions of payment process.diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex e46d1db8ca..86cf94134e 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -12,10 +12,9 @@ from django.utils.translation import pgettext_lazyfrom ..account.models import Address, Userfrom ..checkout.models import Cartfrom ..core import analytics-from ..order import OrderEvents, OrderEventsEmails+from ..order import OrderEvents, OrderEventsEmails, utils as order_utilsfrom ..order.emails import send_payment_confirmationfrom ..order.models import Order-from ..order import utils as order_utilsfrom . import (ChargeStatus, CustomPaymentChoices, GatewayError, OperationType,PaymentError, TransactionKind, get_payment_gateway)@@ -80,7 +79,6 @@ def handle_fully_paid_order(order):if order_utils.order_needs_automatic_fullfilment(order):order_utils.automatically_fulfill_digital_lines(order)- # send_emailtry:analytics.report_order(order.tracking_client_id, order)except Exception:diff --git a/tests/test_order.py b/tests/test_order.pyindex 56f8117732..6be379f769 100644--- a/tests/test_order.py+++ b/tests/test_order.py@@ -1,5 +1,6 @@from decimal import Decimalfrom unittest.mock import patch+import pytestfrom django.urls import reversefrom django_countries.fields import Country@@ -12,16 +13,17 @@ from saleor.core.utils.taxes import (DEFAULT_TAX_RATE_NAME, get_tax_rate_by_name, get_taxes_for_country)from saleor.core.weight import zero_weightfrom saleor.order import FulfillmentStatus, OrderStatus, models-from saleor.order.models import Order, Fulfillment+from saleor.order.models import Fulfillment, Orderfrom saleor.order.utils import (- add_variant_to_order, cancel_fulfillment, cancel_order,- change_order_line_quantity, delete_order_line, recalculate_order,- fulfill_order_line, restock_fulfillment_lines, restock_order_lines,- update_order_prices, update_order_status, automatically_fulfill_digital_lines)+ add_variant_to_order, automatically_fulfill_digital_lines,+ cancel_fulfillment, cancel_order, change_order_line_quantity,+ delete_order_line, fulfill_order_line, recalculate_order,+ restock_fulfillment_lines, restock_order_lines, update_order_prices,+ update_order_status)from saleor.payment import ChargeStatusfrom saleor.payment.models import Paymentfrom saleor.product.models import DigitalContent-from tests.utils import get_redirect_location, create_image+from tests.utils import create_image, get_redirect_locationdef test_total_setter():@@ -580,8 +582,10 @@ def test_get_order_weight_non_existing_product(order_with_lines, product):assert old_weight == new_weight+@patch('saleor.order.utils.emails.send_fulfillment_confirmation')@patch('saleor.order.utils.get_default_digital_content_settings')-def test_fulfill_digital_lines(mock_digital_settings, order_with_lines):+def test_fulfill_digital_lines(+ mock_digital_settings, mock_email_fulfillment, order_with_lines):mock_digital_settings.return_value = {'automatic_fulfillment': True}line = order_with_lines.lines.all()[0]@@ -603,6 +607,7 @@ def test_fulfill_digital_lines(mock_digital_settings, order_with_lines):assert fulfillment_lines.count() == 1assert line.digital_content_url+ assert mock_email_fulfillment.delay.calleddef test_fulfill_order_line(order_with_lines):