forked from DGNum/gestioCOF
Merge branch 'master' into aureplop/fewer_requests
This commit is contained in:
commit
b5cc26bb1b
22 changed files with 431 additions and 282 deletions
|
@ -6,7 +6,7 @@ from urllib.parse import urlencode
|
|||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.cache import cache
|
||||
from django.views.generic import ListView, DetailView, TemplateView
|
||||
from django.views.generic import ListView, DetailView, TemplateView, FormView
|
||||
from django.views.generic.detail import BaseDetailView
|
||||
from django.views.generic.edit import CreateView, UpdateView
|
||||
from django.core.urlresolvers import reverse, reverse_lazy
|
||||
|
@ -24,9 +24,11 @@ from django.utils import timezone
|
|||
from django.utils.crypto import get_random_string
|
||||
from django.utils.decorators import method_decorator
|
||||
from gestioncof.models import CofProfile
|
||||
|
||||
from kfet.config import kfet_config
|
||||
from kfet.decorators import teamkfet_required
|
||||
from kfet.models import (
|
||||
Account, Checkout, Article, Settings, AccountNegative,
|
||||
Account, Checkout, Article, AccountNegative,
|
||||
CheckoutStatement, GenericTeamToken, Supplier, SupplierArticle, Inventory,
|
||||
InventoryArticle, Order, OrderArticle, Operation, OperationGroup,
|
||||
TransferGroup, Transfer, ArticleCategory)
|
||||
|
@ -37,9 +39,9 @@ from kfet.forms import (
|
|||
GroupForm, CheckoutForm, CheckoutRestrictForm, CheckoutStatementCreateForm,
|
||||
CheckoutStatementUpdateForm, ArticleForm, ArticleRestrictForm,
|
||||
KPsulOperationGroupForm, KPsulAccountForm, KPsulCheckoutForm,
|
||||
KPsulOperationFormSet, AddcostForm, FilterHistoryForm, SettingsForm,
|
||||
KPsulOperationFormSet, AddcostForm, FilterHistoryForm,
|
||||
TransferFormSet, InventoryArticleForm, OrderArticleForm,
|
||||
OrderArticleToInventoryForm, CategoryForm
|
||||
OrderArticleToInventoryForm, CategoryForm, KFetConfigForm
|
||||
)
|
||||
from collections import defaultdict
|
||||
from kfet import consumers
|
||||
|
@ -381,7 +383,6 @@ def account_read(request, trigramme):
|
|||
return render(request, "kfet/account_read.html", {
|
||||
'account': account,
|
||||
'addcosts': addcosts,
|
||||
'settings': {'subvention_cof': Settings.SUBVENTION_COF()},
|
||||
})
|
||||
|
||||
# Account - Update
|
||||
|
@ -571,10 +572,6 @@ class AccountNegativeList(ListView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AccountNegativeList, self).get_context_data(**kwargs)
|
||||
context['settings'] = {
|
||||
'overdraft_amount': Settings.OVERDRAFT_AMOUNT(),
|
||||
'overdraft_duration': Settings.OVERDRAFT_DURATION(),
|
||||
}
|
||||
real_balances = (neg.account.real_balance for neg in self.object_list)
|
||||
context['negatives_sum'] = sum(real_balances)
|
||||
return context
|
||||
|
@ -920,14 +917,15 @@ def kpsul(request):
|
|||
|
||||
@teamkfet_required
|
||||
def kpsul_get_settings(request):
|
||||
addcost_for = Settings.ADDCOST_FOR()
|
||||
addcost_for = kfet_config.addcost_for
|
||||
data = {
|
||||
'subvention_cof': Settings.SUBVENTION_COF(),
|
||||
'addcost_for' : addcost_for and addcost_for.trigramme or '',
|
||||
'addcost_amount': Settings.ADDCOST_AMOUNT(),
|
||||
'subvention_cof': kfet_config.subvention_cof,
|
||||
'addcost_for': addcost_for and addcost_for.trigramme or '',
|
||||
'addcost_amount': kfet_config.addcost_amount,
|
||||
}
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
@teamkfet_required
|
||||
def account_read_json(request):
|
||||
trigramme = request.POST.get('trigramme', '')
|
||||
|
@ -967,6 +965,7 @@ def kpsul_checkout_data(request):
|
|||
raise Http404
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
@teamkfet_required
|
||||
def kpsul_update_addcost(request):
|
||||
addcost_form = AddcostForm(request.POST)
|
||||
|
@ -986,15 +985,15 @@ def kpsul_update_addcost(request):
|
|||
|
||||
trigramme = addcost_form.cleaned_data['trigramme']
|
||||
account = trigramme and Account.objects.get(trigramme=trigramme) or None
|
||||
Settings.objects.filter(name='ADDCOST_FOR').update(value_account=account)
|
||||
(Settings.objects.filter(name='ADDCOST_AMOUNT')
|
||||
.update(value_decimal=addcost_form.cleaned_data['amount']))
|
||||
cache.delete('ADDCOST_FOR')
|
||||
cache.delete('ADDCOST_AMOUNT')
|
||||
amount = addcost_form.cleaned_data['amount']
|
||||
|
||||
kfet_config.set(addcost_for=account,
|
||||
addcost_amount=amount)
|
||||
|
||||
data = {
|
||||
'addcost': {
|
||||
'for': trigramme and account.trigramme or None,
|
||||
'amount': addcost_form.cleaned_data['amount'],
|
||||
'for': account and account.trigramme or None,
|
||||
'amount': amount,
|
||||
}
|
||||
}
|
||||
consumers.KPsul.group_send('kfet.kpsul', data)
|
||||
|
@ -1038,10 +1037,10 @@ def kpsul_perform_operations(request):
|
|||
operations = operation_formset.save(commit=False)
|
||||
|
||||
# Retrieving COF grant
|
||||
cof_grant = Settings.SUBVENTION_COF()
|
||||
cof_grant = kfet_config.subvention_cof
|
||||
# Retrieving addcosts data
|
||||
addcost_amount = Settings.ADDCOST_AMOUNT()
|
||||
addcost_for = Settings.ADDCOST_FOR()
|
||||
addcost_amount = kfet_config.addcost_amount
|
||||
addcost_for = kfet_config.addcost_for
|
||||
|
||||
# Initializing vars
|
||||
required_perms = set() # Required perms to perform all operations
|
||||
|
@ -1232,7 +1231,7 @@ def kpsul_cancel_operations(request):
|
|||
opes = [] # Pas déjà annulée
|
||||
required_perms = set()
|
||||
stop_all = False
|
||||
cancel_duration = Settings.CANCEL_DURATION()
|
||||
cancel_duration = kfet_config.cancel_duration
|
||||
to_accounts_balances = defaultdict(lambda:0) # Modifs à faire sur les balances des comptes
|
||||
to_groups_amounts = defaultdict(lambda:0) # ------ sur les montants des groupes d'opé
|
||||
to_checkouts_balances = defaultdict(lambda:0) # ------ sur les balances de caisses
|
||||
|
@ -1460,34 +1459,28 @@ def kpsul_articles_data(request):
|
|||
.filter(is_sold=True))
|
||||
return JsonResponse({ 'articles': list(articles) })
|
||||
|
||||
|
||||
@teamkfet_required
|
||||
def history(request):
|
||||
data = {
|
||||
'filter_form': FilterHistoryForm(),
|
||||
'settings': {
|
||||
'subvention_cof': Settings.SUBVENTION_COF(),
|
||||
}
|
||||
}
|
||||
return render(request, 'kfet/history.html', data)
|
||||
|
||||
|
||||
# -----
|
||||
# Settings views
|
||||
# -----
|
||||
|
||||
class SettingsList(ListView):
|
||||
model = Settings
|
||||
context_object_name = 'settings'
|
||||
|
||||
class SettingsList(TemplateView):
|
||||
template_name = 'kfet/settings.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
Settings.create_missing()
|
||||
return super(SettingsList, self).get_context_data(**kwargs)
|
||||
|
||||
class SettingsUpdate(SuccessMessageMixin, UpdateView):
|
||||
model = Settings
|
||||
form_class = SettingsForm
|
||||
class SettingsUpdate(SuccessMessageMixin, FormView):
|
||||
form_class = KFetConfigForm
|
||||
template_name = 'kfet/settings_update.html'
|
||||
success_message = 'Paramètre %(name)s mis à jour'
|
||||
success_message = 'Paramètres mis à jour'
|
||||
success_url = reverse_lazy('kfet.settings')
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -1495,9 +1488,9 @@ class SettingsUpdate(SuccessMessageMixin, UpdateView):
|
|||
if not self.request.user.has_perm('kfet.change_settings'):
|
||||
form.add_error(None, 'Permission refusée')
|
||||
return self.form_invalid(form)
|
||||
# Creating
|
||||
Settings.empty_cache()
|
||||
return super(SettingsUpdate, self).form_valid(form)
|
||||
form.save()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
|
||||
# -----
|
||||
|
@ -1636,7 +1629,7 @@ def cancel_transfers(request):
|
|||
transfers = [] # Pas déjà annulée
|
||||
required_perms = set()
|
||||
stop_all = False
|
||||
cancel_duration = Settings.CANCEL_DURATION()
|
||||
cancel_duration = kfet_config.cancel_duration
|
||||
to_accounts_balances = defaultdict(lambda:0) # Modifs à faire sur les balances des comptes
|
||||
for transfer in transfers_all:
|
||||
if transfer.canceled_at:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue