Calcul du montant des opérations achats

- Ajout d'un modèle settings
- Ajout de la prise en compte du statut COF dans le montant d'une
  opération achat avec la majoration définie dans le modèle settings
  (name="SUBVENTION_COF")
This commit is contained in:
Aurélien Delobelle 2016-08-07 18:37:06 +02:00
parent 49bb7d99cd
commit 346cbb2695
3 changed files with 49 additions and 5 deletions

View file

@ -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)),
],
),
]

View file

@ -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

View file

@ -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