mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Pep8 compliance on cotisations
This commit is contained in:
parent
e56c80b747
commit
b25137acf4
8 changed files with 224 additions and 121 deletions
|
@ -27,6 +27,7 @@ Here are defined some functions to check acl on the application.
|
||||||
"""
|
"""
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
|
||||||
def can_view(user):
|
def can_view(user):
|
||||||
"""Check if an user can view the application.
|
"""Check if an user can view the application.
|
||||||
|
|
||||||
|
@ -38,4 +39,7 @@ def can_view(user):
|
||||||
viewing is granted and msg is a message (can be None).
|
viewing is granted and msg is a message (can be None).
|
||||||
"""
|
"""
|
||||||
can = user.has_module_perms('cotisations')
|
can = user.has_module_perms('cotisations')
|
||||||
return can, None if can else _("You don't have the rights to see this application.")
|
if can:
|
||||||
|
return can, None
|
||||||
|
else:
|
||||||
|
return can, _("You don't have the rights to see this application.")
|
||||||
|
|
|
@ -38,7 +38,7 @@ from __future__ import unicode_literals
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.forms import ModelForm, Form
|
from django.forms import ModelForm, Form
|
||||||
from django.core.validators import MinValueValidator,MaxValueValidator
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.utils.translation import ugettext_lazy as _l
|
from django.utils.translation import ugettext_lazy as _l
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ from users.models import User
|
||||||
from re2o.field_permissions import FieldPermissionFormMixin
|
from re2o.field_permissions import FieldPermissionFormMixin
|
||||||
from re2o.mixins import FormRevMixin
|
from re2o.mixins import FormRevMixin
|
||||||
|
|
||||||
|
|
||||||
class NewFactureForm(FormRevMixin, ModelForm):
|
class NewFactureForm(FormRevMixin, ModelForm):
|
||||||
"""
|
"""
|
||||||
Form used to create a new invoice by using a payment method, a bank and a
|
Form used to create a new invoice by using a payment method, a bank and a
|
||||||
|
@ -109,12 +110,16 @@ class CreditSoldeForm(NewFactureForm):
|
||||||
montant = forms.DecimalField(max_digits=5, decimal_places=2, required=True)
|
montant = forms.DecimalField(max_digits=5, decimal_places=2, required=True)
|
||||||
|
|
||||||
|
|
||||||
class SelectUserArticleForm(FormRevMixin, Form):
|
class SelectUserArticleForm(
|
||||||
|
FormRevMixin, Form):
|
||||||
"""
|
"""
|
||||||
Form used to select an article during the creation of an invoice for a member.
|
Form used to select an article during the creation of an invoice for a
|
||||||
|
member.
|
||||||
"""
|
"""
|
||||||
article = forms.ModelChoiceField(
|
article = forms.ModelChoiceField(
|
||||||
queryset=Article.objects.filter(Q(type_user='All') | Q(type_user='Adherent')),
|
queryset=Article.objects.filter(
|
||||||
|
Q(type_user='All') | Q(type_user='Adherent')
|
||||||
|
),
|
||||||
label=_l("Article"),
|
label=_l("Article"),
|
||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
|
@ -127,10 +132,13 @@ class SelectUserArticleForm(FormRevMixin, Form):
|
||||||
|
|
||||||
class SelectClubArticleForm(Form):
|
class SelectClubArticleForm(Form):
|
||||||
"""
|
"""
|
||||||
Form used to select an article during the creation of an invoice for a club.
|
Form used to select an article during the creation of an invoice for a
|
||||||
|
club.
|
||||||
"""
|
"""
|
||||||
article = forms.ModelChoiceField(
|
article = forms.ModelChoiceField(
|
||||||
queryset=Article.objects.filter(Q(type_user='All') | Q(type_user='Club')),
|
queryset=Article.objects.filter(
|
||||||
|
Q(type_user='All') | Q(type_user='Club')
|
||||||
|
),
|
||||||
label=_l("Article"),
|
label=_l("Article"),
|
||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
|
@ -140,6 +148,7 @@ class SelectClubArticleForm(Form):
|
||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO : change Facture to Invoice
|
# TODO : change Facture to Invoice
|
||||||
class NewFactureFormPdf(Form):
|
class NewFactureFormPdf(Form):
|
||||||
"""
|
"""
|
||||||
|
@ -147,9 +156,18 @@ class NewFactureFormPdf(Form):
|
||||||
"""
|
"""
|
||||||
paid = forms.BooleanField(label=_l("Paid"), required=False)
|
paid = forms.BooleanField(label=_l("Paid"), required=False)
|
||||||
# TODO : change dest field to recipient
|
# TODO : change dest field to recipient
|
||||||
dest = forms.CharField(required=True, max_length=255, label=_l("Recipient"))
|
dest = forms.CharField(
|
||||||
|
required=True,
|
||||||
|
max_length=255,
|
||||||
|
label=_l("Recipient")
|
||||||
|
)
|
||||||
# TODO : change chambre field to address
|
# TODO : change chambre field to address
|
||||||
chambre = forms.CharField(required=False, max_length=10, label=_l("Address"))
|
chambre = forms.CharField(
|
||||||
|
required=False,
|
||||||
|
max_length=10,
|
||||||
|
label=_l("Address")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO : change Facture to Invoice
|
# TODO : change Facture to Invoice
|
||||||
class EditFactureForm(FieldPermissionFormMixin, NewFactureForm):
|
class EditFactureForm(FieldPermissionFormMixin, NewFactureForm):
|
||||||
|
@ -313,7 +331,6 @@ class NewFactureSoldeForm(NewFactureForm):
|
||||||
# TODO : change paiement to payment and baque to bank
|
# TODO : change paiement to payment and baque to bank
|
||||||
fields = ['paiement', 'banque']
|
fields = ['paiement', 'banque']
|
||||||
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = super(NewFactureSoldeForm, self).clean()
|
cleaned_data = super(NewFactureSoldeForm, self).clean()
|
||||||
# TODO : change paiement to payment
|
# TODO : change paiement to payment
|
||||||
|
@ -342,7 +359,7 @@ class RechargeForm(FormRevMixin, Form):
|
||||||
value = forms.FloatField(
|
value = forms.FloatField(
|
||||||
label=_l("Amount"),
|
label=_l("Amount"),
|
||||||
min_value=0.01,
|
min_value=0.01,
|
||||||
validators = []
|
validators=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -360,7 +377,8 @@ class RechargeForm(FormRevMixin, Form):
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if value + self.user.solde > OptionalUser.get_cached_value('max_solde'):
|
if value + self.user.solde > \
|
||||||
|
OptionalUser.get_cached_value('max_solde'):
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
_("Requested amount is too high. Your balance can't exceed \
|
_("Requested amount is too high. Your balance can't exceed \
|
||||||
%(max_online_balance)s €.") % {
|
%(max_online_balance)s €.") % {
|
||||||
|
|
|
@ -105,11 +105,16 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
abstract = False
|
abstract = False
|
||||||
permissions = (
|
permissions = (
|
||||||
# TODO : change facture to invoice
|
# TODO : change facture to invoice
|
||||||
('change_facture_control', _l("Can change the \"controlled\" state")),
|
('change_facture_control',
|
||||||
# TODO : seems more likely to be call create_facture_pdf or create_invoice_pdf
|
_l("Can change the \"controlled\" state")),
|
||||||
('change_facture_pdf', _l("Can create a custom PDF invoice")),
|
# TODO : seems more likely to be call create_facture_pdf
|
||||||
('view_facture', _l("Can see an invoice's details")),
|
# or create_invoice_pdf
|
||||||
('change_all_facture', _l("Can edit all the previous invoices")),
|
('change_facture_pdf',
|
||||||
|
_l("Can create a custom PDF invoice")),
|
||||||
|
('view_facture',
|
||||||
|
_l("Can see an invoice's details")),
|
||||||
|
('change_all_facture',
|
||||||
|
_l("Can edit all the previous invoices")),
|
||||||
)
|
)
|
||||||
verbose_name = _l("Invoice")
|
verbose_name = _l("Invoice")
|
||||||
verbose_name_plural = _l("Invoices")
|
verbose_name_plural = _l("Invoices")
|
||||||
|
@ -159,11 +164,14 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.change_facture'):
|
if not user_request.has_perm('cotisations.change_facture'):
|
||||||
return False, _("You don't have the right to edit an invoice.")
|
return False, _("You don't have the right to edit an invoice.")
|
||||||
elif not user_request.has_perm('cotisations.change_all_facture') and not self.user.can_edit(user_request, *args, **kwargs)[0]:
|
elif not user_request.has_perm('cotisations.change_all_facture') and \
|
||||||
return False, _("You don't have the right to edit this user's invoices.")
|
not self.user.can_edit(user_request, *args, **kwargs)[0]:
|
||||||
elif not user_request.has_perm('cotisations.change_all_facture') and\
|
return False, _("You don't have the right to edit this user's "
|
||||||
|
"invoices.")
|
||||||
|
elif not user_request.has_perm('cotisations.change_all_facture') and \
|
||||||
(self.control or not self.valid):
|
(self.control or not self.valid):
|
||||||
return False, _("You don't have the right to edit an invoice already controlled or invalidated.")
|
return False, _("You don't have the right to edit an invoice "
|
||||||
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
@ -171,16 +179,19 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
if not user_request.has_perm('cotisations.delete_facture'):
|
if not user_request.has_perm('cotisations.delete_facture'):
|
||||||
return False, _("You don't have the right to delete an invoice.")
|
return False, _("You don't have the right to delete an invoice.")
|
||||||
if not self.user.can_edit(user_request, *args, **kwargs)[0]:
|
if not self.user.can_edit(user_request, *args, **kwargs)[0]:
|
||||||
return False, _("You don't have the right to delete this user's invoices.")
|
return False, _("You don't have the right to delete this user's "
|
||||||
|
"invoices.")
|
||||||
if self.control or not self.valid:
|
if self.control or not self.valid:
|
||||||
return False, _("You don't have the right to delete an invoice already controlled or invalidated.")
|
return False, _("You don't have the right to delete an invoice "
|
||||||
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.view_facture') and\
|
if not user_request.has_perm('cotisations.view_facture') and \
|
||||||
self.user != user_request:
|
self.user != user_request:
|
||||||
return False, _("You don't have the right to see someone else's invoices history.")
|
return False, _("You don't have the right to see someone else's "
|
||||||
|
"invoices history.")
|
||||||
elif not self.valid:
|
elif not self.valid:
|
||||||
return False, _("The invoice has been invalidated.")
|
return False, _("The invoice has been invalidated.")
|
||||||
else:
|
else:
|
||||||
|
@ -188,16 +199,22 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def can_change_control(user_request, *args, **kwargs):
|
def can_change_control(user_request, *args, **kwargs):
|
||||||
return user_request.has_perm('cotisations.change_facture_control'), _("You don't have the right to edit the \"controlled\" state.")
|
return (
|
||||||
|
user_request.has_perm('cotisations.change_facture_control'),
|
||||||
|
_("You don't have the right to edit the \"controlled\" state.")
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def can_change_pdf(user_request, *args, **kwargs):
|
def can_change_pdf(user_request, *args, **kwargs):
|
||||||
return user_request.has_perm('cotisations.change_facture_pdf'), _("You don't have the right to edit an invoice.")
|
return (
|
||||||
|
user_request.has_perm('cotisations.change_facture_pdf'),
|
||||||
|
_("You don't have the right to edit an invoice.")
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Facture, self).__init__(*args, **kwargs)
|
super(Facture, self).__init__(*args, **kwargs)
|
||||||
self.field_permissions = {
|
self.field_permissions = {
|
||||||
'control' : self.can_change_control,
|
'control': self.can_change_control,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -289,7 +306,6 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
verbose_name = _l("Purchase")
|
verbose_name = _l("Purchase")
|
||||||
verbose_name_plural = _l("Purchases")
|
verbose_name_plural = _l("Purchases")
|
||||||
|
|
||||||
|
|
||||||
# TODO : change prix_total to total_price
|
# TODO : change prix_total to total_price
|
||||||
def prix_total(self):
|
def prix_total(self):
|
||||||
"""
|
"""
|
||||||
|
@ -323,11 +339,13 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
facture__in=Facture.objects.filter(
|
facture__in=Facture.objects.filter(
|
||||||
user=self.facture.user
|
user=self.facture.user
|
||||||
).exclude(valid=False))
|
).exclude(valid=False))
|
||||||
).filter(Q(type_cotisation='All') | Q(type_cotisation=self.type_cotisation)
|
).filter(
|
||||||
|
Q(type_cotisation='All') |
|
||||||
|
Q(type_cotisation=self.type_cotisation)
|
||||||
).filter(
|
).filter(
|
||||||
date_start__lt=date_start
|
date_start__lt=date_start
|
||||||
).aggregate(Max('date_end'))['date_end__max']
|
).aggregate(Max('date_end'))['date_end__max']
|
||||||
elif self.type_cotisation=="Adhesion":
|
elif self.type_cotisation == "Adhesion":
|
||||||
end_cotisation = self.facture.user.end_adhesion()
|
end_cotisation = self.facture.user.end_adhesion()
|
||||||
else:
|
else:
|
||||||
end_cotisation = self.facture.user.end_connexion()
|
end_cotisation = self.facture.user.end_connexion()
|
||||||
|
@ -357,11 +375,15 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.change_vente'):
|
if not user_request.has_perm('cotisations.change_vente'):
|
||||||
return False, _("You don't have the right to edit the purchases.")
|
return False, _("You don't have the right to edit the purchases.")
|
||||||
elif not user_request.has_perm('cotisations.change_all_facture') and not self.facture.user.can_edit(user_request, *args, **kwargs)[0]:
|
elif not user_request.has_perm('cotisations.change_all_facture') and \
|
||||||
return False, _("You don't have the right to edit this user's purchases.")
|
not self.facture.user.can_edit(
|
||||||
elif not user_request.has_perm('cotisations.change_all_vente') and\
|
user_request, *args, **kwargs)[0]:
|
||||||
|
return False, _("You don't have the right to edit this user's "
|
||||||
|
"purchases.")
|
||||||
|
elif not user_request.has_perm('cotisations.change_all_vente') and \
|
||||||
(self.facture.control or not self.facture.valid):
|
(self.facture.control or not self.facture.valid):
|
||||||
return False, _("You don't have the right to edit a purchase already controlled or invalidated.")
|
return False, _("You don't have the right to edit a purchase "
|
||||||
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
@ -369,16 +391,19 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
if not user_request.has_perm('cotisations.delete_vente'):
|
if not user_request.has_perm('cotisations.delete_vente'):
|
||||||
return False, _("You don't have the right to delete a purchase.")
|
return False, _("You don't have the right to delete a purchase.")
|
||||||
if not self.facture.user.can_edit(user_request, *args, **kwargs)[0]:
|
if not self.facture.user.can_edit(user_request, *args, **kwargs)[0]:
|
||||||
return False, _("You don't have the right to delete this user's purchases.")
|
return False, _("You don't have the right to delete this user's "
|
||||||
|
"purchases.")
|
||||||
if self.facture.control or not self.facture.valid:
|
if self.facture.control or not self.facture.valid:
|
||||||
return False, _("You don't have the right to delete a purchase already controlled or invalidated.")
|
return False, _("You don't have the right to delete a purchase "
|
||||||
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.view_vente') and\
|
if not user_request.has_perm('cotisations.view_vente') and \
|
||||||
self.facture.user != user_request:
|
self.facture.user != user_request:
|
||||||
return False, _("You don't have the right to see someone else's purchase history.")
|
return False, _("You don't have the right to see someone "
|
||||||
|
"else's purchase history.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
@ -418,12 +443,14 @@ def vente_post_delete(sender, **kwargs):
|
||||||
|
|
||||||
class Article(RevMixin, AclMixin, models.Model):
|
class Article(RevMixin, AclMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
The definition of an article model. It represents an type of object that can be sold to the user.
|
The definition of an article model. It represents a type of object
|
||||||
|
that can be sold to the user.
|
||||||
|
|
||||||
It's represented by:
|
It's represented by:
|
||||||
* a name
|
* a name
|
||||||
* a price
|
* a price
|
||||||
* a cotisation type (indicating if this article reprensents a cotisation or not)
|
* a cotisation type (indicating if this article reprensents a
|
||||||
|
cotisation or not)
|
||||||
* a duration (if it is a cotisation)
|
* a duration (if it is a cotisation)
|
||||||
* a type of user (indicating what kind of user can buy this article)
|
* a type of user (indicating what kind of user can buy this article)
|
||||||
"""
|
"""
|
||||||
|
@ -513,8 +540,8 @@ class Banque(RevMixin, AclMixin, models.Model):
|
||||||
permissions = (
|
permissions = (
|
||||||
('view_banque', _l("Can see a bank's details")),
|
('view_banque', _l("Can see a bank's details")),
|
||||||
)
|
)
|
||||||
verbose_name=_l("Bank")
|
verbose_name = _l("Bank")
|
||||||
verbose_name_plural=_l("Banks")
|
verbose_name_plural = _l("Banks")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -622,24 +649,29 @@ class Cotisation(RevMixin, AclMixin, models.Model):
|
||||||
def can_edit(self, user_request, *args, **kwargs):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.change_cotisation'):
|
if not user_request.has_perm('cotisations.change_cotisation'):
|
||||||
return False, _("You don't have the right to edit a cotisation.")
|
return False, _("You don't have the right to edit a cotisation.")
|
||||||
elif not user_request.has_perm('cotisations.change_all_cotisation') and\
|
elif not user_request.has_perm('cotisations.change_all_cotisation') \
|
||||||
(self.vente.facture.control or not self.vente.facture.valid):
|
and (self.vente.facture.control or
|
||||||
return False, _("You don't have the right to edit a cotisation already controlled or invalidated.")
|
not self.vente.facture.valid):
|
||||||
|
return False, _("You don't have the right to edit a cotisation "
|
||||||
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
def can_delete(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.delete_cotisation'):
|
if not user_request.has_perm('cotisations.delete_cotisation'):
|
||||||
return False, _("You don't have the right to delete a cotisation.")
|
return False, _("You don't have the right to delete a "
|
||||||
|
"cotisation.")
|
||||||
if self.vente.facture.control or not self.vente.facture.valid:
|
if self.vente.facture.control or not self.vente.facture.valid:
|
||||||
return False, _("You don't have the right to delete a cotisation already controlled or invalidated.")
|
return False, _("You don't have the right to delete a cotisation "
|
||||||
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def can_view(self, user_request, *args, **kwargs):
|
def can_view(self, user_request, *args, **kwargs):
|
||||||
if not user_request.has_perm('cotisations.view_cotisation') and\
|
if not user_request.has_perm('cotisations.view_cotisation') and\
|
||||||
self.vente.facture.user != user_request:
|
self.vente.facture.user != user_request:
|
||||||
return False, _("You don't have the right to see someone else's cotisation history.")
|
return False, _("You don't have the right to see someone else's "
|
||||||
|
"cotisation history.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ from preferences.models import AssoOption
|
||||||
from .models import Facture
|
from .models import Facture
|
||||||
from .payment_utils.comnpay import Payment as ComnpayPayment
|
from .payment_utils.comnpay import Payment as ComnpayPayment
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@login_required
|
@login_required
|
||||||
def accept_payment(request, factureid):
|
def accept_payment(request, factureid):
|
||||||
|
@ -30,7 +31,10 @@ def accept_payment(request, factureid):
|
||||||
'amount': facture.prix()
|
'amount': facture.prix()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return redirect(reverse('users:profil', kwargs={'userid':request.user.id}))
|
return redirect(reverse(
|
||||||
|
'users:profil',
|
||||||
|
kwargs={'userid': request.user.id}
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -43,7 +47,11 @@ def refuse_payment(request):
|
||||||
request,
|
request,
|
||||||
_("The payment has been refused.")
|
_("The payment has been refused.")
|
||||||
)
|
)
|
||||||
return redirect(reverse('users:profil', kwargs={'userid':request.user.id}))
|
return redirect(reverse(
|
||||||
|
'users:profil',
|
||||||
|
kwargs={'userid': request.user.id}
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def ipn(request):
|
def ipn(request):
|
||||||
|
@ -105,7 +113,7 @@ def comnpay(facture, request):
|
||||||
str(AssoOption.get_cached_value('payment_pass')),
|
str(AssoOption.get_cached_value('payment_pass')),
|
||||||
'https://' + host + reverse(
|
'https://' + host + reverse(
|
||||||
'cotisations:accept_payment',
|
'cotisations:accept_payment',
|
||||||
kwargs={'factureid':facture.id}
|
kwargs={'factureid': facture.id}
|
||||||
),
|
),
|
||||||
'https://' + host + reverse('cotisations:refuse_payment'),
|
'https://' + host + reverse('cotisations:refuse_payment'),
|
||||||
'https://' + host + reverse('cotisations:ipn'),
|
'https://' + host + reverse('cotisations:ipn'),
|
||||||
|
@ -113,20 +121,20 @@ def comnpay(facture, request):
|
||||||
"D"
|
"D"
|
||||||
)
|
)
|
||||||
r = {
|
r = {
|
||||||
'action' : 'https://secure.homologation.comnpay.com',
|
'action': 'https://secure.homologation.comnpay.com',
|
||||||
'method' : 'POST',
|
'method': 'POST',
|
||||||
'content' : p.buildSecretHTML(
|
'content': p.buildSecretHTML(
|
||||||
"Rechargement du solde",
|
"Rechargement du solde",
|
||||||
facture.prix(),
|
facture.prix(),
|
||||||
idTransaction=str(facture.id)
|
idTransaction=str(facture.id)
|
||||||
),
|
),
|
||||||
'amount' : facture.prix,
|
'amount': facture.prix,
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
# The payment systems supported by re2o
|
# The payment systems supported by re2o
|
||||||
PAYMENT_SYSTEM = {
|
PAYMENT_SYSTEM = {
|
||||||
'COMNPAY' : comnpay,
|
'COMNPAY': comnpay,
|
||||||
'NONE' : None
|
'NONE': None
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import hashlib
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
|
|
||||||
class Payment():
|
class Payment():
|
||||||
|
|
||||||
vad_number = ""
|
vad_number = ""
|
||||||
|
@ -15,7 +16,8 @@ class Payment():
|
||||||
source = ""
|
source = ""
|
||||||
typeTr = "D"
|
typeTr = "D"
|
||||||
|
|
||||||
def __init__(self, vad_number = "", secret_key = "", urlRetourOK = "", urlRetourNOK = "", urlIPN = "", source="", typeTr="D"):
|
def __init__(self, vad_number="", secret_key="", urlRetourOK="",
|
||||||
|
urlRetourNOK="", urlIPN="", source="", typeTr="D"):
|
||||||
self.vad_number = vad_number
|
self.vad_number = vad_number
|
||||||
self.secret_key = secret_key
|
self.secret_key = secret_key
|
||||||
self.urlRetourOK = urlRetourOK
|
self.urlRetourOK = urlRetourOK
|
||||||
|
@ -24,36 +26,45 @@ class Payment():
|
||||||
self.source = source
|
self.source = source
|
||||||
self.typeTr = typeTr
|
self.typeTr = typeTr
|
||||||
|
|
||||||
def buildSecretHTML(self, produit="Produit", montant="0.00", idTransaction=""):
|
def buildSecretHTML(self, produit="Produit", montant="0.00",
|
||||||
|
idTransaction=""):
|
||||||
if idTransaction == "":
|
if idTransaction == "":
|
||||||
self.idTransaction = str(time.time())+self.vad_number+str(randrange(999))
|
self.idTransaction = str(time.time())
|
||||||
|
self.idTransaction += self.vad_number
|
||||||
|
self.idTransaction += str(randrange(999))
|
||||||
else:
|
else:
|
||||||
self.idTransaction = idTransaction
|
self.idTransaction = idTransaction
|
||||||
|
|
||||||
array_tpe = OrderedDict(
|
array_tpe = OrderedDict(
|
||||||
montant= str(montant),
|
montant=str(montant),
|
||||||
idTPE= self.vad_number,
|
idTPE=self.vad_number,
|
||||||
idTransaction= self.idTransaction,
|
idTransaction=self.idTransaction,
|
||||||
devise= "EUR",
|
devise="EUR",
|
||||||
lang= 'fr',
|
lang='fr',
|
||||||
nom_produit= produit,
|
nom_produit=produit,
|
||||||
source= self.source,
|
source=self.source,
|
||||||
urlRetourOK= self.urlRetourOK,
|
urlRetourOK=self.urlRetourOK,
|
||||||
urlRetourNOK= self.urlRetourNOK,
|
urlRetourNOK=self.urlRetourNOK,
|
||||||
typeTr= str(self.typeTr)
|
typeTr=str(self.typeTr)
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.urlIPN!="":
|
if self.urlIPN != "":
|
||||||
array_tpe['urlIPN'] = self.urlIPN
|
array_tpe['urlIPN'] = self.urlIPN
|
||||||
|
|
||||||
array_tpe['key'] = self.secret_key;
|
array_tpe['key'] = self.secret_key
|
||||||
strWithKey = base64.b64encode(bytes('|'.join(array_tpe.values()), 'utf-8'))
|
strWithKey = base64.b64encode(bytes(
|
||||||
|
'|'.join(array_tpe.values()),
|
||||||
|
'utf-8'
|
||||||
|
))
|
||||||
del array_tpe["key"]
|
del array_tpe["key"]
|
||||||
array_tpe['sec'] = hashlib.sha512(strWithKey).hexdigest()
|
array_tpe['sec'] = hashlib.sha512(strWithKey).hexdigest()
|
||||||
|
|
||||||
ret = ""
|
ret = ""
|
||||||
for key in array_tpe:
|
for key in array_tpe:
|
||||||
ret += '<input type="hidden" name="'+key+'" value="'+array_tpe[key]+'"/>'
|
ret += '<input type="hidden" name="{k}" value="{v}"/>'.format(
|
||||||
|
'k'=key,
|
||||||
|
'v'=array_type[key]
|
||||||
|
)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -61,8 +72,10 @@ class Payment():
|
||||||
if "sec" in values:
|
if "sec" in values:
|
||||||
sec = values['sec']
|
sec = values['sec']
|
||||||
del values["sec"]
|
del values["sec"]
|
||||||
strWithKey = hashlib.sha512(base64.b64encode(bytes('|'.join(values.values()) +"|"+secret_key, 'utf-8'))).hexdigest()
|
strWithKey = hashlib.sha512(base64.b64encode(bytes(
|
||||||
|
'|'.join(values.values()) + "|" + secret_key,
|
||||||
|
'utf-8'
|
||||||
|
))).hexdigest()
|
||||||
return strWithKey.upper() == sec.upper()
|
return strWithKey.upper() == sec.upper()
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,12 @@ def render_invoice(request, ctx={}):
|
||||||
str(ctx['DATE'].day),
|
str(ctx['DATE'].day),
|
||||||
])
|
])
|
||||||
r = render_tex(request, 'cotisations/factures.tex', ctx)
|
r = render_tex(request, 'cotisations/factures.tex', ctx)
|
||||||
r['Content-Disposition'] = ''.join(['attachment; filename="',filename,'.pdf"'])
|
r['Content-Disposition'] = 'attachment; filename="{name}.pdf"'.format(
|
||||||
|
name=filename
|
||||||
|
)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def render_tex(request, template, ctx={}):
|
def render_tex(request, template, ctx={}):
|
||||||
"""
|
"""
|
||||||
Creates a PDF from a LaTex templates using pdflatex.
|
Creates a PDF from a LaTex templates using pdflatex.
|
||||||
|
@ -71,8 +74,8 @@ def render_tex(request, template, ctx={}):
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
process = Popen(
|
process = Popen(
|
||||||
['pdflatex', '-output-directory', tempdir],
|
['pdflatex', '-output-directory', tempdir],
|
||||||
stdin = PIPE,
|
stdin=PIPE,
|
||||||
stdout = PIPE,
|
stdout=PIPE,
|
||||||
)
|
)
|
||||||
process.communicate(rendered_tpl)
|
process.communicate(rendered_tpl)
|
||||||
with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
|
with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
|
||||||
|
|
|
@ -101,11 +101,10 @@ urlpatterns = [
|
||||||
views.index_paiement,
|
views.index_paiement,
|
||||||
name='index-paiement'
|
name='index-paiement'
|
||||||
),
|
),
|
||||||
url(
|
url(r'history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
|
||||||
r'history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
|
|
||||||
re2o.views.history,
|
re2o.views.history,
|
||||||
name='history',
|
name='history',
|
||||||
kwargs={'application':'cotisations'},
|
kwargs={'application': 'cotisations'},
|
||||||
),
|
),
|
||||||
url(r'^control/$',
|
url(r'^control/$',
|
||||||
views.control,
|
views.control,
|
||||||
|
|
|
@ -77,7 +77,6 @@ from . import payment as online_payment
|
||||||
from .tex import render_invoice
|
from .tex import render_invoice
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(Facture)
|
@can_create(Facture)
|
||||||
@can_edit(User)
|
@can_edit(User)
|
||||||
|
@ -102,9 +101,13 @@ def new_facture(request, user, userid):
|
||||||
# Building the invocie form and the article formset
|
# Building the invocie form and the article formset
|
||||||
invoice_form = NewFactureForm(request.POST or None, instance=invoice)
|
invoice_form = NewFactureForm(request.POST or None, instance=invoice)
|
||||||
if request.user.is_class_club:
|
if request.user.is_class_club:
|
||||||
article_formset = formset_factory(SelectClubArticleForm)(request.POST or None)
|
article_formset = formset_factory(SelectClubArticleForm)(
|
||||||
|
request.POST or None
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
article_formset = formset_factory(SelectUserArticleForm)(request.POST or None)
|
article_formset = formset_factory(SelectUserArticleForm)(
|
||||||
|
request.POST or None
|
||||||
|
)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -118,15 +121,18 @@ def new_facture(request, user, userid):
|
||||||
# the authorized minimum (negative_balance)
|
# the authorized minimum (negative_balance)
|
||||||
if user_balance:
|
if user_balance:
|
||||||
# TODO : change Paiement to Payment
|
# TODO : change Paiement to Payment
|
||||||
if new_invoice_instance.paiement == Paiement.objects.get_or_create(
|
if new_invoice_instance.paiement == (
|
||||||
moyen='solde'
|
Paiement.objects.get_or_create(moyen='solde')[0]
|
||||||
)[0]:
|
):
|
||||||
total_price = 0
|
total_price = 0
|
||||||
for art_item in articles:
|
for art_item in articles:
|
||||||
if art_item.cleaned_data:
|
if art_item.cleaned_data:
|
||||||
total_price += art_item.cleaned_data['article']\
|
total_price += (
|
||||||
.prix*art_item.cleaned_data['quantity']
|
art_item.cleaned_data['article'].prix *
|
||||||
if float(user.solde) - float(total_price) < negative_balance:
|
art_item.cleaned_data['quantity']
|
||||||
|
)
|
||||||
|
if (float(user.solde) - float(total_price)
|
||||||
|
< negative_balance):
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
_("Your balance is too low for this operation.")
|
_("Your balance is too low for this operation.")
|
||||||
|
@ -205,9 +211,13 @@ def new_facture_pdf(request):
|
||||||
# Building the invocie form and the article formset
|
# Building the invocie form and the article formset
|
||||||
invoice_form = NewFactureFormPdf(request.POST or None)
|
invoice_form = NewFactureFormPdf(request.POST or None)
|
||||||
if request.user.is_class_club:
|
if request.user.is_class_club:
|
||||||
articles_formset = formset_factory(SelectClubArticleForm)(request.POST or None)
|
articles_formset = formset_factory(SelectClubArticleForm)(
|
||||||
|
request.POST or None
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
articles_formset = formset_factory(SelectUserArticleForm)(request.POST or None)
|
articles_formset = formset_factory(SelectUserArticleForm)(
|
||||||
|
request.POST or None
|
||||||
|
)
|
||||||
if invoice_form.is_valid() and articles_formset.is_valid():
|
if invoice_form.is_valid() and articles_formset.is_valid():
|
||||||
# Get the article list and build an list out of it
|
# Get the article list and build an list out of it
|
||||||
# contiaining (article_name, article_price, quantity, total_price)
|
# contiaining (article_name, article_price, quantity, total_price)
|
||||||
|
@ -303,7 +313,11 @@ def edit_facture(request, facture, factureid):
|
||||||
can be set as desired. This is also the view used to invalidate
|
can be set as desired. This is also the view used to invalidate
|
||||||
an invoice.
|
an invoice.
|
||||||
"""
|
"""
|
||||||
invoice_form = EditFactureForm(request.POST or None, instance=facture, user=request.user)
|
invoice_form = EditFactureForm(
|
||||||
|
request.POST or None,
|
||||||
|
instance=facture,
|
||||||
|
user=request.user
|
||||||
|
)
|
||||||
purchases_objects = Vente.objects.filter(facture=facture)
|
purchases_objects = Vente.objects.filter(facture=facture)
|
||||||
purchase_form_set = modelformset_factory(
|
purchase_form_set = modelformset_factory(
|
||||||
Vente,
|
Vente,
|
||||||
|
@ -311,7 +325,10 @@ def edit_facture(request, facture, factureid):
|
||||||
extra=0,
|
extra=0,
|
||||||
max_num=len(purchases_objects)
|
max_num=len(purchases_objects)
|
||||||
)
|
)
|
||||||
purchase_form = purchase_form_set(request.POST or None, queryset=purchases_objects)
|
purchase_form = purchase_form_set(
|
||||||
|
request.POST or None,
|
||||||
|
queryset=purchases_objects
|
||||||
|
)
|
||||||
if invoice_form.is_valid() and purchase_form.is_valid():
|
if invoice_form.is_valid() and purchase_form.is_valid():
|
||||||
if invoice_form.changed_data:
|
if invoice_form.changed_data:
|
||||||
invoice_form.save()
|
invoice_form.save()
|
||||||
|
@ -613,7 +630,8 @@ def control(request):
|
||||||
View used to control the invoices all at once.
|
View used to control the invoices all at once.
|
||||||
"""
|
"""
|
||||||
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
pagination_number = GeneralOption.get_cached_value('pagination_number')
|
||||||
invoice_list = Facture.objects.select_related('user').select_related('paiement')
|
invoice_list = (Facture.objects.select_related('user').
|
||||||
|
select_related('paiement'))
|
||||||
invoice_list = SortTable.sort(
|
invoice_list = SortTable.sort(
|
||||||
invoice_list,
|
invoice_list,
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
@ -725,9 +743,13 @@ def new_facture_solde(request, userid):
|
||||||
Q(type_user='All') | Q(type_user=request.user.class_name)
|
Q(type_user='All') | Q(type_user=request.user.class_name)
|
||||||
)
|
)
|
||||||
if request.user.is_class_club:
|
if request.user.is_class_club:
|
||||||
article_formset = formset_factory(SelectClubArticleForm)(request.POST or None)
|
article_formset = formset_factory(SelectClubArticleForm)(
|
||||||
|
request.POST or None
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
article_formset = formset_factory(SelectUserArticleForm)(request.POST or None)
|
article_formset = formset_factory(SelectUserArticleForm)(
|
||||||
|
request.POST or None
|
||||||
|
)
|
||||||
|
|
||||||
if article_formset.is_valid():
|
if article_formset.is_valid():
|
||||||
articles = article_formset
|
articles = article_formset
|
||||||
|
@ -826,7 +848,9 @@ def recharge(request):
|
||||||
refill_form = RechargeForm(request.POST or None, user=request.user)
|
refill_form = RechargeForm(request.POST or None, user=request.user)
|
||||||
if refill_form.is_valid():
|
if refill_form.is_valid():
|
||||||
invoice = Facture(user=request.user)
|
invoice = Facture(user=request.user)
|
||||||
payment, _created = Paiement.objects.get_or_create(moyen='Rechargement en ligne')
|
payment, _created = Paiement.objects.get_or_create(
|
||||||
|
moyen='Rechargement en ligne'
|
||||||
|
)
|
||||||
invoice.paiement = payment
|
invoice.paiement = payment
|
||||||
invoice.valid = False
|
invoice.valid = False
|
||||||
invoice.save()
|
invoice.save()
|
||||||
|
@ -837,7 +861,9 @@ def recharge(request):
|
||||||
number=1
|
number=1
|
||||||
)
|
)
|
||||||
purchase.save()
|
purchase.save()
|
||||||
content = online_payment.PAYMENT_SYSTEM[AssoOption.get_cached_value('payment')](invoice, request)
|
content = online_payment.PAYMENT_SYSTEM[
|
||||||
|
AssoOption.get_cached_value('payment')
|
||||||
|
](invoice, request)
|
||||||
return render(request, 'cotisations/payment.html', content)
|
return render(request, 'cotisations/payment.html', content)
|
||||||
return form({
|
return form({
|
||||||
'rechargeform': refill_form
|
'rechargeform': refill_form
|
||||||
|
|
Loading…
Reference in a new issue