Skip to content

Commit

Permalink
Merge pull request #4709 from korycins/fix/digital_product/update_ord…
Browse files Browse the repository at this point in the history
…er_status_after_fillfiled

Update order status after fullfilled digital products
  • Loading branch information
maarcingebala committed Sep 3, 2019
2 parents 7180fd7 + 693f41f commit 854bcd3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ All notable, unreleased changes to this project will be documented in this file.
- Change AddressValidationRules API - #4655 by @Kwaidan00
- Refactor account deletion mutations - #4668 by @fowczarek
- Upgraded django-prices from v1 to v2.1. Currency codes are now locked at 3 characters max by default for consistency. - #4639 by @NyanKiyoshi
- Drop deprecated fields from api - #4684 by@fowczarek
- Drop deprecated fields from api - #4684 by @fowczarek
- Distinguish OrderLine product name and variant name - #4702 by @fowczarek
- Fix for Digital products - update order status after automatic fulfillment - #4709 by @korycins

## 2.8.0

Expand Down
5 changes: 4 additions & 1 deletion saleor/order/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def automatically_fulfill_digital_lines(order: Order):
fulfillment=fulfillment, order_line=line, quantity=quantity
)
fulfill_order_line(order_line=line, quantity=quantity)
emails.send_fulfillment_confirmation.delay(order.pk, fulfillment.pk)
emails.send_fulfillment_confirmation_to_customer(
order, fulfillment, user=order.user
)
update_order_status(order)


def check_order_status(func):
Expand Down
63 changes: 63 additions & 0 deletions tests/test_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import pytest
from django.core.exceptions import ImproperlyConfigured
from prices import Money, TaxedMoney

from saleor.order import OrderStatus
from saleor.order.events import OrderEvents, OrderEventsEmails
from saleor.payment import (
ChargeStatus,
Expand Down Expand Up @@ -161,6 +163,67 @@ def test_handle_fully_paid_order(mock_send_payment_confirmation, order):
mock_send_payment_confirmation.assert_called_once_with(order.pk)


@patch("saleor.order.emails.send_fulfillment_confirmation.delay")
@patch("saleor.order.emails.send_payment_confirmation.delay")
def test_handle_fully_paid_order_digital_lines(
mock_send_payment_confirmation,
mock_send_fulfillment_confirmation,
order,
digital_content,
variant,
site_settings,
):
site_settings.automatic_fulfillment_digital_products = True
site_settings.save()

variant.digital_content = digital_content
variant.digital_content.save()

product_type = variant.product.product_type
product_type.is_shipping_required = False
product_type.is_digital = True
product_type.save()

net = variant.get_price()
gross = Money(amount=net.amount * Decimal(1.23), currency=net.currency)
order.lines.create(
product_name=str(variant.product),
variant_name=str(variant),
product_sku=variant.sku,
is_shipping_required=variant.is_shipping_required(),
quantity=3,
variant=variant,
unit_price=TaxedMoney(net=net, gross=gross),
tax_rate=23,
)

handle_fully_paid_order(order)

fulfillment = order.fulfillments.first()

event_order_paid, event_email_sent, event_order_fulfilled, event_digital_links = (
order.events.all()
)
assert event_order_paid.type == OrderEvents.ORDER_FULLY_PAID

assert event_email_sent.type == OrderEvents.EMAIL_SENT
assert event_order_fulfilled.type == OrderEvents.EMAIL_SENT
assert event_digital_links.type == OrderEvents.EMAIL_SENT

assert (
event_order_fulfilled.parameters["email_type"] == OrderEventsEmails.FULFILLMENT
)
assert (
event_digital_links.parameters["email_type"] == OrderEventsEmails.DIGITAL_LINKS
)

mock_send_payment_confirmation.assert_called_once_with(order.pk)
mock_send_fulfillment_confirmation.assert_called_once_with(order.pk, fulfillment.pk)

order.refresh_from_db()
assert order.status == OrderStatus.FULFILLED


def test_require_active_payment():
@require_active_payment
def test_function(_payment, *_args, **_kwargs):
Expand Down

0 comments on commit 854bcd3

Please sign in to comment.