mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-24 20:33:11 +00:00
Rename fields in cotisations.Vente
This commit is contained in:
parent
26a5c6cfb3
commit
4906fa8842
3 changed files with 51 additions and 24 deletions
30
cotisations/migrations/0041_auto_20190325_0837.py
Normal file
30
cotisations/migrations/0041_auto_20190325_0837.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2019-03-25 07:37
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cotisations', '0040_auto_20190325_0832'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='vente',
|
||||||
|
old_name='number',
|
||||||
|
new_name='amount',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='vente',
|
||||||
|
old_name='facture',
|
||||||
|
new_name='invoice',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='vente',
|
||||||
|
old_name='prix',
|
||||||
|
new_name='price',
|
||||||
|
),
|
||||||
|
]
|
|
@ -385,14 +385,12 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
('All', _("Both of them")),
|
('All', _("Both of them")),
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO : change facture to invoice
|
invoice = models.ForeignKey(
|
||||||
facture = models.ForeignKey(
|
|
||||||
'BaseInvoice',
|
'BaseInvoice',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
verbose_name=_("invoice")
|
verbose_name=_("invoice")
|
||||||
)
|
)
|
||||||
# TODO : change number to amount for clarity
|
amount = models.IntegerField(
|
||||||
number = models.IntegerField(
|
|
||||||
verbose_name=_("amount"),
|
verbose_name=_("amount"),
|
||||||
validators=[MinValueValidator(1)],
|
validators=[MinValueValidator(1)],
|
||||||
)
|
)
|
||||||
|
@ -401,9 +399,8 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
verbose_name=_("article"),
|
verbose_name=_("article"),
|
||||||
max_length=255,
|
max_length=255,
|
||||||
)
|
)
|
||||||
# TODO : change prix to price
|
|
||||||
# TODO : this field is not needed if you use Article ForeignKey
|
# TODO : this field is not needed if you use Article ForeignKey
|
||||||
prix = models.DecimalField(
|
price = models.DecimalField(
|
||||||
verbose_name=_("price"),
|
verbose_name=_("price"),
|
||||||
max_digits=5,
|
max_digits=5,
|
||||||
decimal_places=2,
|
decimal_places=2,
|
||||||
|
@ -436,7 +433,7 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
Returns: the total of price for this amount of items.
|
Returns: the total of price for this amount of items.
|
||||||
"""
|
"""
|
||||||
return self.prix*self.number
|
return self.price * self.amount
|
||||||
|
|
||||||
def update_cotisation(self):
|
def update_cotisation(self):
|
||||||
"""
|
"""
|
||||||
|
@ -446,7 +443,7 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
if hasattr(self, 'cotisation'):
|
if hasattr(self, 'cotisation'):
|
||||||
cotisation = self.cotisation
|
cotisation = self.cotisation
|
||||||
cotisation.date_end = cotisation.date_start + relativedelta(
|
cotisation.date_end = cotisation.date_start + relativedelta(
|
||||||
months=self.duration*self.number)
|
months=self.duration*self.amount)
|
||||||
return
|
return
|
||||||
|
|
||||||
def create_cotis(self, date_start=False):
|
def create_cotis(self, date_start=False):
|
||||||
|
@ -456,7 +453,7 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
a cotisation)
|
a cotisation)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
invoice = self.facture.facture
|
invoice = self.invoice.facture
|
||||||
except Facture.DoesNotExist:
|
except Facture.DoesNotExist:
|
||||||
return
|
return
|
||||||
if not hasattr(self, 'cotisation') and self.type_cotisation:
|
if not hasattr(self, 'cotisation') and self.type_cotisation:
|
||||||
|
@ -483,7 +480,7 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
date_max = max(end_cotisation, date_start)
|
date_max = max(end_cotisation, date_start)
|
||||||
cotisation.date_start = date_max
|
cotisation.date_start = date_max
|
||||||
cotisation.date_end = cotisation.date_start + relativedelta(
|
cotisation.date_end = cotisation.date_start + relativedelta(
|
||||||
months=self.duration*self.number
|
months=self.duration*self.amount
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -505,13 +502,13 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
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
|
elif (not user_request.has_perm('cotisations.change_all_facture') and
|
||||||
not self.facture.user.can_edit(
|
not self.invoice.user.can_edit(
|
||||||
user_request, *args, **kwargs
|
user_request, *args, **kwargs
|
||||||
)[0]):
|
)[0]):
|
||||||
return False, _("You don't have the right to edit this user's "
|
return False, _("You don't have the right to edit this user's "
|
||||||
"purchases.")
|
"purchases.")
|
||||||
elif (not user_request.has_perm('cotisations.change_all_vente') and
|
elif (not user_request.has_perm('cotisations.change_all_vente') and
|
||||||
(self.facture.control or not self.facture.valid)):
|
(self.invoice.control or not self.invoice.valid)):
|
||||||
return False, _("You don't have the right to edit a purchase "
|
return False, _("You don't have the right to edit a purchase "
|
||||||
"already controlled or invalidated.")
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
|
@ -520,10 +517,10 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
def can_delete(self, user_request, *args, **kwargs):
|
def can_delete(self, user_request, *args, **kwargs):
|
||||||
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.invoice.user.can_edit(user_request, *args, **kwargs)[0]:
|
||||||
return False, _("You don't have the right to delete this user's "
|
return False, _("You don't have the right to delete this user's "
|
||||||
"purchases.")
|
"purchases.")
|
||||||
if self.facture.control or not self.facture.valid:
|
if self.invoice.control or not self.invoice.valid:
|
||||||
return False, _("You don't have the right to delete a purchase "
|
return False, _("You don't have the right to delete a purchase "
|
||||||
"already controlled or invalidated.")
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
|
@ -531,14 +528,14 @@ class Vente(RevMixin, AclMixin, models.Model):
|
||||||
|
|
||||||
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.invoice.user != user_request):
|
||||||
return False, _("You don't have the right to view someone "
|
return False, _("You don't have the right to view someone "
|
||||||
"else's purchase history.")
|
"else's purchase history.")
|
||||||
else:
|
else:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.name) + ' ' + str(self.facture)
|
return str(self.name) + ' ' + str(self.invoice)
|
||||||
|
|
||||||
|
|
||||||
# TODO : change vente to purchase
|
# TODO : change vente to purchase
|
||||||
|
@ -906,8 +903,8 @@ class Cotisation(RevMixin, AclMixin, models.Model):
|
||||||
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 subscription.")
|
return False, _("You don't have the right to edit a subscription.")
|
||||||
elif not user_request.has_perm('cotisations.change_all_cotisation') \
|
elif not user_request.has_perm('cotisations.change_all_cotisation') \
|
||||||
and (self.vente.facture.control or
|
and (self.vente.invoice.control or
|
||||||
not self.vente.facture.valid):
|
not self.vente.invoice.valid):
|
||||||
return False, _("You don't have the right to edit a subscription "
|
return False, _("You don't have the right to edit a subscription "
|
||||||
"already controlled or invalidated.")
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
|
@ -917,7 +914,7 @@ class Cotisation(RevMixin, AclMixin, models.Model):
|
||||||
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 "
|
return False, _("You don't have the right to delete a "
|
||||||
"subscription.")
|
"subscription.")
|
||||||
if self.vente.facture.control or not self.vente.facture.valid:
|
if self.vente.invoice.control or not self.vente.invoice.valid:
|
||||||
return False, _("You don't have the right to delete a subscription "
|
return False, _("You don't have the right to delete a subscription "
|
||||||
"already controlled or invalidated.")
|
"already controlled or invalidated.")
|
||||||
else:
|
else:
|
||||||
|
@ -925,7 +922,7 @@ class Cotisation(RevMixin, AclMixin, models.Model):
|
||||||
|
|
||||||
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.invoice.user != user_request:
|
||||||
return False, _("You don't have the right to view someone else's "
|
return False, _("You don't have the right to view someone else's "
|
||||||
"subscription history.")
|
"subscription history.")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -151,7 +151,7 @@ def new_facture(request, user, userid):
|
||||||
if price_ok:
|
if price_ok:
|
||||||
new_invoice_instance.save()
|
new_invoice_instance.save()
|
||||||
for p in purchases:
|
for p in purchases:
|
||||||
p.facture = new_invoice_instance
|
p.invoice = new_invoice_instance
|
||||||
p.save()
|
p.save()
|
||||||
|
|
||||||
return new_invoice_instance.paiement.end_payment(
|
return new_invoice_instance.paiement.end_payment(
|
||||||
|
@ -347,7 +347,7 @@ def edit_facture(request, facture, **_kwargs):
|
||||||
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,
|
||||||
fields=('name', 'number'),
|
fields=('name', 'amount'),
|
||||||
extra=0,
|
extra=0,
|
||||||
max_num=len(purchases_objects)
|
max_num=len(purchases_objects)
|
||||||
)
|
)
|
||||||
|
@ -401,7 +401,7 @@ def edit_cost_estimate(request, invoice, **kwargs):
|
||||||
purchases_objects = Vente.objects.filter(facture=invoice)
|
purchases_objects = Vente.objects.filter(facture=invoice)
|
||||||
purchase_form_set = modelformset_factory(
|
purchase_form_set = modelformset_factory(
|
||||||
Vente,
|
Vente,
|
||||||
fields=('name', 'number'),
|
fields=('name', 'amount'),
|
||||||
extra=0,
|
extra=0,
|
||||||
max_num=len(purchases_objects)
|
max_num=len(purchases_objects)
|
||||||
)
|
)
|
||||||
|
@ -450,7 +450,7 @@ def edit_custom_invoice(request, invoice, **kwargs):
|
||||||
purchases_objects = Vente.objects.filter(facture=invoice)
|
purchases_objects = Vente.objects.filter(facture=invoice)
|
||||||
purchase_form_set = modelformset_factory(
|
purchase_form_set = modelformset_factory(
|
||||||
Vente,
|
Vente,
|
||||||
fields=('name', 'number'),
|
fields=('name', 'amount'),
|
||||||
extra=0,
|
extra=0,
|
||||||
max_num=len(purchases_objects)
|
max_num=len(purchases_objects)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue