diff --git a/kfet/forms.py b/kfet/forms.py
index 0281efab..54c0dd38 100644
--- a/kfet/forms.py
+++ b/kfet/forms.py
@@ -54,6 +54,11 @@ class AccountForm(forms.ModelForm):
'trigramme': forms.TextInput(attrs={'autocomplete': 'off'}),
}
+class AccountBalanceForm(forms.ModelForm):
+ class Meta:
+ model = Account
+ fields = ['balance']
+
class AccountTriForm(AccountForm):
def clean_trigramme(self):
diff --git a/kfet/migrations/0045_auto_20160905_0705.py b/kfet/migrations/0045_auto_20160905_0705.py
new file mode 100644
index 00000000..0673fdca
--- /dev/null
+++ b/kfet/migrations/0045_auto_20160905_0705.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('kfet', '0044_auto_20160901_1614'),
+ ]
+
+ operations = [
+ migrations.AlterModelOptions(
+ name='globalpermissions',
+ options={'managed': False, 'permissions': (('is_team', 'Is part of the team'), ('perform_deposit', 'Effectuer une charge'), ('perform_negative_operations', 'Enregistrer des commandes en n\xe9gatif'), ('override_frozen_protection', "Forcer le gel d'un compte"), ('cancel_old_operations', 'Annuler des commandes non r\xe9centes'), ('manage_perms', 'G\xe9rer les permissions K-F\xeat'), ('manage_addcosts', 'G\xe9rer les majorations'), ('perform_commented_operations', 'Enregistrer des commandes avec commentaires'), ('view_negs', 'Voir la liste des n\xe9gatifs'), ('order_to_inventory', "G\xe9n\xe9rer un inventaire \xe0 partir d'une commande"), ('edit_balance_account', "Modifier la balance d'un compte"), ('change_account_password', "Modifier le mot de passe d'une personne de l'\xe9quipe"), ('special_add_account', 'Cr\xe9er un compte avec une balance initiale'))},
+ ),
+ migrations.AlterField(
+ model_name='operation',
+ name='type',
+ field=models.CharField(max_length=8, choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial')]),
+ ),
+ ]
diff --git a/kfet/models.py b/kfet/models.py
index 5e333b76..6a6807aa 100644
--- a/kfet/models.py
+++ b/kfet/models.py
@@ -508,11 +508,13 @@ class Operation(models.Model):
PURCHASE = 'purchase'
DEPOSIT = 'deposit'
WITHDRAW = 'withdraw'
+ INITIAL = 'initial'
TYPE_ORDER_CHOICES = (
(PURCHASE, 'Achat'),
(DEPOSIT, 'Charge'),
(WITHDRAW, 'Retrait'),
+ (INITIAL, 'Initial'),
)
group = models.ForeignKey(
@@ -563,6 +565,7 @@ class GlobalPermissions(models.Model):
('order_to_inventory', "Générer un inventaire à partir d'une commande"),
('edit_balance_account', "Modifier la balance d'un compte"),
('change_account_password', "Modifier le mot de passe d'une personne de l'équipe"),
+ ('special_add_account', "Créer un compte avec une balance initiale")
)
class Settings(models.Model):
diff --git a/kfet/templates/kfet/account_create_special.html b/kfet/templates/kfet/account_create_special.html
new file mode 100644
index 00000000..a002d40e
--- /dev/null
+++ b/kfet/templates/kfet/account_create_special.html
@@ -0,0 +1,96 @@
+{% extends "kfet/base.html" %}
+{% load staticfiles %}
+
+{% block title %}Nouveau compte{% endblock %}
+
+{% block extra_head %}
+
+{% endblock %}
+
+{% block content-header-title %}Création d'un compte{% endblock %}
+
+{% block content %}
+
+{% include 'kfet/base_messages.html' %}
+
+
+
+
+{% endblock %}
diff --git a/kfet/templates/kfet/history.html b/kfet/templates/kfet/history.html
index 881a5fa9..faab76dd 100644
--- a/kfet/templates/kfet/history.html
+++ b/kfet/templates/kfet/history.html
@@ -212,9 +212,11 @@ $(document).ready(function() {
content += ''+data['errors']['missing_perms'][i]+'';
content += '';
}
- if ('negative' in data['errors'])
+ if ('negative' in data['errors']) {
for (var i=0; iAutorisation de négatif requise pour '+data['errors']['negative'][i]+'';
+ }
+ }
return content;
}
diff --git a/kfet/urls.py b/kfet/urls.py
index 3422c671..e0bacf9a 100644
--- a/kfet/urls.py
+++ b/kfet/urls.py
@@ -31,6 +31,8 @@ urlpatterns = [
# Account - Create
url(r'^accounts/new$', views.account_create,
name = 'kfet.account.create'),
+ url(r'^accounts/new_special$', views.account_create_special,
+ name = 'kfet.account.create_special'),
url(r'^accounts/new/user/(?P.+)$', views.account_create_ajax,
name = 'kfet.account.create.fromuser'),
url(r'^accounts/new/clipper/(?P.+)$', views.account_create_ajax,
diff --git a/kfet/views.py b/kfet/views.py
index f9c4d288..53c3412c 100644
--- a/kfet/views.py
+++ b/kfet/views.py
@@ -83,6 +83,81 @@ def account_is_validandfree_ajax(request):
# Account - Create
+@login_required
+@teamkfet_required
+def account_create_special(request):
+
+ # Enregistrement
+ if request.method == "POST":
+ trigramme_form = AccountTriForm(request.POST, initial={'balance':0})
+ balance_form = AccountBalanceForm(request.POST)
+
+ # Peuplement des forms
+ username = request.POST.get('username')
+ login_clipper = request.POST.get('login_clipper')
+
+ forms = get_account_create_forms(
+ request, username=username, login_clipper=login_clipper)
+
+ account_form = forms['account_form']
+ cof_form = forms['cof_form']
+ user_form = forms['user_form']
+
+ if all((user_form.is_valid(), cof_form.is_valid(),
+ trigramme_form.is_valid(), account_form.is_valid(),
+ balance_form.is_valid())):
+ # Checking permission
+ if not request.user.has_perm('kfet.special_add_account'):
+ messages.error(request, 'Permission refusée')
+ else:
+ data = {}
+ # Fill data for Account.save()
+ put_cleaned_data_in_dict(data, user_form)
+ put_cleaned_data_in_dict(data, cof_form)
+
+ try:
+ account = trigramme_form.save(data = data)
+ account_form = AccountNoTriForm(request.POST, instance=account)
+ account_form.save()
+ balance_form = AccountBalanceForm(request.POST, instance=account)
+ balance_form.save()
+ amount = balance_form.cleaned_data['balance']
+ checkout = Checkout.objects.get(name='Initial')
+ is_cof = account.is_cof
+ opegroup = OperationGroup.objects.create(
+ on_acc=account,
+ checkout=checkout,
+ amount = amount,
+ is_cof = account.is_cof)
+ ope = Operation.objects.create(
+ group = opegroup,
+ type = Operation.INITIAL,
+ amount = amount,
+ is_checkout = False)
+ messages.success(request, 'Compte créé : %s' % account.trigramme)
+ return redirect('kfet.account.create')
+ except Account.UserHasAccount as e:
+ messages.error(request, \
+ "Cet utilisateur a déjà un compte K-Fêt : %s" % e.trigramme)
+ else:
+ initial = { 'trigramme': request.GET.get('trigramme', '') }
+ trigramme_form = AccountTriForm(initial = initial)
+ balance_form = AccountBalanceForm(initial = {'balance': 0})
+ account_form = None
+ cof_form = None
+ user_form = None
+
+ return render(request, "kfet/account_create_special.html", {
+ 'trigramme_form': trigramme_form,
+ 'account_form': account_form,
+ 'cof_form': cof_form,
+ 'user_form': user_form,
+ 'balance_form': balance_form,
+ })
+
+
+# Account - Create
+
@login_required
@teamkfet_required
def account_create(request):