Ajout liste transferts

This commit is contained in:
Aurélien Delobelle 2016-08-26 20:14:00 +02:00
parent 022e1f3984
commit be8243c4ce
5 changed files with 85 additions and 24 deletions

View file

@ -1,3 +1,20 @@
.transfer_general {
margin:15px 0;
height:45px;
}
.transfer_general input {
height:100%;
border:0;
padding:0 5px;
font-size:16px;
}
.transfer_general button {
height:100%;
margin-top:-3px;
}
.transfer_formset { .transfer_formset {
background:#FFF; background:#FFF;
} }
@ -11,11 +28,9 @@
text-align:center; text-align:center;
} }
.transfer_form {
height:50px;
}
.transfer_form td { .transfer_form td {
height:50px;
vertical-align:middle;
padding:0 !important; padding:0 !important;
} }
@ -31,13 +46,13 @@
font-weight:bold; font-weight:bold;
text-align:center; text-align:center;
vertical-align:middle;
text-transform:uppercase; text-transform:uppercase;
} }
.transfer_form .from_acc_data, .transfer_form .to_acc_data { .transfer_form .from_acc_data, .transfer_form .to_acc_data {
width:30%; width:30%;
text-align:center; text-align:center;
vertical-align:middle;
font-size:20px; font-size:20px;
} }

View file

@ -6,11 +6,42 @@
{% block content %} {% block content %}
<div class="row"> <div class="row">
<form action="" method="post"> <div class="col-sm-4 col-md-3 col-content-left">
{% csrf_token %} <div class="content-left">
{{ form }} <div class="content-left-top">
<input type="submit" value="Enregistrer"> </div>
</form> <div class="buttons">
<a class="btn btn-primary btn-lg" href="{% url 'kfet.transfers.create' %}">
Nouveaux
</a>
</div>
</div>
</div>
<div class="col-sm-8 col-md-9 col-content-right">
{% include 'kfet/base_messages.html' %}
<div class="content-right">
<div class="content-right-block">
<h2>Liste des transferts</h2>
<div id="history">
{% for transfergroup in transfergroups %}
<div class="opegroup">
<span>{{ transfergroup.at }}</span>
<span>{{ transfergroup.valid_by.trigramme }}</span>
<span>{{ transfergroup.comment }}</span>
</div>
{% for transfer in transfergroup.transfers.all %}
<div>
<span>{{ transfer.amount }} €</span>
<span>{{ transfer.from_acc.trigramme }}</span>
<span>--></span>
<span>{{ transfer.to_acc.trigramme }}</span>
</div>
{% endfor %}
{% endfor %}
</table>
</div>
</div>
</div>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -14,6 +14,11 @@
{% csrf_token %} {% csrf_token %}
<form id="transfers_form"> <form id="transfers_form">
<div class="transfer_general text-center">
<input type="text" name="comment" id="comment" placeholder="Commentaire"><!--
--><button type="submit" id="submit" class="btn btn-primary btn-lg">Enregistrer</button>
{{ transfer_formset.management_form }}
</div>
<table class="transfer_formset table"> <table class="transfer_formset table">
<thead> <thead>
<tr> <tr>
@ -42,12 +47,6 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<div>
<label for="comment">Commentaire:</label>
<input type="text" name="comment" id="comment">
{{ transfer_formset.management_form }}
<button type="submit" id="submit" class="btn btn-primary btn-lg">Enregistrer</button>
</div>
</form> </form>
<script type="text/javascript"> <script type="text/javascript">
@ -105,7 +104,7 @@ $(document).ready(function () {
}, },
}) })
.done(function(data) { .done(function(data) {
window.location.replace("{% url 'kfet.transfers' %}"); window.location.href = "{% url 'kfet.transfers' %}";
}) })
.fail(function($xhr) { .fail(function($xhr) {
var data = $xhr.responseJSON; var data = $xhr.responseJSON;

View file

@ -155,9 +155,9 @@ urlpatterns = [
# Transfers urls # Transfers urls
# ----- # -----
url(r'^transfers/$', views.home, url(r'^transfers/$', views.transfers,
name = 'kfet.transfers'), name = 'kfet.transfers'),
url(r'^transfers/new$', views.transfer_create, url(r'^transfers/new$', views.transfers_create,
name = 'kfet.transfers.create'), name = 'kfet.transfers.create'),
url(r'^transfers/perform$', views.perform_transfers, url(r'^transfers/perform$', views.perform_transfers,
name = 'kfet.transfers.perform'), name = 'kfet.transfers.perform'),

View file

@ -1128,11 +1128,22 @@ class SettingsUpdate(SuccessMessageMixin, UpdateView):
# Transfer views # Transfer views
# ----- # -----
def transfer_create(request): @permission_required('kfet.is_team')
def transfers(request):
transfergroups = (TransferGroup.objects
.prefetch_related('transfers')
.order_by('-at'))
return render(request, 'kfet/transfers.html', {
'transfergroups': transfergroups,
})
@permission_required('kfet.is_team')
def transfers_create(request):
transfer_formset = TransferFormSet(queryset=Transfer.objects.none()) transfer_formset = TransferFormSet(queryset=Transfer.objects.none())
return render(request, 'kfet/transfers_create.html', return render(request, 'kfet/transfers_create.html',
{ 'transfer_formset': transfer_formset }) { 'transfer_formset': transfer_formset })
@permission_required('kfet.is_team')
def perform_transfers(request): def perform_transfers(request):
data = { 'errors': {}, 'transfers': [], 'transfergroup': 0 } data = { 'errors': {}, 'transfers': [], 'transfergroup': 0 }
@ -1168,6 +1179,14 @@ def perform_transfers(request):
data['errors']['negative'] = True data['errors']['negative'] = True
return JsonResponse(data, status=403) return JsonResponse(data, status=403)
# Creating transfer group
transfergroup = TransferGroup()
if required_perms:
transfergroup.valid_by = request.user.profile.account_kfet
comment = request.POST.get('comment', '')
transfergroup.comment = comment.strip()
with transaction.atomic(): with transaction.atomic():
# Updating balances accounts # Updating balances accounts
for account in to_accounts_balances: for account in to_accounts_balances:
@ -1187,10 +1206,7 @@ def perform_transfers(request):
and not account.negative.balance_offset): and not account.negative.balance_offset):
account.negative.delete() account.negative.delete()
# Creating transfer group # Saving transfer group
transfergroup = TransferGroup()
if required_perms:
transfergroup.valid_by = request.user.profile.account_kfet
transfergroup.save() transfergroup.save()
data['transfergroup'] = transfergroup.pk data['transfergroup'] = transfergroup.pk