|
|
@ -54,7 +54,7 @@ class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model): |
|
|
""" |
|
|
""" |
|
|
The model for an invoice. It reprensents the fact that a user paid for |
|
|
The model for an invoice. It reprensents the fact that a user paid for |
|
|
something (it can be multiple article paid at once). |
|
|
something (it can be multiple article paid at once). |
|
|
|
|
|
|
|
|
An invoice is linked to : |
|
|
An invoice is linked to : |
|
|
* one or more purchases (one for each article sold that time) |
|
|
* one or more purchases (one for each article sold that time) |
|
|
* a user (the one who bought those articles) |
|
|
* a user (the one who bought those articles) |
|
|
@ -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 " |
|
|
(self.control or not self.valid): |
|
|
"invoices.") |
|
|
return False, _("You don't have the right to edit an invoice already controlled or invalidated.") |
|
|
elif not user_request.has_perm('cotisations.change_all_facture') and \ |
|
|
|
|
|
(self.control or not self.valid): |
|
|
|
|
|
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): |
|
|
@ -228,7 +245,7 @@ class Vente(RevMixin, AclMixin, models.Model): |
|
|
""" |
|
|
""" |
|
|
The model defining a purchase. It consist of one type of article being |
|
|
The model defining a purchase. It consist of one type of article being |
|
|
sold. In particular there may be multiple purchases in a single invoice. |
|
|
sold. In particular there may be multiple purchases in a single invoice. |
|
|
|
|
|
|
|
|
It's reprensentated by: |
|
|
It's reprensentated by: |
|
|
* an amount (the number of items sold) |
|
|
* an amount (the number of items sold) |
|
|
* an invoice (whose the purchase is part of) |
|
|
* an invoice (whose the purchase is part of) |
|
|
@ -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]: |
|
|
(self.facture.control or not self.facture.valid): |
|
|
return False, _("You don't have the right to edit this user's " |
|
|
return False, _("You don't have the right to edit a purchase already controlled or invalidated.") |
|
|
"purchases.") |
|
|
|
|
|
elif not user_request.has_perm('cotisations.change_all_vente') and \ |
|
|
|
|
|
(self.facture.control or not self.facture.valid): |
|
|
|
|
|
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 |
|
|
@ -530,7 +557,7 @@ class Paiement(RevMixin, AclMixin, models.Model): |
|
|
* a type (used for the type 'cheque' which implies the use of a bank |
|
|
* a type (used for the type 'cheque' which implies the use of a bank |
|
|
and an account number in related models) |
|
|
and an account number in related models) |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
PAYMENT_TYPES = ( |
|
|
PAYMENT_TYPES = ( |
|
|
(0, _l("Standard")), |
|
|
(0, _l("Standard")), |
|
|
(1, _l("Cheque")), |
|
|
(1, _l("Cheque")), |
|
|
@ -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 |
|
|
|
|
|
|
|
|
|