Browse Source

Add more values to Service.get_prices()

unit_staggered_goods_share & unit_consolidated_cost
Jocelyn Delande 9 years ago
parent
commit
6959146a0f
4 changed files with 27 additions and 9 deletions
  1. 5 0
      costs/models.py
  2. 18 6
      costs/tests/test_models.py
  3. 0 3
      costs/views.py
  4. 4 0
      transparency/settings.py

+ 5 - 0
costs/models.py

@@ -327,11 +327,16 @@ class Service(AbstractResource):
                 total_recurring_price/self.subscriptions_count
                 total_recurring_price/self.subscriptions_count
             unit_goods_value_share = \
             unit_goods_value_share = \
                 total_goods_value_share/self.subscriptions_count
                 total_goods_value_share/self.subscriptions_count
+        unit_staggered_goods_share = \
+            unit_goods_value_share/settings.SETUP_COST_STAGGERING_MONTHS
         return {
         return {
             'total_recurring_price': total_recurring_price,
             'total_recurring_price': total_recurring_price,
             'total_goods_value_share': total_goods_value_share,
             'total_goods_value_share': total_goods_value_share,
             'unit_goods_value_share': unit_goods_value_share,
             'unit_goods_value_share': unit_goods_value_share,
             'unit_recurring_price': unit_recurring_price,
             'unit_recurring_price': unit_recurring_price,
+            'unit_staggered_goods_share': unit_staggered_goods_share,
+            'unit_consolidated_cost': (
+                unit_staggered_goods_share + unit_recurring_price),
         }
         }
 
 
 
 

+ 18 - 6
costs/tests/test_models.py

@@ -27,9 +27,12 @@ class ServiceTests(TestCase):
         s = Service.objects.create(name='Foo', document=self.doc)
         s = Service.objects.create(name='Foo', document=self.doc)
         self.assertEqual(s.get_prices(), {
         self.assertEqual(s.get_prices(), {
             'total_recurring_price': 0,
             'total_recurring_price': 0,
+            'total_goods_value_share': 0,
             'unit_recurring_price': 0,
             'unit_recurring_price': 0,
             'unit_goods_value_share': 0,
             'unit_goods_value_share': 0,
-            'total_goods_value_share': 0,
+            'unit_recurring_price': 0,
+            'unit_consolidated_cost': 0,
+            'unit_staggered_goods_share': 0,
         })
         })
 
 
     def test_get_prices_w_costs(self):
     def test_get_prices_w_costs(self):
@@ -43,6 +46,8 @@ class ServiceTests(TestCase):
             'unit_recurring_price': 0,
             'unit_recurring_price': 0,
             'unit_goods_value_share': 0,
             'unit_goods_value_share': 0,
             'total_goods_value_share': 0,
             'total_goods_value_share': 0,
+            'unit_staggered_goods_share': 0.0,
+            'unit_consolidated_cost': 0,
         })
         })
 
 
         s.subscriptions_count = 2
         s.subscriptions_count = 2
@@ -50,9 +55,11 @@ class ServiceTests(TestCase):
 
 
         self.assertEqual(s.get_prices(), {
         self.assertEqual(s.get_prices(), {
             'total_recurring_price': 10,
             'total_recurring_price': 10,
+            'total_goods_value_share': 0,
             'unit_recurring_price': 5,
             'unit_recurring_price': 5,
             'unit_goods_value_share': 0,
             'unit_goods_value_share': 0,
-            'total_goods_value_share': 0,
+            'unit_staggered_goods_share': 0,
+            'unit_consolidated_cost': 5.0,
         })
         })
 
 
     def test_get_prices_w_goods(self):
     def test_get_prices_w_goods(self):
@@ -66,17 +73,22 @@ class ServiceTests(TestCase):
             'total_recurring_price': 10/(365*3)*365.25/12,
             'total_recurring_price': 10/(365*3)*365.25/12,
             'unit_recurring_price': 0,
             'unit_recurring_price': 0,
             'unit_goods_value_share': 0,
             'unit_goods_value_share': 0,
-            'total_goods_value_share': 10.0,
+            'total_goods_value_share': 10,
+            'unit_consolidated_cost': 0.0,
+            'unit_staggered_goods_share': 0.0,
         })
         })
 
 
         s.subscriptions_count = 2
         s.subscriptions_count = 2
         s.save()
         s.save()
+        total_recurring_price = 10/(365*3)*365.25/12
 
 
         self.assertEqual(s.get_prices(), {
         self.assertEqual(s.get_prices(), {
-            'total_recurring_price': 10/(365*3)*365.25/12,
-            'unit_recurring_price': 10/(365*3)*365.25/12/2,
-            'unit_goods_value_share': 5,
+            'total_recurring_price': total_recurring_price,
             'total_goods_value_share': 10,
             'total_goods_value_share': 10,
+            'unit_recurring_price': total_recurring_price/2,
+            'unit_goods_value_share': 5,
+            'unit_staggered_goods_share': 5/36,
+            'unit_consolidated_cost': total_recurring_price/2 + 5/36,
         })
         })
 
 
 
 

+ 0 - 3
costs/views.py

@@ -58,7 +58,6 @@ def detail_service(request, pk):
 
 
     context = {}
     context = {}
     context.update(service.get_prices())
     context.update(service.get_prices())
-    unit_staggered_goods_share = context['unit_goods_value_share']/36
     context.update({
     context.update({
         'breadcrumbs': breadcrumbs,
         'breadcrumbs': breadcrumbs,
         'document': doc,
         'document': doc,
@@ -66,7 +65,5 @@ def detail_service(request, pk):
         'costs_uses': costs_uses,
         'costs_uses': costs_uses,
         'goods_uses': goods_uses,
         'goods_uses': goods_uses,
         'services_uses': services_uses,
         'services_uses': services_uses,
-        'unit_staggered_goods_share': unit_staggered_goods_share,
-        'unit_consolidated_cost': unit_staggered_goods_share + context['unit_recurring_price'],
     })
     })
     return render(request, 'costs/service_detail.html', context)
     return render(request, 'costs/service_detail.html', context)

+ 4 - 0
transparency/settings.py

@@ -110,6 +110,10 @@ PROVISIONING_DURATIONS = [
     (datetime.timedelta(days=365*5), '5 ans'),
     (datetime.timedelta(days=365*5), '5 ans'),
 ]
 ]
 
 
+## How many months do we suggest setup costs staggering accross ?
+
+SETUP_COST_STAGGERING_MONTHS = 36
+
 try:
 try:
     from .local_settings import *
     from .local_settings import *
 except ImportError:
 except ImportError: