Repository: saleor/saleor

Issue:
Using of wrong Money constructor on displaying order info in dashboard
### What I'm trying to achieve
I've tried to add refunds / captures (using dummy provider's preauth. payment)

### Steps to reproduce the problem
1. Create payment using dummy provider
2. Preauth. payment
3. Make payment refunds and captures in dashboard
4. Open order in dashboard

### What I expected to happen
I expected to see order page in dashboard, but I've got `conversion from dict to Decimal is not supported` on order's page
I guess the root of the problem is (from Django debugger information):
Line: `/app/saleor/order/__init__.py : 134-135` in display_order_event

Code:
```
amount = Money(
            amount=params['amount'], currency=settings.DEFAULT_CURRENCY) 
```

Local vars:
```
event_type | 'captured'
order_event | OrderEvent(type='captured', user=<User: ***@***>)
params | {'amount': {'_type': 'Money', 'amount': '500', 'currency': 'USD'}}
```

Possible solution:
```
amount = Money(
            amount=params['amount']['amount'], currency=params['amount']['currency']) 
```

**System information**
Operating system: ubuntu 16.04
Browser: chrome



Discussion:
Right, Money serialization changed to the dictionary at some point and this function was not adjusted. It's tested, but params could be json dumped and loaded again instead of hardcoding them.  

Resolving patch:
diff --git a/saleor/order/__init__.py b/saleor/order/__init__.py
--- a/saleor/order/__init__.py
+++ b/saleor/order/__init__.py
@@ -106,6 +106,19 @@ class OrderEventsEmails(Enum):
         '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
+    """
+    if isinstance(amount, Money):
+        return amount
+    if isinstance(amount, dict):
+        return Money(amount=amount['amount'], currency=amount['currency'])
+    return Money(amount, settings.DEFAULT_CURRENCY)
+
+
 def display_order_event(order_event):
     """This function is used to keep the  backwards compatibility
     with the old dashboard and new type of order events
@@ -124,15 +137,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' % {


Test patch:
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -1,11 +1,12 @@
 import json
 
 import pytest
-
 from django.conf import settings
 from django.urls import reverse
 from payments import PaymentStatus
 from prices import Money
+from tests.utils import get_form_errors, get_redirect_location
+
 from saleor.checkout import AddressType
 from saleor.core.utils.taxes import ZERO_MONEY, ZERO_TAXED_MONEY
 from saleor.dashboard.order.forms import ChangeQuantityForm
@@ -15,11 +16,10 @@
 from saleor.discount.utils import increase_voucher_usage
 from saleor.order import (
     FulfillmentStatus, OrderEvents, OrderEventsEmails, OrderStatus)
-from saleor.order.models import Order, OrderLine, OrderEvent
+from saleor.order.models import Order, OrderEvent, OrderLine
 from saleor.order.utils import add_variant_to_order, change_order_line_quantity
 from saleor.product.models import ProductVariant
 from saleor.shipping.models import ShippingZone
-from tests.utils import get_form_errors, get_redirect_location
 
 
 def test_ajax_order_shipping_methods_list(
@@ -1232,7 +1232,7 @@ def test_order_event_display(admin_user, type, order):
         'quantity': 12,
         'email_type': OrderEventsEmails.PAYMENT.value,
         'email': 'example@example.com',
-        'amount': '80.00',
+        'amount': {'_type': 'Money', 'amount': '10.00', 'currency': 'USD'},
         'composed_id': 12,
         'tracking_number': '5421AB',
         'oversold_items': ['Blue Shirt', 'Red Shirt']}