mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
Make use of mandates everywhere.
This commit is contained in:
parent
75bb3658ac
commit
6dd4e776c1
4 changed files with 30 additions and 7 deletions
|
@ -25,7 +25,9 @@ from django.template.loader import get_template
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
|
|
||||||
from .tex import create_pdf
|
from .tex import create_pdf
|
||||||
from preferences.models import AssoOption, GeneralOption, CotisationsOption
|
from preferences.models import (
|
||||||
|
AssoOption, GeneralOption, CotisationsOption, Mandate
|
||||||
|
)
|
||||||
from re2o.settings import LOGO_PATH
|
from re2o.settings import LOGO_PATH
|
||||||
from re2o import settings
|
from re2o import settings
|
||||||
|
|
||||||
|
@ -97,9 +99,10 @@ def send_mail_invoice(invoice):
|
||||||
|
|
||||||
def send_mail_voucher(invoice):
|
def send_mail_voucher(invoice):
|
||||||
"""Creates a voucher from an invoice and sends it by email to the client"""
|
"""Creates a voucher from an invoice and sends it by email to the client"""
|
||||||
|
president = Mandate.get_mandate().president
|
||||||
ctx = {
|
ctx = {
|
||||||
'asso_name': AssoOption.get_cached_value('name'),
|
'asso_name': AssoOption.get_cached_value('name'),
|
||||||
'pres_name': AssoOption.get_cached_value('pres_name'),
|
'pres_name': ' '.join([president.name, president.surname]),
|
||||||
'firstname': invoice.user.name,
|
'firstname': invoice.user.name,
|
||||||
'lastname': invoice.user.surname,
|
'lastname': invoice.user.surname,
|
||||||
'email': invoice.user.email,
|
'email': invoice.user.email,
|
||||||
|
|
|
@ -60,7 +60,7 @@ from re2o.acl import (
|
||||||
can_delete_set,
|
can_delete_set,
|
||||||
can_change,
|
can_change,
|
||||||
)
|
)
|
||||||
from preferences.models import AssoOption, GeneralOption
|
from preferences.models import AssoOption, GeneralOption, Mandate
|
||||||
from .models import (
|
from .models import (
|
||||||
Facture,
|
Facture,
|
||||||
Article,
|
Article,
|
||||||
|
@ -1068,9 +1068,10 @@ def voucher_pdf(request, invoice, **_kwargs):
|
||||||
_("Could not find a voucher for that invoice.")
|
_("Could not find a voucher for that invoice.")
|
||||||
)
|
)
|
||||||
return redirect(reverse('cotisations:index'))
|
return redirect(reverse('cotisations:index'))
|
||||||
|
president = Mandate.get_mandate().president
|
||||||
return render_voucher(request, {
|
return render_voucher(request, {
|
||||||
'asso_name': AssoOption.get_cached_value('name'),
|
'asso_name': AssoOption.get_cached_value('name'),
|
||||||
'pres_name': AssoOption.get_cached_value('pres_name'),
|
'pres_name': ' '.join([president.name, president.surname]),
|
||||||
'firstname': invoice.user.name,
|
'firstname': invoice.user.name,
|
||||||
'lastname': invoice.user.surname,
|
'lastname': invoice.user.surname,
|
||||||
'email': invoice.user.email,
|
'email': invoice.user.email,
|
||||||
|
|
|
@ -51,4 +51,9 @@ class Migration(migrations.Migration):
|
||||||
bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model),
|
bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model),
|
||||||
),
|
),
|
||||||
migrations.RunPython(create_current_mandate),
|
migrations.RunPython(create_current_mandate),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='cotisationsoption',
|
||||||
|
name='send_voucher_mail',
|
||||||
|
field=models.BooleanField(default=False, help_text='Be carefull, if no mandate is defined on the preferences page, errors will be triggered when generating vouchers.', verbose_name='Send voucher by email when the invoice is controlled.'),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -528,11 +528,24 @@ class Mandate(RevMixin, AclMixin, models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_mandate(cls, date=timezone.now):
|
def get_mandate(cls, date=timezone.now):
|
||||||
|
""""Find the mandate taking place at the given date. If none is found
|
||||||
|
look for the nearest in the future. If none is found (again), look
|
||||||
|
for the nearest in the past."""
|
||||||
if callable(date):
|
if callable(date):
|
||||||
date = date()
|
date = date()
|
||||||
|
try:
|
||||||
return cls.objects.get(
|
return cls.objects.get(
|
||||||
start_date__gte=date, end_date__lte=date
|
start_date__gte=date, end_date__lte=date
|
||||||
)
|
)
|
||||||
|
except cls.DoesNotExist:
|
||||||
|
try:
|
||||||
|
return cls.objects.filter(start_date__gte=date).earliest('start_date')
|
||||||
|
except cls.DoesNotExist:
|
||||||
|
try:
|
||||||
|
return cls.objects.filter(start_date__lte=date).latest('start_date')
|
||||||
|
except cls.DoesNotExist:
|
||||||
|
raise cls.DoesNotExist("No mandate have been created. Please go to the preferences page to create one.")
|
||||||
|
|
||||||
|
|
||||||
def is_over(self):
|
def is_over(self):
|
||||||
return self.end_date is None
|
return self.end_date is None
|
||||||
|
@ -847,6 +860,7 @@ class CotisationsOption(AclMixin, PreferencesModel):
|
||||||
)
|
)
|
||||||
send_voucher_mail = models.BooleanField(
|
send_voucher_mail = models.BooleanField(
|
||||||
verbose_name=_("Send voucher by email when the invoice is controlled."),
|
verbose_name=_("Send voucher by email when the invoice is controlled."),
|
||||||
|
help_text=_("Be carefull, if no mandate is defined on the preferences page, errors will be triggered when generating vouchers."),
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue