Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix invoice creation when no plugin is enabled (#17355)
Jonatan Witoszek11e5215f1041
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 66390b684c..e7d677195e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -21,7 +21,8 @@ All notable, unreleased changes to this project will be documented in this file.- The `updateMetadata` for `Order` and `OrderLine` types requires the `MANAGE_ORDERS` permission- Fix updating `metadata` and `privateMetadata` in `transactionUpdate` - #17261 by @IKarbowiak- The provided data in the input field are merged with the existing one (previously the existing data was overridden by the new one).- -Queries: `checkouts`, `checkoutLines`, and `me.checkouts` will no longer trigger external calls to calculate taxes: the `CHECKOUT_CALCULATE_TAXES` webhooks and plugins (including AvataxPlugin) - #17268 by @korycins+- Fixed `invoiceRequest` no longer throws an error, when only app with webhook `INVOICE_REQUESTED` is installed, without invoice plugin - #17355 by @witoszekdev+- Queries: `checkouts`, `checkoutLines`, and `me.checkouts` will no longer trigger external calls to calculate taxes: the `CHECKOUT_CALCULATE_TAXES` webhooks and plugins (including AvataxPlugin) - #17268 by @korycins### GraphQL APIdiff --git a/saleor/graphql/invoice/mutations/invoice_request.py b/saleor/graphql/invoice/mutations/invoice_request.pyindex ff4303f1fd..0249269148 100644--- a/saleor/graphql/invoice/mutations/invoice_request.py+++ b/saleor/graphql/invoice/mutations/invoice_request.py@@ -15,7 +15,6 @@ from ...core.utils import WebhookEventInfofrom ...order.types import Orderfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ..types import Invoice-from ..utils import is_event_active_for_any_pluginclass InvoiceRequest(ModelMutation):@@ -75,7 +74,10 @@ class InvoiceRequest(ModelMutation):cls.check_channel_permissions(info, [order.channel_id])cls.clean_order(order)manager = get_plugin_manager_promise(info.context).get()- if not is_event_active_for_any_plugin("invoice_request", manager.all_plugins):++ if not manager.is_event_active_for_any_plugin(+ "invoice_request", channel_slug=order.channel.slug+ ):raise ValidationError({"orderId": ValidationError(diff --git a/saleor/graphql/invoice/tests/test_invoice_request.py b/saleor/graphql/invoice/tests/test_invoice_request.pyindex 742d7d32ba..c5585f5f0b 100644--- a/saleor/graphql/invoice/tests/test_invoice_request.py+++ b/saleor/graphql/invoice/tests/test_invoice_request.py@@ -42,7 +42,7 @@ def setup_dummy_gateways(settings):@patch(- "saleor.graphql.invoice.mutations.invoice_request.is_event_active_for_any_plugin",+ "saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin",return_value=True,)@patch("saleor.plugins.manager.PluginsManager.invoice_request")@@ -118,7 +118,7 @@ def test_invoice_request_by_user_no_channel_access(@patch(- "saleor.graphql.invoice.mutations.invoice_request.is_event_active_for_any_plugin",+ "saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin",return_value=True,)@patch("saleor.plugins.manager.PluginsManager.invoice_request")@@ -225,7 +225,7 @@ def test_invoice_request_no_billing_address(@patch(- "saleor.graphql.invoice.mutations.invoice_request.is_event_active_for_any_plugin",+ "saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin",return_value=True,)def test_invoice_request_no_number(@@ -263,7 +263,7 @@ def test_invoice_request_invalid_id(staff_api_client, permission_group_manage_or@patch(- "saleor.graphql.invoice.mutations.invoice_request.is_event_active_for_any_plugin",+ "saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin",return_value=False,)def test_invoice_request_no_invoice_plugin(diff --git a/saleor/graphql/invoice/tests/test_invoice_utils.py b/saleor/graphql/invoice/tests/test_invoice_utils.pydeleted file mode 100644index 2225ec7b49..0000000000--- a/saleor/graphql/invoice/tests/test_invoice_utils.py+++ /dev/null@@ -1,31 +0,0 @@-from ..utils import is_event_active_for_any_plugin---class MockInvoicePluginActive:- active = True-- @staticmethod- def is_event_active(_):- return True---class MockInvoicePluginInactive:- active = False-- @staticmethod- def is_event_active(_):- return True---def test_is_event_active_for_any_plugin_plugin_active():- result = is_event_active_for_any_plugin(- "event", [MockInvoicePluginActive(), MockInvoicePluginInactive()]- )- assert result is True---def test_is_event_active_for_any_plugin_plugin_inactive():- result = is_event_active_for_any_plugin(- "event", [MockInvoicePluginInactive(), MockInvoicePluginInactive()]- )- assert result is Falsediff --git a/saleor/graphql/invoice/utils.py b/saleor/graphql/invoice/utils.pydeleted file mode 100644index 64f52b70c2..0000000000--- a/saleor/graphql/invoice/utils.py+++ /dev/null@@ -1,4 +0,0 @@-def is_event_active_for_any_plugin(event: str, plugins_list):- return any(- plugin.is_event_active(event) for plugin in plugins_list if plugin.active- )