Browse Source

Consider access fee for services using services

Jocelyn Delande 9 years ago
parent
commit
f1753391f1
3 changed files with 30 additions and 2 deletions
  1. 5 1
      costs/models.py
  2. 12 0
      costs/templates/costs/service_detail.html
  3. 13 1
      costs/tests/test_models.py

+ 5 - 1
costs/models.py

@@ -262,7 +262,8 @@ class Service(AbstractResource):
             (i.cost_share() for i in services_uses)
         ))
 
-        total_goods_value_share = sum(i.value_share() for i in goods_uses)
+        total_goods_value_share = sum(
+            (i.value_share() for i in chain(goods_uses, services_uses)))
 
         if self.subscriptions_count == 0:
             unit_recurring_price = 0
@@ -303,6 +304,9 @@ class ServiceUse(AbstractUse):
         else:
             return self.cost_share()/self.service.subscriptions_count
 
+    def value_share(self):
+        return self.share*self.resource.get_prices()['unit_goods_value_share']
+
     def clean(self):
         """ Checks for cycles in service using services
         """

+ 12 - 0
costs/templates/costs/service_detail.html

@@ -171,6 +171,18 @@ d'avance de trésorerie)</li>
         <td>{{ good_use.unit_value_share|price }}</td>
       </tr>
 {% endfor %}
+{% for service_use in services_uses %}
+      <tr>
+        <td>
+          FAS service
+          <a href="{{ service_use.resource.get_absolute_url }}">
+            {{ service_use.resource.name }}
+          </a>
+        </td>
+        <td>{{ service_use.unit_value_share|price }}</td>
+      </tr>
+{% endfor %}
+
     </tbody>
     <tfoot>
       <tr>

+ 13 - 1
costs/tests/test_models.py

@@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError
 from ..models import (
     Cost, CostUse, Document, Good, GoodUse, Service, ServiceUse)
 
+THREE_YEARS = datetime.timedelta(days=365*3)
 
 class ServiceTests(TestCase):
     def setUp(self):
@@ -19,7 +20,7 @@ class ServiceTests(TestCase):
             name="Computer",
             price=10,
             document=self.doc,
-            provisioning_duration=datetime.timedelta(days=365*3),
+            provisioning_duration=THREE_YEARS,
         )
 
     def test_get_prices_zero(self):
@@ -283,6 +284,17 @@ class AbstractUseTests(TestCase):
         # VPN this is the only service using electricity
         self.assertEqual(wifi_vpn_use.unit_real_share(), 10)
 
+        # VPN is now using some gear, with deprecation provisioning
+        hosting_access_fee = Good.objects.create(
+            name='hosting access fee', price=360,
+            provisioning_duration=THREE_YEARS, document=self.doc)
+        GoodUse.objects.create(
+            service=vpn_service, resource=hosting_access_fee, share=2)
+        self.assertEqual(
+            wifi_service.get_prices()['total_goods_value_share'], 36)
+        self.assertEqual(
+            wifi_service.get_prices()['unit_goods_value_share'], 18)
+
     def test_service_using_non_usable_service(self):
         serva = Service.objects.create(
             name='A', document=self.doc,