Skip to content

Instantly share code, notes, and snippets.

@nferrari
Last active March 25, 2016 14:36
Show Gist options
  • Save nferrari/7152054 to your computer and use it in GitHub Desktop.
Save nferrari/7152054 to your computer and use it in GitHub Desktop.
django-oscar french strategy
# 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.
"""
@brunifrancesco
Copy link

Hi Nicolas, I'm playing around Django Oscar and I'd like to implement my own pricing strategy.
Where do you place this strategy? I edited oscar.apps.partner.streategy but nothing changed.

Cheers,
Francesco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment