|
|
|
@ -40,6 +40,8 @@ from django.db.models import Q |
|
|
|
from django.forms import modelformset_factory, formset_factory |
|
|
|
from django.utils import timezone |
|
|
|
from django.utils.translation import ugettext as _ |
|
|
|
from django.core.mail import EmailMessage |
|
|
|
from django.template.loader import get_template |
|
|
|
|
|
|
|
# Import des models, forms et fonctions re2o |
|
|
|
from reversion import revisions as reversion |
|
|
|
@ -72,7 +74,7 @@ from .forms import ( |
|
|
|
SelectClubArticleForm, |
|
|
|
RechargeForm |
|
|
|
) |
|
|
|
from .tex import render_invoice |
|
|
|
from .tex import create_pdf, render_invoice |
|
|
|
from .payment_methods.forms import payment_method_factory |
|
|
|
from .utils import find_payment_method |
|
|
|
|
|
|
|
@ -147,6 +149,48 @@ def new_facture(request, user, userid): |
|
|
|
p.facture = new_invoice_instance |
|
|
|
p.save() |
|
|
|
|
|
|
|
facture = new_invoice_instance # BErk |
|
|
|
purchases_info = [] |
|
|
|
for purchase in facture.vente_set.all(): |
|
|
|
purchases_info.append({ |
|
|
|
'name': purchase.name, |
|
|
|
'price': purchase.prix, |
|
|
|
'quantity': purchase.number, |
|
|
|
'total_price': purchase.prix_total |
|
|
|
}) |
|
|
|
ctx = { |
|
|
|
'paid': True, |
|
|
|
'fid': facture.id, |
|
|
|
'DATE': facture.date, |
|
|
|
'recipient_name': "{} {}".format( |
|
|
|
facture.user.name, |
|
|
|
facture.user.surname |
|
|
|
), |
|
|
|
'address': facture.user.room, |
|
|
|
'article': purchases_info, |
|
|
|
'total': facture.prix_total(), |
|
|
|
'asso_name': AssoOption.get_cached_value('name'), |
|
|
|
'line1': AssoOption.get_cached_value('adresse1'), |
|
|
|
'line2': AssoOption.get_cached_value('adresse2'), |
|
|
|
'siret': AssoOption.get_cached_value('siret'), |
|
|
|
'email': AssoOption.get_cached_value('contact'), |
|
|
|
'phone': AssoOption.get_cached_value('telephone'), |
|
|
|
'tpl_path': os.path.join(settings.BASE_DIR, LOGO_PATH) |
|
|
|
} |
|
|
|
|
|
|
|
pdf = create_pdf('cotisations/factures.tex', ctx) |
|
|
|
|
|
|
|
template = get_template('cotisations/email_invoice') |
|
|
|
|
|
|
|
mail = EmailMessage( |
|
|
|
_('Your invoice'), |
|
|
|
template.render(ctx), |
|
|
|
GeneralOption.get_cached_value('email_from'), |
|
|
|
[new_invoice_instance.user.email], |
|
|
|
attachments = [('invoice.pdf', pdf, 'application/pdf')] |
|
|
|
) |
|
|
|
mail.send() |
|
|
|
|
|
|
|
return new_invoice_instance.paiement.end_payment( |
|
|
|
new_invoice_instance, |
|
|
|
request |
|
|
|
@ -161,6 +205,7 @@ def new_facture(request, user, userid): |
|
|
|
balance = user.solde |
|
|
|
else: |
|
|
|
balance = None |
|
|
|
|
|
|
|
return form( |
|
|
|
{ |
|
|
|
'factureform': invoice_form, |
|
|
|
|