Coverage for /home/tribaal/workspace/django-shop/shop/cart/modifiers/tax_modifiers: 100.00%

# Coverage for /home/tribaal/workspace/django-shop/shop/cart/modifiers/tax_modifiers : 100.00%

## 14 statements 14 run 0 missing 0 excluded 0 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # -*- coding: utf-8 -*- from decimal import Decimal from shop.cart.cart_modifiers_base import BaseCartModifier class TenPercentGlobalTaxModifier(BaseCartModifier): """ A basic Tax calculator: it simply adds a taxes field to the *order*, and makes it a fixed percentage of the subtotal (10%) Obviously, this is only provided as an example, and anything serious should use a more dynamic configuration system, such as settings or models to hold the tax values... """ TAX_PERCENTAGE = Decimal('10') def get_extra_cart_price_field(self, cart): """ Add a field on cart.extra_price_fields: """ taxes = (self.TAX_PERCENTAGE / 100) * cart.current_total result_tuple = ('Taxes total', taxes) return result_tuple class TenPercentPerItemTaxModifier(BaseCartModifier): """ This adds a 10% tax cart modifier, calculated on the item's base price, plus any modifier applied to the cart item *so far* (order matters!). Make sure the moment you apply taxes comply with your local regulations! Some countries insist that taxes are calculated after/before discounts, and so forth """ TAX_PERCENTAGE = Decimal("10") def get_extra_cart_item_price_field(self, cart_item): tax_amount = (self.TAX_PERCENTAGE / 100) * cart_item.current_total result_tuple = ('Taxes (10%)', tax_amount) return result_tuple