Przeglądaj źródła

Added some basic price/tax calculation methods to the core stock record.

This seems to be a simpler and better place for the price calculation at
the moment.  We could introduce a calculator object at some point to
separate the responsibilities.
master
David Winterbottom 15 lat temu
rodzic
commit
28e72e25ce

+ 1
- 0
oscar/product/abstract_models.py Wyświetl plik

@@ -6,6 +6,7 @@ import re
6 6
 from django.db import models
7 7
 from django.utils.translation import ugettext_lazy as _
8 8
 
9
+from oscar.services import get_price_calculator
9 10
 
10 11
 def _convert_to_underscores(str):
11 12
     """

+ 1
- 1
oscar/product/models.py Wyświetl plik

@@ -8,7 +8,7 @@ class ItemClass(AbstractItemClass):
8 8
 
9 9
 class Item(AbstractItem):
10 10
     pass
11
-
11
+    
12 12
 class AttributeType(AbstractAttributeType):
13 13
     pass
14 14
 

+ 7
- 1
oscar/product/templates/item.html Wyświetl plik

@@ -15,7 +15,13 @@
15 15
         <th>Product class</th><td>{{item.product_class.name}}</td>
16 16
     </tr>
17 17
     <tr>
18
-        <th>Price (excl. tax)</th><td>{{item.stockrecord.price_excl_tax}}</td>
18
+        <th>Price (excl. tax)</th><td>{{item.stockrecord.get_price_incl_tax}}</td>
19
+    </tr>
20
+    <tr>
21
+        <th>Price (incl. tax)</th><td>{{item.stockrecord.get_price_excl_tax}}</td>
22
+    </tr>
23
+    <tr>
24
+        <th>RRP</th><td>{{item.stockrecord.price_excl_tax}}</td>
19 25
     </tr>
20 26
     <tr>
21 27
         <th>Number in stock</th>

+ 0
- 1
oscar/product/tests.py Wyświetl plik

@@ -17,7 +17,6 @@ class TopLevelItemTests(ItemTests):
17 17
     
18 18
     def test_top_level_products_must_have_titles(self):
19 19
         self.assertRaises(ValidationError, Item.objects.create, item_class=self.item_class)
20
-  
21 20
         
22 21
 class VariantItemTests(ItemTests):
23 22
     

+ 16
- 2
oscar/stock/abstract_models.py Wyświetl plik

@@ -34,16 +34,30 @@ class AbstractStockRecord(models.Model):
34 34
     # We deliberately don't store tax information to allow each project
35 35
     # to subclass this model and put its own fields for convey tax.
36 36
     price_currency = models.CharField(max_length=12, default='GBP')
37
+    # This is the base price for calculations
37 38
     price_excl_tax = models.DecimalField(decimal_places=2, max_digits=12)
38
-    price_retail_excl_tax = models.DecimalField(decimal_places=2, max_digits=12)
39 39
     
40 40
     # Stock level information
41
-    num_in_stock = models.IntegerField()
41
+    num_in_stock = models.IntegerField(default=0)
42 42
     num_allocated = models.IntegerField(default=0)
43 43
     
44 44
     class Meta:
45 45
         abstract = True
46 46
         
47
+    # Price retrieval methods - these default to no tax being applicable
48
+    # These are intended to be overridden.    
49
+    def get_price_incl_tax(self):
50
+        return self.get_price_excl_tax()
51
+    
52
+    def get_price_excl_tax(self):
53
+        return self.price_excl_tax
54
+    
55
+    def get_price_tax(self):
56
+        return 0
57
+    
58
+    def get_rrp(self):
59
+        return self.get_price_incl_tax()    
60
+        
47 61
     def __unicode__(self):
48 62
         if self.partner_reference:
49 63
             return "%s (%s): %s" % (self.partner.name, self.partner_reference, self.product.title)

+ 27
- 0
oscar/stock/tests.py Wyświetl plik

@@ -0,0 +1,27 @@
1
+import unittest
2
+from decimal import Decimal as D
3
+
4
+from django.test import TestCase
5
+from django.core.exceptions import ValidationError
6
+
7
+from oscar.product.models import Item, ItemClass
8
+from oscar.stock.models import Partner, StockRecord
9
+
10
+
11
+class StockRecordTests(unittest.TestCase):
12
+
13
+    def setUp(self):
14
+        item_class = ItemClass.objects.create(name='Dummy item class')
15
+        p = Item.objects.create(title="Dummy product", item_class=item_class)
16
+        partner = Partner.objects.create(name='Dummy partner')
17
+        self.record = StockRecord.objects.create(product=p, partner_reference='dummy_ref_123', partner=partner,
18
+                                                 price_excl_tax=D('10.00'))
19
+   
20
+    def test_get_price_incl_tax_defaults_to_no_tax(self):
21
+        self.assertEquals(D('10.00'), self.record.get_price_incl_tax())
22
+        
23
+    def test_get_price_excl_tax_returns_correct_value(self):
24
+        self.assertEquals(D('10.00'), self.record.get_price_excl_tax())
25
+        
26
+    def test_get_rrp_defaults_to_no_tax_price(self):
27
+        self.assertEquals(D('10.00'), self.record.get_rrp())

+ 1
- 0
oscar/tests.py Wyświetl plik

@@ -5,6 +5,7 @@ from django.test import TestCase
5 5
 from oscar.basket.tests import *
6 6
 from oscar.order.tests import *
7 7
 from oscar.product.tests import *
8
+from oscar.stock.tests import *
8 9
 
9 10
 from oscar.services import import_module, AppNotFoundError
10 11
 

Ładowanie…
Anuluj
Zapisz