diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-09-24 17:38:55 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-09-24 17:38:55 +0200 |
commit | 6a21a75c0d6695f030f8edebba4f78730467dea4 (patch) | |
tree | adfa33485d23022d38244de112d8544ba42f9e09 /ishtar/ishtar_base/models.py | |
parent | ba442fc40b28790674244d6c9c598c431ce2eead (diff) | |
download | Ishtar-6a21a75c0d6695f030f8edebba4f78730467dea4.tar.bz2 Ishtar-6a21a75c0d6695f030f8edebba4f78730467dea4.zip |
Correct cost and fnap financing (closes #634)
Diffstat (limited to 'ishtar/ishtar_base/models.py')
-rw-r--r-- | ishtar/ishtar_base/models.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py index 67dad81b7..6921b3284 100644 --- a/ishtar/ishtar_base/models.py +++ b/ishtar/ishtar_base/models.py @@ -29,7 +29,7 @@ from django.utils.safestring import SafeUnicode, mark_safe from django.core.urlresolvers import reverse, NoReverseMatch from django.db.utils import DatabaseError from django.db.models import Q, Max, Count, Sum, Avg -from django.db.models.signals import m2m_changed +from django.db.models.signals import m2m_changed, post_save from django.contrib.auth.models import User from django.contrib.gis.db import models @@ -868,7 +868,7 @@ class OperationDashboard: .values('department__pk', 'operation__year')\ .annotate(number=Count('operation'), area=Sum('operation__surface'), - fnap=Sum('operation__fnap_financing'), + fnap=Sum('operation__fnap_cost'), cost=Sum('operation__cost'))\ .order_by('operation__year') dct_years = {} @@ -1363,7 +1363,9 @@ class Operation(BaseHistorizedItem, OwnPerms): TABLE_COLS = ['code_patriarche'] + TABLE_COLS code_dracar = models.CharField(u"Code DRACAR", max_length=10, null=True, blank=True) - fnap_financing = models.FloatField(u"Financement FNAP", + fnap_financing = models.FloatField(u"Financement FNAP (%)", + blank=True, null=True) + fnap_cost = models.IntegerField(u"Financement FNAP (€)", blank=True, null=True) zoning_prescription = models.NullBooleanField( _(u"Prescription on zoning"), blank=True, null=True) @@ -1468,6 +1470,21 @@ class Operation(BaseHistorizedItem, OwnPerms): return {'date':item.history_date, 'user':IshtarUser.objects.get(pk=item.history_modifier_id)} +def operation_post_save(sender, **kwargs): + if not kwargs['instance']: + return + operation = kwargs['instance'] + if operation.fnap_financing and operation.cost: + fnap_cost = int(float(operation.cost)/100*operation.fnap_financing) + if not operation.fnap_cost or operation.fnap_cost != fnap_cost: + operation.fnap_cost = fnap_cost + operation.save() + elif operation.fnap_cost and operation.cost: + fnap_percent = float(operation.fnap_cost)*100/operation.cost + operation.fnap_financing = fnap_percent + operation.save() +post_save.connect(operation_post_save, sender=Operation) + class OperationByDepartment(models.Model): ''' Database view: don't forget to create it |