Skip to content

Commit

Permalink
TESTS FAIL
Browse files Browse the repository at this point in the history
Made extra price modifiers ordered (a list).
  • Loading branch information
Chris Glass committed Mar 7, 2011
1 parent 493f02e commit c7f7813
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions shop/cart/modifiers/product_options.py
Expand Up @@ -16,7 +16,7 @@ def add_extra_cart_item_price_field(self, cart_item):

for selected_opt in selected_options:
option_obj = selected_opt.option
data = {option_obj.name: option_obj.price}
cart_item.extra_price_fields.update(data)
data = (option_obj.name, option_obj.price)
cart_item.extra_price_fields.append(data)

return cart_item
3 changes: 2 additions & 1 deletion shop/cart/modifiers/rebate_modifiers.py
Expand Up @@ -17,5 +17,6 @@ def add_extra_cart_item_price_field(self, cart_item):
NUMBER_OF_ITEMS_TO_TRIGGER_REBATE = 5
if cart_item.quantity >= NUMBER_OF_ITEMS_TO_TRIGGER_REBATE:
rebate = (REBATE_PERCENTAGE/100) * cart_item.line_subtotal
cart_item.extra_price_fields.update({'Rebate': -rebate})
to_append = ('Rebate', -rebate)
cart_item.extra_price_fields.append(to_append)
return cart_item
13 changes: 11 additions & 2 deletions shop/cart/modifiers/tax_modifiers.py
Expand Up @@ -19,5 +19,14 @@ def add_extra_cart_price_field(self, cart):
Add a field on cart.extra_price_fields:
'''
taxes = (self.TAX_PERCENTAGE/100) * cart.subtotal_price
cart.extra_price_fields.update({'Taxes total':taxes})
return cart
to_append = ('Taxes total', taxes)
cart.extra_price_fields.append(to_append)
return cart

class TenPercentPerItemTaxModifier(BaseCartModifier):
'''
This adds a 10% tax cart modifier on
'''
TAX_PERCENTAGE = Decimal("10")


8 changes: 4 additions & 4 deletions shop/models/cartmodel.py
Expand Up @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs):
# That will hold things like tax totals or total discount
self.subtotal_price = Decimal('0.0')
self.total_price = Decimal('0.0')
self.extra_price_fields = {}
self.extra_price_fields = [] # List of tuples (label, value)
self.update() # This populates transient fields when coming from the DB

def add_product(self,product, quantity=1):
Expand Down Expand Up @@ -73,7 +73,7 @@ def update(self):
self.total_price = self.subtotal_price
# Like for line items, most of the modifiers will simply add a field
# to extra_price_fields, let's update the total with them
for value in self.extra_price_fields.values():
for (label, value) in self.extra_price_fields:
self.total_price = self.total_price + value


Expand All @@ -95,7 +95,7 @@ def __init__(self, *args, **kwargs):
# That will hold extra fields to display to the user
# (ex. taxes, discount)
super(CartItem, self).__init__(*args,**kwargs)
self.extra_price_fields = {}
self.extra_price_fields = [] # list of tuples (label, value)
# These must not be stored, since their components can be changed between
# sessions / logins etc...
self.line_subtotal = Decimal('0.0')
Expand All @@ -110,7 +110,7 @@ def update(self):
# We now loop over every registered price modifier,
# most of them will simply add a field to extra_payment_fields
modifier.process_cart_item(self)
for value in self.extra_price_fields.values():
for (label, value) in self.extra_price_fields:
self.line_total = self.line_total + value

return self.line_total
Expand Down
4 changes: 2 additions & 2 deletions shop/models/ordermodel.py
Expand Up @@ -60,7 +60,7 @@ def create_from_cart(self, cart):
o.billing_country = bill_address.country.name
o.save()
# Let's serialize all the extra price arguments in DB
for label, value in cart.extra_price_fields.iteritems():
for label, value in cart.extra_price_fields:
eoi = ExtraOrderPriceField()
eoi.order = o
eoi.label = label
Expand All @@ -80,7 +80,7 @@ def create_from_cart(self, cart):
i.line_subtotal = item.line_subtotal
i.save()
# For each order item, we save the extra_price_fields to DB
for label, value in item.extra_price_fields.iteritems():
for label, value in item.extra_price_fields:
eoi = ExtraOrderItemPriceField()
eoi.order_item = i
eoi.label = label
Expand Down

0 comments on commit c7f7813

Please sign in to comment.