Skip to content

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

Call fulfillment_approved in order_fulfilled and approve_fulfillment methods

IKarbowiakde34c5870042
diff --git a/saleor/graphql/order/tests/test_fulfillment.py b/saleor/graphql/order/tests/test_fulfillment.py
index 04e43b8f77..a31f798fc5 100644
--- a/saleor/graphql/order/tests/test_fulfillment.py
+++ b/saleor/graphql/order/tests/test_fulfillment.py
@@ -1800,9 +1800,11 @@ APPROVE_FULFILLMENT_MUTATION = """
"""
+@patch("saleor.plugins.manager.PluginsManager.fulfillment_approved")
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
def test_fulfillment_approve(
mock_email_fulfillment,
+ mock_fulfillment_approved,
staff_api_client,
fulfillment,
permission_manage_orders,
@@ -1829,6 +1831,7 @@ def test_fulfillment_approve(
event = events[0]
assert event.type == OrderEvents.FULFILLMENT_FULFILLED_ITEMS
assert event.user == staff_api_client.user
+ mock_fulfillment_approved.assert_called_once_with(fulfillment)
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
@@ -1869,9 +1872,11 @@ def test_fulfillment_approve_delete_products_before_approval_allow_stock_exceede
assert event.user == staff_api_client.user
+@patch("saleor.plugins.manager.PluginsManager.fulfillment_approved")
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
def test_fulfillment_approve_delete_products_before_approval_allow_stock_exceeded_false(
mock_email_fulfillment,
+ mock_fulfillment_approved,
staff_api_client,
fulfillment,
permission_manage_orders,
@@ -1918,6 +1923,7 @@ def test_fulfillment_approve_delete_products_before_approval_allow_stock_exceede
assert mock_email_fulfillment.call_count == 1
events = fulfillment.order.events.all()
assert len(events) == 0
+ mock_fulfillment_approved.assert_not_called()
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
diff --git a/saleor/order/actions.py b/saleor/order/actions.py
index c62a8ff779..b4c873f6c8 100644
--- a/saleor/order/actions.py
+++ b/saleor/order/actions.py
@@ -263,6 +263,8 @@ def order_fulfilled(
if order.status == OrderStatus.FULFILLED:
transaction.on_commit(lambda: manager.order_fulfilled(order))
+ for fulfillment in fulfillments:
+ transaction.on_commit(lambda: manager.fulfillment_approved(fulfillment))
if notify_customer:
for fulfillment in fulfillments:
@@ -476,6 +478,7 @@ def approve_fulfillment(
transaction.on_commit(lambda: manager.order_updated(order))
if order.status == OrderStatus.FULFILLED:
transaction.on_commit(lambda: manager.order_fulfilled(order))
+ transaction.on_commit(lambda: manager.fulfillment_approved(fulfillment))
if gift_card_lines_info:
gift_cards_create(
diff --git a/saleor/order/tests/test_fulfillments_actions.py b/saleor/order/tests/test_fulfillments_actions.py
index a41f51e753..01124473e5 100644
--- a/saleor/order/tests/test_fulfillments_actions.py
+++ b/saleor/order/tests/test_fulfillments_actions.py
@@ -11,9 +11,11 @@ from ..actions import create_fulfillments
from ..models import FulfillmentLine, OrderStatus
+@patch("saleor.plugins.manager.PluginsManager.fulfillment_approved")
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
def test_create_fulfillments(
mock_email_fulfillment,
+ mock_fulfillment_approved,
staff_user,
order_with_lines,
warehouse,
@@ -71,14 +73,18 @@ def test_create_fulfillments(
[fulfillment_lines[0].pk, fulfillment_lines[1].pk]
)
+ flush_post_commit_hooks()
mock_email_fulfillment.assert_called_once_with(
order, order.fulfillments.get(), staff_user, None, manager
)
+ mock_fulfillment_approved.assert_called_once_with(fulfillment)
+@patch("saleor.plugins.manager.PluginsManager.fulfillment_approved")
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)
def test_create_fulfillments_require_approval(
mock_email_fulfillment,
+ mock_fulfillment_approved,
staff_user,
order_with_lines,
warehouse,
@@ -140,7 +146,9 @@ def test_create_fulfillments_require_approval(
[fulfillment_lines[0].pk, fulfillment_lines[1].pk]
)
+ flush_post_commit_hooks()
mock_email_fulfillment.assert_not_called()
+ mock_fulfillment_approved.assert_not_called()
@patch("saleor.order.actions.send_fulfillment_confirmation_to_customer", autospec=True)