8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 20:33:11 +00:00

Refractor cotisations forms

This commit is contained in:
Alexandre Iooss 2019-03-21 16:54:13 +01:00
parent 91f5d6a92e
commit ae7f99dd9f
No known key found for this signature in database
GPG key ID: 6C79278F3FCDCC02
2 changed files with 23 additions and 39 deletions

View file

@ -37,7 +37,6 @@ of each of the method.
from __future__ import unicode_literals
from django import forms
from django.db.models import Q
from django.forms import ModelForm, Form
from django.core.validators import MinValueValidator
@ -116,7 +115,7 @@ class DiscountForm(Form):
Form used in oder to create a discount on an invoice.
"""
is_relative = forms.BooleanField(
label=_("Discount is on percentage."),
label=_("Discount is in percentage."),
required=False,
)
discount = forms.DecimalField(
@ -173,11 +172,6 @@ class ArticleForm(FormRevMixin, ModelForm):
model = Article
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ArticleForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['name'].label = _("Article name")
class DelArticleForm(FormRevMixin, Form):
"""
@ -199,8 +193,7 @@ class DelArticleForm(FormRevMixin, Form):
self.fields['articles'].queryset = Article.objects.all()
# TODO : change Paiement to Payment
class PaiementForm(FormRevMixin, ModelForm):
class PaymentForm(FormRevMixin, ModelForm):
"""
Form used to create a new payment method.
The 'cheque' type is used to associate a specific behaviour requiring
@ -213,12 +206,11 @@ class PaiementForm(FormRevMixin, ModelForm):
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(PaiementForm, self).__init__(*args, prefix=prefix, **kwargs)
super(PaymentForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['moyen'].label = _("Payment method name")
# TODO : change paiement to payment
class DelPaiementForm(FormRevMixin, Form):
class DelPaymentForm(FormRevMixin, Form):
"""
Form used to delete one or more payment methods.
The user must choose the one to delete by checking the boxes.
@ -232,31 +224,24 @@ class DelPaiementForm(FormRevMixin, Form):
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelPaiementForm, self).__init__(*args, **kwargs)
super(DelPaymentForm, self).__init__(*args, **kwargs)
if instances:
self.fields['paiements'].queryset = instances
else:
self.fields['paiements'].queryset = Paiement.objects.all()
# TODO : change banque to bank
class BanqueForm(FormRevMixin, ModelForm):
class BankForm(FormRevMixin, ModelForm):
"""
Form used to create a bank.
"""
class Meta:
# TODO : change banque to bank
model = Banque
fields = ['name']
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(BanqueForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['name'].label = _("Bank name")
fields = '__all__'
# TODO : change banque to bank
class DelBanqueForm(FormRevMixin, Form):
class DelBankForm(FormRevMixin, Form):
"""
Form used to delete one or more banks.
The use must choose the one to delete by checking the boxes.
@ -270,15 +255,14 @@ class DelBanqueForm(FormRevMixin, Form):
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelBanqueForm, self).__init__(*args, **kwargs)
super(DelBankForm, self).__init__(*args, **kwargs)
if instances:
self.fields['banques'].queryset = instances
else:
self.fields['banques'].queryset = Banque.objects.all()
# TODO : Better name and docstring
class RechargeForm(FormRevMixin, Form):
class RefillBalanceForm(FormRevMixin, Form):
"""
Form used to refill a user's balance
"""
@ -294,7 +278,7 @@ class RechargeForm(FormRevMixin, Form):
def __init__(self, *args, user=None, user_source=None, **kwargs):
self.user = user
super(RechargeForm, self).__init__(*args, **kwargs)
super(RefillBalanceForm, self).__init__(*args, **kwargs)
self.fields['payment'].empty_label = \
_("Select a payment method")
self.fields['payment'].queryset = Paiement.find_allowed_payments(

View file

@ -75,12 +75,12 @@ from .forms import (
FactureForm,
ArticleForm,
DelArticleForm,
PaiementForm,
DelPaiementForm,
BanqueForm,
DelBanqueForm,
PaymentForm,
DelPaymentForm,
BankForm,
DelBankForm,
SelectArticleForm,
RechargeForm,
RefillBalanceForm,
CustomInvoiceForm,
DiscountForm,
CostEstimateForm,
@ -673,7 +673,7 @@ def add_paiement(request):
"""
View used to add a payment method.
"""
payment = PaiementForm(request.POST or None, prefix='payment')
payment = PaymentForm(request.POST or None, prefix='payment')
payment_method = payment_method_factory(
payment.instance,
request.POST or None,
@ -702,7 +702,7 @@ def edit_paiement(request, paiement_instance, **_kwargs):
"""
View used to edit a payment method.
"""
payment = PaiementForm(
payment = PaymentForm(
request.POST or None,
instance=paiement_instance,
prefix="payment"
@ -738,7 +738,7 @@ def del_paiement(request, instances):
"""
View used to delete a set of payment methods.
"""
payment = DelPaiementForm(request.POST or None, instances=instances)
payment = DelPaymentForm(request.POST or None, instances=instances)
if payment.is_valid():
payment_dels = payment.cleaned_data['paiements']
for payment_del in payment_dels:
@ -773,7 +773,7 @@ def add_banque(request):
"""
View used to add a bank.
"""
bank = BanqueForm(request.POST or None)
bank = BankForm(request.POST or None)
if bank.is_valid():
bank.save()
messages.success(
@ -795,7 +795,7 @@ def edit_banque(request, banque_instance, **_kwargs):
"""
View used to edit a bank.
"""
bank = BanqueForm(request.POST or None, instance=banque_instance)
bank = BankForm(request.POST or None, instance=banque_instance)
if bank.is_valid():
if bank.changed_data:
bank.save()
@ -818,7 +818,7 @@ def del_banque(request, instances):
"""
View used to delete a set of banks.
"""
bank = DelBanqueForm(request.POST or None, instances=instances)
bank = DelBankForm(request.POST or None, instances=instances)
if bank.is_valid():
bank_dels = bank.cleaned_data['banques']
for bank_del in bank_dels:
@ -1021,7 +1021,7 @@ def credit_solde(request, user, **_kwargs):
kwargs={'userid': user.id}
))
refill_form = RechargeForm(
refill_form = RefillBalanceForm(
request.POST or None, user=user, user_source=request.user)
if refill_form.is_valid():
price = refill_form.cleaned_data['value']