Last active
March 25, 2016 14:36
-
-
Save nferrari/7152054 to your computer and use it in GitHub Desktop.
django-oscar french strategy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# myapp/partner/strategy.py | |
from decimal import Decimal as D | |
from oscar.apps.partner import strategy, prices | |
DEFAULT_RATE = D('0.196') | |
PRODUCT_CLASSES_RATES = { | |
'cours': 0, | |
'medias': D('0.055'), | |
} | |
class Selector(object): | |
""" | |
Custom selector to return a FR-specific strategy that charges VAT | |
""" | |
def strategy(self, request=None, user=None, **kwargs): | |
return FRStrategy(request) | |
class FrenchFixedRateTax(object): | |
""" | |
This mixin applies a french fixed rate tax to the base price from the product's | |
stockrecord. How is the rate discovered: | |
_ found in PRODUCT_CLASSES_RATES setting | |
_ otherwise apply default rate | |
""" | |
def pricing_policy(self, product, stockrecord): | |
self.rate = PRODUCT_CLASSES_RATES.get( | |
product.get_product_class().slug, | |
DEFAULT_RATE) | |
if not stockrecord: | |
return prices.Unavailable() | |
return prices.FixedPrice( | |
currency=stockrecord.price_currency, | |
excl_tax=stockrecord.price_excl_tax, | |
tax=stockrecord.price_excl_tax * self.rate) | |
class FRStrategy( | |
strategy.UseFirstStockRecord, | |
FrenchFixedRateTax, | |
strategy.StockRequired, | |
strategy.Structured): | |
""" | |
Typical FR strategy for physical goods. | |
- There's only one warehouse/partner so we use the first and only stockrecord | |
- Enforce stock level. Don't allow purchases when we don't have stock. | |
- Charge FR VAT on prices. Assume everything is standard-rated. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://django-oscar.readthedocs.org/en/latest/topics/customisation.html#fork-the-oscar-app