Skip to content

Commit

Permalink
Merge pull request #74 from borgia-app/feature/Refactor_SharedEvent
Browse files Browse the repository at this point in the history
Feature/Refactor Shared events
  • Loading branch information
Mael Lacour authored Jun 11, 2018
2 parents 73e8a4e + 9b8ad29 commit 0519964
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 104 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ Borgia est un outil qui permet de construire, gérer et organiser votre vie étu
- `u.save()`
- Créer ensuite les différents magasins avec l'interface graphique. Attention, ne pas oublier d'ajouter des utiliseurs aux groupes `chefs` et `associés` de chaque magasin après la création.

### Tester ses modifications

Pour lancer les tests unitaires : `python manage.py test`

Pour lancer les tests unitaires uniquement sur un module :
`python manage.py test nom_du_module`

## Se documenter

La documentation de Borgia est en cours de construction. Des ressources sont disponibles [ici](https://github.com/borgia-app/Borgia-docs).
Expand Down
8 changes: 6 additions & 2 deletions finances/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,12 @@ class SharedEventCreateForm(forms.Form):
)


class SharedEventDeleteForm(forms.Form):
checkbox = forms.BooleanField(label="Je suis conscient que la suppression entraîne le non-paiement, et la perte des informations.")


class SharedEventFinishForm(forms.Form):
type_payment = forms.ChoiceField(label='Type', choices=(('pay_by_total', 'Payer par division du total'),
type_payment = forms.ChoiceField(label='Type de débucquage', choices=(('pay_by_total', 'Payer par division du total'),
('pay_by_ponderation', 'Payer par prix par pondération'),
('no_payment', 'Ne pas faire payer')))
total_price = forms.DecimalField(label='Prix total', decimal_places=2, max_digits=9,
Expand Down Expand Up @@ -317,7 +321,7 @@ class SharedEventUpdateForm(forms.Form):


class SharedEventListUsersForm(forms.Form):
order_by = forms.ChoiceField(label='Trier par', choices=(('username', 'Username'), ('last_name', 'Nom'), ('surname', 'Bucque'), ('year', 'Promo')))
order_by = forms.ChoiceField(label='Trier par', choices=(('username', 'Username'), ('last_name', 'Nom'), ('surname', 'Bucque'), ('year', 'Année')))
state = forms.ChoiceField(label='Lister', choices=(('users', 'Tous les concernés'),
('registrants', 'Uniquement les préinscrits'),
('participants', 'Uniquement les participants')))
Expand Down
18 changes: 12 additions & 6 deletions finances/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ def pay_by_total(self, operator, recipient, total_price):
:return:
"""

self.done = True
self.save()

# Calcul du prix par weight
total_weight = self.get_total_weights_participants()
try:
Expand All @@ -603,7 +606,9 @@ def pay_by_total(self, operator, recipient, total_price):
return

for e in self.weightsuser_set.all():
e.user.debit(final_price_per_weight * e.weights_participation)
user_price = final_price_per_weight * e.weights_participation
e.user.debit(user_price)
recipient.credit(user_price)
if (e.user.balance < 0):
# If negative balance after event
# We notify
Expand All @@ -613,8 +618,6 @@ def pay_by_total(self, operator, recipient, total_price):
target_object=self
)


self.done = True
self.price = total_price
self.datetime = now()
self.remark = 'Paiement par Borgia (Prix total : ' + str(total_price) + ')'
Expand All @@ -631,10 +634,15 @@ def pay_by_ponderation(self, operator, recipient, ponderation_price):
:return:
"""

self.done = True
self.save()

for e in self.weightsuser_set.all():
weight = e.weights_participation
if weight != 0:
e.user.debit(ponderation_price * weight)
user_price = ponderation_price * weight
e.user.debit(user_price)
recipient.credit(user_price)
if (e.user.balance < 0):
# If negative balance after event
# We notify
Expand All @@ -644,8 +652,6 @@ def pay_by_ponderation(self, operator, recipient, ponderation_price):
target_object=self
)


self.done = True
self.payment_by_ponderation = True
self.price = ponderation_price
self.datetime = now()
Expand Down
8 changes: 6 additions & 2 deletions finances/templates/finances/sharedevent_delete.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{% extends 'base_sober.html' %}
{% load bootstrap %}

{% block content %}
<div class="panel panel-danger">
<div class="panel-heading">
Suppression d'un événement
Suppression d'un événement :
</div>
<div class="panel-body">
<form action="" method="post">
{% csrf_token %}
<label>Supprimer l'événement {{ object }} ?</label>
<h3>Supprimer l'événement ""{{ se.description }}"" ?</h3>
<br>
{{ form|bootstrap }}
<br>
<button class="btn btn-danger" type="submit">Valider</button>
</form>
</div>
Expand Down
10 changes: 8 additions & 2 deletions finances/templates/finances/sharedevent_finish.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
Terminer l'évènement {{ se }}
</div>
<div class="panel-body">
<form action="" method="post">
<p>
<strong>Rappel :</strong><br>
- Prix total: {% if total_price %}{{ total_price }}{% else %}Non renseigné{% endif %}<br>
- Nombre de part: {{ total_weights_participants }}<br>
{% if ponderation_price %}- Prix de revient par part: {{ ponderation_price }}<br>{% endif %}
<br>
<form id="finish_form" action="" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<button class="btn btn-success" type="submit">Terminer</button>
<button class="btn btn-success" type="submit" id="finish_submit">Terminer</button>
</form>
<a href="{% url 'url_sharedevent_update' pk=se.pk group_name=group.name %}" class="btn btn-info pull-right">Retour a la gestion générale de l'évènement</a>

Expand Down
4 changes: 2 additions & 2 deletions finances/templates/finances/sharedevent_manage_users.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<thead>
<tr>
<th>Username</th>
<th>Prénom Nom</th>
<th>Nom Prénom</th>
<th>Bucque</th>
{% if state == 'users' %}
<th>Préinscrit</th>
Expand All @@ -85,7 +85,7 @@
{% for u in list_weights %}
<tr>
<td>{{ u.0.username }}</td>
<td>{{ u.0.first_name }} {{ u.0.last_name }}</td>
<td>{{ u.0.last_name }} {{ u.0.first_name }}</td>
<td>{{ u.0.surname }}</td>

{% if done %}
Expand Down
Loading

0 comments on commit 0519964

Please sign in to comment.