Skip to content

Commit

Permalink
Rework US site's shipping methods to fit new system
Browse files Browse the repository at this point in the history
  • Loading branch information
codeinthehole committed May 28, 2014
1 parent 4dcfcc1 commit 223ed64
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
5 changes: 1 addition & 4 deletions sites/us/apps/checkout/session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from decimal import Decimal as D

from oscar.apps.checkout import session
from apps import tax

Expand All @@ -17,8 +15,7 @@ def build_submission(self, **kwargs):

# Recalculate order total to ensure we have a tax-inclusive total
submission['order_total'] = self.get_order_totals(
submission['basket'],
shipping_method=submission['shipping_method'])
submission['basket'], submission['shipping_charge'])

return submission

Expand Down
25 changes: 13 additions & 12 deletions sites/us/apps/shipping/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@


class Standard(methods.FixedPrice):
def __init__(self):
super(Standard, self).__init__(
charge_excl_tax=D('10.00'))
code = "standard"
name = "Standard"
charge_excl_tax = D('10.00')


class Express(methods.FixedPrice):
def __init__(self):
super(Express, self).__init__(
charge_excl_tax=D('20.00'))
code = "express"
name = "Express"
charge_excl_tax = D('20.00')


class Repository(repository.Repository):
methods = [Standard, Express]

def get_shipping_methods(self, user, basket, shipping_addr=None,
def get_shipping_methods(self, basket, user=None, shipping_addr=None,
request=None, **kwargs):
methods = super(Repository, self).get_shipping_methods(
user, basket, shipping_addr, request, **kwargs)
basket, user, shipping_addr, request, **kwargs)

item_methods = models.OrderAndItemCharges.objects.filter(
countries=shipping_addr.country)
for method in item_methods:
methods.append(self.prime_method(basket, method))
if shipping_addr:
item_methods = models.OrderAndItemCharges.objects.filter(
countries=shipping_addr.country)
for method in item_methods:
methods.append(self.prime_method(basket, method))

return methods
9 changes: 4 additions & 5 deletions sites/us/apps/tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ def apply_to(submission):
unit_tax = (line_tax / line.quantity).quantize(D('0.01'))
line.purchase_info.price.tax = unit_tax

# We don't charge sales tax on shipping
shipping_method = submission['shipping_method']
if shipping_method is not None:
shipping_method.tax = calculate_tax(
shipping_method.charge_excl_tax, rate)
shipping_charge = submission['shipping_charge']
if shipping_charge is not None:
shipping_charge.tax = calculate_tax(
shipping_charge.excl_tax, rate)


def calculate_tax(price, rate):
Expand Down

0 comments on commit 223ed64

Please sign in to comment.