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:
parent
91f5d6a92e
commit
ae7f99dd9f
2 changed files with 23 additions and 39 deletions
|
@ -37,7 +37,6 @@ of each of the method.
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.db.models import Q
|
|
||||||
from django.forms import ModelForm, Form
|
from django.forms import ModelForm, Form
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
|
||||||
|
@ -116,7 +115,7 @@ class DiscountForm(Form):
|
||||||
Form used in oder to create a discount on an invoice.
|
Form used in oder to create a discount on an invoice.
|
||||||
"""
|
"""
|
||||||
is_relative = forms.BooleanField(
|
is_relative = forms.BooleanField(
|
||||||
label=_("Discount is on percentage."),
|
label=_("Discount is in percentage."),
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
discount = forms.DecimalField(
|
discount = forms.DecimalField(
|
||||||
|
@ -173,11 +172,6 @@ class ArticleForm(FormRevMixin, ModelForm):
|
||||||
model = Article
|
model = Article
|
||||||
fields = '__all__'
|
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):
|
class DelArticleForm(FormRevMixin, Form):
|
||||||
"""
|
"""
|
||||||
|
@ -199,8 +193,7 @@ class DelArticleForm(FormRevMixin, Form):
|
||||||
self.fields['articles'].queryset = Article.objects.all()
|
self.fields['articles'].queryset = Article.objects.all()
|
||||||
|
|
||||||
|
|
||||||
# TODO : change Paiement to Payment
|
class PaymentForm(FormRevMixin, ModelForm):
|
||||||
class PaiementForm(FormRevMixin, ModelForm):
|
|
||||||
"""
|
"""
|
||||||
Form used to create a new payment method.
|
Form used to create a new payment method.
|
||||||
The 'cheque' type is used to associate a specific behaviour requiring
|
The 'cheque' type is used to associate a specific behaviour requiring
|
||||||
|
@ -213,12 +206,11 @@ class PaiementForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
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")
|
self.fields['moyen'].label = _("Payment method name")
|
||||||
|
|
||||||
|
|
||||||
# TODO : change paiement to payment
|
class DelPaymentForm(FormRevMixin, Form):
|
||||||
class DelPaiementForm(FormRevMixin, Form):
|
|
||||||
"""
|
"""
|
||||||
Form used to delete one or more payment methods.
|
Form used to delete one or more payment methods.
|
||||||
The user must choose the one to delete by checking the boxes.
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
instances = kwargs.pop('instances', None)
|
instances = kwargs.pop('instances', None)
|
||||||
super(DelPaiementForm, self).__init__(*args, **kwargs)
|
super(DelPaymentForm, self).__init__(*args, **kwargs)
|
||||||
if instances:
|
if instances:
|
||||||
self.fields['paiements'].queryset = instances
|
self.fields['paiements'].queryset = instances
|
||||||
else:
|
else:
|
||||||
self.fields['paiements'].queryset = Paiement.objects.all()
|
self.fields['paiements'].queryset = Paiement.objects.all()
|
||||||
|
|
||||||
|
|
||||||
# TODO : change banque to bank
|
class BankForm(FormRevMixin, ModelForm):
|
||||||
class BanqueForm(FormRevMixin, ModelForm):
|
|
||||||
"""
|
"""
|
||||||
Form used to create a bank.
|
Form used to create a bank.
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
# TODO : change banque to bank
|
# TODO : change banque to bank
|
||||||
model = Banque
|
model = Banque
|
||||||
fields = ['name']
|
fields = '__all__'
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
|
||||||
# TODO : change banque to bank
|
class DelBankForm(FormRevMixin, Form):
|
||||||
class DelBanqueForm(FormRevMixin, Form):
|
|
||||||
"""
|
"""
|
||||||
Form used to delete one or more banks.
|
Form used to delete one or more banks.
|
||||||
The use must choose the one to delete by checking the boxes.
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
instances = kwargs.pop('instances', None)
|
instances = kwargs.pop('instances', None)
|
||||||
super(DelBanqueForm, self).__init__(*args, **kwargs)
|
super(DelBankForm, self).__init__(*args, **kwargs)
|
||||||
if instances:
|
if instances:
|
||||||
self.fields['banques'].queryset = instances
|
self.fields['banques'].queryset = instances
|
||||||
else:
|
else:
|
||||||
self.fields['banques'].queryset = Banque.objects.all()
|
self.fields['banques'].queryset = Banque.objects.all()
|
||||||
|
|
||||||
|
|
||||||
# TODO : Better name and docstring
|
class RefillBalanceForm(FormRevMixin, Form):
|
||||||
class RechargeForm(FormRevMixin, Form):
|
|
||||||
"""
|
"""
|
||||||
Form used to refill a user's balance
|
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):
|
def __init__(self, *args, user=None, user_source=None, **kwargs):
|
||||||
self.user = user
|
self.user = user
|
||||||
super(RechargeForm, self).__init__(*args, **kwargs)
|
super(RefillBalanceForm, 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(
|
self.fields['payment'].queryset = Paiement.find_allowed_payments(
|
||||||
|
|
|
@ -75,12 +75,12 @@ from .forms import (
|
||||||
FactureForm,
|
FactureForm,
|
||||||
ArticleForm,
|
ArticleForm,
|
||||||
DelArticleForm,
|
DelArticleForm,
|
||||||
PaiementForm,
|
PaymentForm,
|
||||||
DelPaiementForm,
|
DelPaymentForm,
|
||||||
BanqueForm,
|
BankForm,
|
||||||
DelBanqueForm,
|
DelBankForm,
|
||||||
SelectArticleForm,
|
SelectArticleForm,
|
||||||
RechargeForm,
|
RefillBalanceForm,
|
||||||
CustomInvoiceForm,
|
CustomInvoiceForm,
|
||||||
DiscountForm,
|
DiscountForm,
|
||||||
CostEstimateForm,
|
CostEstimateForm,
|
||||||
|
@ -673,7 +673,7 @@ def add_paiement(request):
|
||||||
"""
|
"""
|
||||||
View used to add a payment method.
|
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_method = payment_method_factory(
|
||||||
payment.instance,
|
payment.instance,
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
|
@ -702,7 +702,7 @@ def edit_paiement(request, paiement_instance, **_kwargs):
|
||||||
"""
|
"""
|
||||||
View used to edit a payment method.
|
View used to edit a payment method.
|
||||||
"""
|
"""
|
||||||
payment = PaiementForm(
|
payment = PaymentForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
instance=paiement_instance,
|
instance=paiement_instance,
|
||||||
prefix="payment"
|
prefix="payment"
|
||||||
|
@ -738,7 +738,7 @@ def del_paiement(request, instances):
|
||||||
"""
|
"""
|
||||||
View used to delete a set of payment methods.
|
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():
|
if payment.is_valid():
|
||||||
payment_dels = payment.cleaned_data['paiements']
|
payment_dels = payment.cleaned_data['paiements']
|
||||||
for payment_del in payment_dels:
|
for payment_del in payment_dels:
|
||||||
|
@ -773,7 +773,7 @@ def add_banque(request):
|
||||||
"""
|
"""
|
||||||
View used to add a bank.
|
View used to add a bank.
|
||||||
"""
|
"""
|
||||||
bank = BanqueForm(request.POST or None)
|
bank = BankForm(request.POST or None)
|
||||||
if bank.is_valid():
|
if bank.is_valid():
|
||||||
bank.save()
|
bank.save()
|
||||||
messages.success(
|
messages.success(
|
||||||
|
@ -795,7 +795,7 @@ def edit_banque(request, banque_instance, **_kwargs):
|
||||||
"""
|
"""
|
||||||
View used to edit a bank.
|
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.is_valid():
|
||||||
if bank.changed_data:
|
if bank.changed_data:
|
||||||
bank.save()
|
bank.save()
|
||||||
|
@ -818,7 +818,7 @@ def del_banque(request, instances):
|
||||||
"""
|
"""
|
||||||
View used to delete a set of banks.
|
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():
|
if bank.is_valid():
|
||||||
bank_dels = bank.cleaned_data['banques']
|
bank_dels = bank.cleaned_data['banques']
|
||||||
for bank_del in bank_dels:
|
for bank_del in bank_dels:
|
||||||
|
@ -1021,7 +1021,7 @@ def credit_solde(request, user, **_kwargs):
|
||||||
kwargs={'userid': user.id}
|
kwargs={'userid': user.id}
|
||||||
))
|
))
|
||||||
|
|
||||||
refill_form = RechargeForm(
|
refill_form = RefillBalanceForm(
|
||||||
request.POST or None, user=user, user_source=request.user)
|
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']
|
||||||
|
|
Loading…
Reference in a new issue