Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

...
 
Commits (16)
...@@ -84,15 +84,13 @@ class FactureForm(FieldPermissionFormMixin, FormRevMixin, ModelForm): ...@@ -84,15 +84,13 @@ class FactureForm(FieldPermissionFormMixin, FormRevMixin, ModelForm):
return cleaned_data return cleaned_data
class SelectUserArticleForm(FormRevMixin, Form): class SelectArticleForm(FormRevMixin, Form):
""" """
Form used to select an article during the creation of an invoice for a Form used to select an article during the creation of an invoice for a
member. member.
""" """
article = forms.ModelChoiceField( article = forms.ModelChoiceField(
queryset=Article.objects.filter( queryset=Article.objects.none(),
Q(type_user='All') | Q(type_user='Adherent')
),
label=_("Article"), label=_("Article"),
required=True required=True
) )
...@@ -104,31 +102,9 @@ class SelectUserArticleForm(FormRevMixin, Form): ...@@ -104,31 +102,9 @@ class SelectUserArticleForm(FormRevMixin, Form):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
user = kwargs.pop('user') user = kwargs.pop('user')
super(SelectUserArticleForm, self).__init__(*args, **kwargs) target_user = kwargs.pop('target_user')
self.fields['article'].queryset = Article.find_allowed_articles(user) super(SelectArticleForm, self).__init__(*args, **kwargs)
self.fields['article'].queryset = Article.find_allowed_articles(user, target_user)
class SelectClubArticleForm(Form):
"""
Form used to select an article during the creation of an invoice for a
club.
"""
article = forms.ModelChoiceField(
queryset=Article.objects.filter(
Q(type_user='All') | Q(type_user='Club')
),
label=_("Article"),
required=True
)
quantity = forms.IntegerField(
label=_("Quantity"),
validators=[MinValueValidator(1)],
required=True
)
def __init__(self, user, *args, **kwargs):
super(SelectClubArticleForm, self).__init__(*args, **kwargs)
self.fields['article'].queryset = Article.find_allowed_articles(user)
class CustomInvoiceForm(FormRevMixin, ModelForm): class CustomInvoiceForm(FormRevMixin, ModelForm):
...@@ -267,12 +243,12 @@ class RechargeForm(FormRevMixin, Form): ...@@ -267,12 +243,12 @@ class RechargeForm(FormRevMixin, Form):
label=_("Payment method") label=_("Payment method")
) )
def __init__(self, *args, user=None, **kwargs): def __init__(self, *args, user=None, user_source=None, **kwargs):
self.user = user self.user = user
super(RechargeForm, self).__init__(*args, **kwargs) super(RechargeForm, self).__init__(*args, **kwargs)
self.fields['payment'].empty_label = \ self.fields['payment'].empty_label = \
_("Select a payment method") _("Select a payment method")
self.fields['payment'].queryset = Paiement.find_allowed_payments(user).exclude(is_balance=True) self.fields['payment'].queryset = Paiement.find_allowed_payments(user_source).exclude(is_balance=True)
def clean(self): def clean(self):
""" """
......
...@@ -222,7 +222,7 @@ class Facture(BaseInvoice): ...@@ -222,7 +222,7 @@ class Facture(BaseInvoice):
return True, None return True, None
if len(Paiement.find_allowed_payments(user_request)) <= 0: if len(Paiement.find_allowed_payments(user_request)) <= 0:
return False, _("There are no payment method which you can use.") return False, _("There are no payment method which you can use.")
if len(Article.find_allowed_articles(user_request)) <= 0: if len(Article.find_allowed_articles(user_request, user_request)) <= 0:
return False, _("There are no article that you can buy.") return False, _("There are no article that you can buy.")
return True, None return True, None
...@@ -595,15 +595,24 @@ class Article(RevMixin, AclMixin, models.Model): ...@@ -595,15 +595,24 @@ class Article(RevMixin, AclMixin, models.Model):
) )
@classmethod @classmethod
def find_allowed_articles(cls, user): def find_allowed_articles(cls, user, target_user):
"""Finds every allowed articles for an user. """Finds every allowed articles for an user, on a target user.
Args: Args:
user: The user requesting articles. user: The user requesting articles.
target_user: The user to sell articles
""" """
if target_user.is_class_club:
objects_pool = cls.objects.filter(
Q(type_user='All') | Q(type_user='Club')
)
else:
objects_pool = cls.objects.filter(
Q(type_user='All') | Q(type_user='Adherent')
)
if user.has_perm('cotisations.buy_every_article'): if user.has_perm('cotisations.buy_every_article'):
return cls.objects.all() return objects_pool
return cls.objects.filter(available_for_everyone=True) return objects_pool.filter(available_for_everyone=True)
class Banque(RevMixin, AclMixin, models.Model): class Banque(RevMixin, AclMixin, models.Model):
......
...@@ -73,7 +73,7 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -73,7 +73,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% can_delete facture %} {% can_delete facture %}
{% include 'buttons/suppr.html' with href='cotisations:del-facture' id=facture.id %} {% include 'buttons/suppr.html' with href='cotisations:del-facture' id=facture.id %}
{% acl_end %} {% acl_end %}
{% history_button facture text=True html_class=False %} {% history_button facture %}
</td> </td>
<td> <td>
{% if facture.valid %} {% if facture.valid %}
......
#-*- coding: utf-8 -*- # coding: utf-8
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il # Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en # se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics. # quelques clics.
......
...@@ -75,8 +75,7 @@ from .forms import ( ...@@ -75,8 +75,7 @@ from .forms import (
DelPaiementForm, DelPaiementForm,
BanqueForm, BanqueForm,
DelBanqueForm, DelBanqueForm,
SelectUserArticleForm, SelectArticleForm,
SelectClubArticleForm,
RechargeForm, RechargeForm,
CustomInvoiceForm CustomInvoiceForm
) )
...@@ -110,16 +109,10 @@ def new_facture(request, user, userid): ...@@ -110,16 +109,10 @@ def new_facture(request, user, userid):
creation=True creation=True
) )
if request.user.is_class_club: article_formset = formset_factory(SelectArticleForm)(
article_formset = formset_factory(SelectClubArticleForm)( request.POST or None,
request.POST or None, form_kwargs={'user': request.user, 'target_user': user}
form_kwargs={'user': request.user} )
)
else:
article_formset = formset_factory(SelectUserArticleForm)(
request.POST or None,
form_kwargs={'user': request.user}
)
if invoice_form.is_valid() and article_formset.is_valid(): if invoice_form.is_valid() and article_formset.is_valid():
new_invoice_instance = invoice_form.save(commit=False) new_invoice_instance = invoice_form.save(commit=False)
...@@ -199,16 +192,12 @@ def new_custom_invoice(request): ...@@ -199,16 +192,12 @@ def new_custom_invoice(request):
) )
# Building the invocie form and the article formset # Building the invocie form and the article formset
invoice_form = CustomInvoiceForm(request.POST or None) invoice_form = CustomInvoiceForm(request.POST or None)
if request.user.is_class_club:
articles_formset = formset_factory(SelectClubArticleForm)( article_formset = formset_factory(SelectArticleForm)(
request.POST or None, request.POST or None,
form_kwargs={'user': request.user} form_kwargs={'user': request.user, 'target_user': user}
) )
else:
articles_formset = formset_factory(SelectUserArticleForm)(
request.POST or None,
form_kwargs={'user': request.user}
)
if invoice_form.is_valid() and articles_formset.is_valid(): if invoice_form.is_valid() and articles_formset.is_valid():
new_invoice_instance = invoice_form.save() new_invoice_instance = invoice_form.save()
for art_item in articles_formset: for art_item in articles_formset:
...@@ -838,7 +827,7 @@ def credit_solde(request, user, **_kwargs): ...@@ -838,7 +827,7 @@ def credit_solde(request, user, **_kwargs):
kwargs={'userid': user.id} kwargs={'userid': user.id}
)) ))
refill_form = RechargeForm(request.POST or None, user=request.user) refill_form = RechargeForm(request.POST or None, user=user, user_source=request.user)
if refill_form.is_valid(): if refill_form.is_valid():
price = refill_form.cleaned_data['value'] price = refill_form.cleaned_data['value']
invoice = Facture(user=user) invoice = Facture(user=user)
...@@ -865,7 +854,7 @@ def credit_solde(request, user, **_kwargs): ...@@ -865,7 +854,7 @@ def credit_solde(request, user, **_kwargs):
p = get_object_or_404(Paiement, is_balance=True) p = get_object_or_404(Paiement, is_balance=True)
return form({ return form({
'factureform': refill_form, 'factureform': refill_form,
'balance': request.user.solde, 'balance': user.solde,
'title': _("Refill your balance"), 'title': _("Refill your balance"),
'action_name': _("Pay"), 'action_name': _("Pay"),
'max_balance': p.payment_method.maximum_balance, 'max_balance': p.payment_method.maximum_balance,
......
...@@ -52,7 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -52,7 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td colspan="4"> <td colspan="4">
{% trans "No name" as tr_no_name %} {% trans "No name" as tr_no_name %}
{% trans "View the profile" as tr_view_the_profile %} {% trans "View the profile" as tr_view_the_profile %}
<b>{{ machine.name|default:'<i>tr_no_name</i>' }}</b> <i class="fa-angle-right"></i> <b>{{ machine.name|default:tr_no_name }}</b> <i class="fa-angle-right"></i>
<a href="{% url 'users:profil' userid=machine.user.id %}" title=tr_view_the_profile> <a href="{% url 'users:profil' userid=machine.user.id %}" title=tr_view_the_profile>
<i class="fa fa-user"></i> {{ machine.user }} <i class="fa fa-user"></i> {{ machine.user }}
</a> </a>
......
...@@ -153,7 +153,7 @@ def generate_ipv4_choices(form_obj): ...@@ -153,7 +153,7 @@ def generate_ipv4_choices(form_obj):
""" """
f_ipv4 = form_obj.fields['ipv4'] f_ipv4 = form_obj.fields['ipv4']
used_mtype_id = [] used_mtype_id = []
choices = '{"":[{key:"",value:'+_("Select a machine type first.},") choices = '{"":[{key:"",value:"'+_("Select a machine type first.") + '"}'
mtype_id = -1 mtype_id = -1
for ip in (f_ipv4.queryset for ip in (f_ipv4.queryset
......
...@@ -168,9 +168,6 @@ class EditAssoOptionForm(ModelForm): ...@@ -168,9 +168,6 @@ class EditAssoOptionForm(ModelForm):
self.fields['pseudo'].label = _("Usual name") self.fields['pseudo'].label = _("Usual name")
self.fields['utilisateur_asso'].label = _("Account used for editing" self.fields['utilisateur_asso'].label = _("Account used for editing"
" from /admin") " from /admin")
self.fields['payment'].label = _("Payment")
self.fields['payment_id'].label = _("Payment ID")
self.fields['payment_pass'].label = _("Payment password")
self.fields['description'].label = _("Description") self.fields['description'].label = _("Description")
......
...@@ -52,7 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -52,7 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% elif not users.has_access %} {% elif not users.has_access %}
<div class="panel panel-danger"> <div class="panel panel-danger">
<div class="panel-heading dashboard">{% trans "No connection" %}</div> <div class="panel-heading dashboard">{% trans "No connection" %}</div>
<div class="panel-body dashboard"> <div class="panel-body dashboard">
{% can_create Facture %} {% can_create Facture %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:new-facture' users.id %}"> <a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:new-facture' users.id %}">
<i class="fas fa-sign-in-alt"></i> {% trans "Pay for a connection" %} <i class="fas fa-sign-in-alt"></i> {% trans "Pay for a connection" %}
......