Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Handle Money serialized as a dict
Pacu20f37087fc592
diff --git a/saleor/order/__init__.py b/saleor/order/__init__.pyindex 3ddd1c47ab..40bde7ec5b 100644--- a/saleor/order/__init__.py+++ b/saleor/order/__init__.py@@ -106,6 +106,20 @@ EMAIL_CHOICES = {'Email type', 'Order confirmation')}+def get_money_from_params(amount):+ """Money serialization changed at one point, as for now it's serialized+ as a dict. But we keep those settings for the legacy data.++ Can be safely removed after migrating to Dashboard 2.0+ """+ money_amount = amount+ money_currency = settings.DEFAULT_CURRENCY+ if isinstance(amount, dict):+ money_amount = amount['amount']+ money_currency = amount['currency']+ return Money(amount=money_amount, currency=money_currency)++def display_order_event(order_event):"""This function is used to keep the backwards compatibilitywith the old dashboard and new type of order events@@ -124,15 +138,13 @@ def display_order_event(order_event):'Payment was released by %(user_name)s' % {'user_name': order_event.user})if event_type == OrderEvents.PAYMENT_REFUNDED.value:- amount = Money(- amount=params['amount'], currency=settings.DEFAULT_CURRENCY)+ amount = get_money_from_params(params['amount'])return pgettext_lazy('Dashboard message related to an order','Successfully refunded: %(amount)s' % {'amount': prices_i18n.amount(amount)})if event_type == OrderEvents.PAYMENT_CAPTURED.value:- amount = Money(- amount=params['amount'], currency=settings.DEFAULT_CURRENCY)+ amount = get_money_from_params(params['amount'])return pgettext_lazy('Dashboard message related to an order','Successfully captured: %(amount)s' % {diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.pyindex 2808f1b38e..e372fc6079 100644--- a/tests/dashboard/test_order.py+++ b/tests/dashboard/test_order.py@@ -1232,7 +1232,7 @@ def test_order_event_display(admin_user, type, order):'quantity': 12,'email_type': OrderEventsEmails.PAYMENT.value,'email': '[email protected]',- 'amount': '80.00',+ 'amount': json.dumps(Money(80, 'USD')),'composed_id': 12,'tracking_number': '5421AB','oversold_items': ['Blue Shirt', 'Red Shirt']}