diff --git a/kfet/migrations/0012_settings.py b/kfet/migrations/0012_settings.py new file mode 100644 index 00000000..8f0f6247 --- /dev/null +++ b/kfet/migrations/0012_settings.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0011_auto_20160807_1720'), + ] + + operations = [ + migrations.CreateModel( + name='Settings', + fields=[ + ('id', models.AutoField(serialize=False, auto_created=True, primary_key=True, verbose_name='ID')), + ('name', models.CharField(max_length=45)), + ('value_decimal', models.DecimalField(null=True, max_digits=6, decimal_places=2, blank=True, default=None)), + ], + ), + ] diff --git a/kfet/models.py b/kfet/models.py index d74eeb7b..57a85320 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -410,13 +410,29 @@ class Operation(models.Model): max_digits = 6, decimal_places = 2, default = 0) - def save(self, *args, **kwargs): - #self.full_clean() - return super(Operation, self).save(*args, **kwargs) - class GlobalPermissions(models.Model): class Meta: managed = False permissions = ( ('is_team', 'Is part of the team'), ) + +class Settings(models.Model): + name = models.CharField(max_length = 45) + value_decimal = models.DecimalField( + max_digits = 6, decimal_places = 2, + blank = True, null = True, default = None) + + @staticmethod + def setting_inst(name): + return Settings.objects.get(name=name) + + @staticmethod + def SUBVENTION_COF(): + try: + return Settings.setting_inst("SUBVENTION_COF").value_decimal + except Settings.DoesNotExist: + return 0 + + class SettingsError(Exception): + pass diff --git a/kfet/views.py b/kfet/views.py index 7c801b9b..c8ca4836 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -10,7 +10,7 @@ from django.contrib.auth.models import User from django.http import HttpResponse, JsonResponse, Http404 from django.forms import modelformset_factory from gestioncof.models import CofProfile, Clipper -from kfet.models import Account, Checkout, Article +from kfet.models import Account, Checkout, Article, Settings from kfet.forms import * from collections import defaultdict @@ -406,11 +406,17 @@ def kpsul_perform_operations(request): operationgroup = operationgroup_form.save(commit = False) operations = operation_formset.save(commit = False) + # Retrieving COF grant + cof_grant = Settings.SUBVENTION_COF() + cof_grant_divisor = 1 + cof_grant / 100 + # Calculating amount of each PURCHASE operations # and total amount for operation group for operation in operations: if operation.type == Operation.PURCHASE: operation.amount = - operation.article.price * operation.article_nb + if operationgroup.on_acc.is_cof: + operation.amount = operation.amount / cof_grant_divisor operationgroup.amount += operation.amount # Filling cof status for statistics