Skip to content

Commit

Permalink
Merge pull request #129 from django-oscar/missing-shipping-method-fields
Browse files Browse the repository at this point in the history
Added the missing shipping method fields, that should all be availabl…
  • Loading branch information
Martijn Jacobs committed Aug 17, 2018
2 parents 45bcf44 + 0b4e62c commit 13cc741
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions oscarapi/serializers/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ class Meta:
class ShippingMethodSerializer(serializers.Serializer):
code = serializers.CharField(max_length=128)
name = serializers.CharField(max_length=128)
description = serializers.CharField()
price = serializers.SerializerMethodField('calculate_price')
is_discounted = serializers.BooleanField()
discount = serializers.SerializerMethodField('calculate_discount')

def calculate_discount(self, obj):
basket = self.context.get('basket')
return obj.discount(basket)

def calculate_price(self, obj):
price = obj.calculate(self.context.get('basket'))
Expand Down
6 changes: 6 additions & 0 deletions oscarapi/tests/testcheckout.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ def test_shipping_methods(self):
self.assertDictEqual(self.response[0], {
'code': 'no-shipping-required',
'name': 'No shipping required',
'description': "",
'is_discounted': False,
'discount': 0,
'price': {
'currency': None,
'excl_tax': '0.00',
Expand All @@ -497,6 +500,9 @@ def test_shipping_methods(self):
self.assertDictEqual(self.response[0], {
'code': 'free-shipping',
'name': 'Free shipping',
'description': "",
'is_discounted': False,
'discount': 0,
'price': {
'currency': 'EUR',
'excl_tax': '0.00',
Expand Down

0 comments on commit 13cc741

Please sign in to comment.