Explorar el Código

Added recipe on tax exemptions

master
David Winterbottom hace 13 años
padre
commit
bd9d70d38e

+ 1
- 1
README.rst Ver fichero

@@ -59,6 +59,6 @@ companies, from large multinationals to small, boutique stores:
59 59
 * Carlsberg - Their global "We Deliver More" platform is powered by Oscar (but
60 60
   is a B2B site so it not browsable by the public).
61 61
 * Dolbeau - http://www.dolbeau.ca/
62
-* The UK Labour party - http://shop.labour.org.uk (will be live in early June)
62
+* The UK Labour party - http://shop.labour.org.uk
63 63
 
64 64
 Many more on the way.  If you use Oscar in production, please let us know.

+ 8
- 0
docs/source/recipes.rst Ver fichero

@@ -36,6 +36,14 @@ Pricing, stock and availability
36 36
     recipes/enforcing_stock_rules
37 37
     recipes/how_to_configure_stock_messaging
38 38
 
39
+Tax
40
+---
41
+
42
+.. toctree::
43
+    :maxdepth: 1
44
+
45
+    recipes/how_to_apply_tax_exemptions
46
+
39 47
 Shipping
40 48
 --------
41 49
 

+ 55
- 0
docs/source/recipes/how_to_apply_tax_exemptions.rst Ver fichero

@@ -0,0 +1,55 @@
1
+===========================
2
+How to apply tax exemptions
3
+===========================
4
+
5
+Problem
6
+=======
7
+The tax a customer pays depends on the shipping address of his/her
8
+order.  
9
+
10
+Solution
11
+========
12
+Use custom basket middleware to set the tax status of the basket.
13
+
14
+The default Oscar basket middleware is::
15
+
16
+    'oscar.apps.basket.middleware.BasketMiddleware'
17
+
18
+To alter the tax behaviour, replace this class with one within your own project
19
+that subclasses Oscar's and extends the ``get_basket`` method.  For example, use
20
+something like::
21
+
22
+    from oscar.apps.basket.middleware import BasketMiddleware
23
+    from oscar.apps.checkout.utils import CheckoutSessionData
24
+
25
+    class MyBasketMiddleware(BasketMiddleware):
26
+        
27
+        def get_basket(self, request):
28
+            basket = super(MyBasketMiddleware, self).get_basket(request)
29
+            if self.is_tax_exempt(request):
30
+                basket.set_as_tax_exempt()
31
+            return basket
32
+
33
+        def is_tax_exempt(self, request):
34
+            country = self.get_shipping_address_country(request)
35
+            if country is None:
36
+                return False
37
+            return country.iso_3166_1_a2 not in ('GB',)
38
+
39
+        def get_shipping_address_country(self, request):
40
+            session = CheckoutSessionData(request)
41
+            if not session.is_shipping_address_set():
42
+                return None
43
+            addr_id = session.shipping_user_address_id()
44
+            if addr_id:
45
+                # User shipping to address from address book
46
+                return UserAddress.objects.get(id=addr_id).country
47
+            else:
48
+                fields = session.new_shipping_address_fields()
49
+        
50
+Here we are using the checkout session wrapper to check if the user has set a
51
+shipping address.  If they have, we extract the country and check its ISO
52
+3166 code.
53
+
54
+It is straightforward to extend this idea to apply custom tax exemptions to the
55
+basket based of different criteria.

+ 1
- 1
docs/source/recipes/how_to_configure_shipping.rst Ver fichero

@@ -32,7 +32,7 @@ Set a custom shipping methods
32 32
 -----------------------------
33 33
 
34 34
 To apply your domain logic for shipping, you will need to override
35
-the default repository class (see :doc:`recipes/how_to_override_a_core_class`) and alter
35
+the default repository class (see :doc:`how_to_override_a_core_class`) and alter
36 36
 the implementation of the ``get_shipping_methods`` method.  This method
37 37
 should return a list of "shipping method" classes already instantiated
38 38
 and holding a reference to the basket instance.

+ 1
- 1
sandbox/settings.py Ver fichero

@@ -247,7 +247,7 @@ from oscar.defaults import *
247 247
 
248 248
 
249 249
 OSCAR_RECENTLY_VIEWED_PRODUCTS = 20
250
-OSCAR_ALLOW_ANON_CHECKOUT = False
250
+OSCAR_ALLOW_ANON_CHECKOUT = True
251 251
 OSCAR_INITIAL_ORDER_STATUS = 'Pending'
252 252
 OSCAR_INITIAL_LINE_STATUS = 'Pending'
253 253
 OSCAR_ORDER_STATUS_PIPELINE = {

Loading…
Cancelar
Guardar