Repository: django-oscar/django-oscar

Issue:
Basket View Error with Weight Based shipping and discount Applied 
When a discount it's applied to shipping and the shipping method is WeightBased occurs the following error:

  File "/Users/christian/virtualenvs/webstores/lib/python2.7/site-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, _callback_args, *_callback_kwargs)
  File "/Users/christian/virtualenvs/webstores/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, _args, *_kwargs)
  File "/Users/christian/virtualenvs/webstores/lib/python2.7/site-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, _args, *_kwargs)
  File "/Users/christian/virtualenvs/webstores/lib/python2.7/site-packages/django/views/generic/base.py", line 87, in dispatch
    return handler(request, _args, *_kwargs)
  File "/Users/christian/virtualenvs/webstores/lib/python2.7/site-packages/extra_views/formsets.py", line 338, in get
    return super(BaseModelFormSetView, self).get(request, _args, *_kwargs)
  File "/Users/christian/virtualenvs/webstores/lib/python2.7/site-packages/extra_views/formsets.py", line 301, in get
    return self.render_to_response(self.get_context_data(formset=formset))
  File "/Users/christian/virtualenvs/webstores/src/django-oscar/oscar/apps/basket/views.py", line 150, in get_context_data
    excl_discount = method.calculate_excl_discount(shipping_charge)
  File "/Users/christian/virtualenvs/webstores/src/django-oscar/oscar/apps/shipping/methods.py", line 119, in calculate_excl_discount
    return self.method.calculate(basket)
  File "/Users/christian/Documents/Projects/webstores/project/inti/oscarapp/shipping/models.py", line 60, in calculate
    weight = scale.weigh_basket(basket)
  File "/Users/christian/virtualenvs/webstores/src/django-oscar/oscar/apps/shipping/scales.py", line 27, in weigh_basket
    for line in basket.lines.all():

apps/basket/views.py

``` python
        method = self.get_default_shipping_method(self.request.basket)
        context['shipping_method'] = method
        shipping_charge = method.calculate(self.request.basket)
        context['shipping_charge'] = shipping_charge
        if method.is_discounted:
            excl_discount = method.calculate_excl_discount(shipping_charge) # It's passing Price object type here not basket 
            context['shipping_charge_excl_discount'] = excl_discount
```

but in method weigh_basket in  
apps/shipping/scales.py line 25

``` python
    def weigh_basket(self, basket): #it requires  basket object not price object
        weight = 0.0
        for line in basket.lines.all(): 
            weight += self.weigh_product(line.product) * line.quantity
        return weight
```



Discussion:

Resolving patch:
diff --git a/src/oscar/apps/basket/views.py b/src/oscar/apps/basket/views.py
--- a/src/oscar/apps/basket/views.py
+++ b/src/oscar/apps/basket/views.py
@@ -159,7 +159,7 @@ def get_context_data(self, **kwargs):
         shipping_charge = method.calculate(self.request.basket)
         context['shipping_charge'] = shipping_charge
         if method.is_discounted:
-            excl_discount = method.calculate_excl_discount(shipping_charge)
+            excl_discount = method.calculate_excl_discount(self.request.basket)
             context['shipping_charge_excl_discount'] = excl_discount
 
         context['order_total'] = OrderTotalCalculator().calculate(


Test patch: