Commit cdc8b970 authored by alexAubin's avatar alexAubin
Browse files

Add mecanism to send reminders because of negative balance after importing bank CSV

parent 7d970a52
Pipeline #60 passed with stage
in 2 minutes and 44 seconds
......@@ -14,6 +14,7 @@ from coin.billing.models import Invoice, InvoiceDetail, Payment, \
PaymentAllocation, MembershipFee, Donation
from coin.billing.utils import get_bill_from_id_or_number
from coin.billing.membershipfee_filter import MembershipFeeFilter
from coin.members.models import Member
from coin.members.admin import MemberAdmin
from django.core.urlresolvers import reverse
import autocomplete_light
......@@ -273,7 +274,6 @@ class PaymentAdmin(admin.ModelAdmin):
return my_urls + urls
def wizard_import_payment_csv(self, request):
template = "admin/billing/payment/wizard_import_payment_csv.html"
......@@ -291,9 +291,15 @@ class PaymentAdmin(admin.ModelAdmin):
'adminform': form,
'opts': self.model._meta,
'new_payments': new_payments
})
})
else:
add_new_payments(new_payments)
if "send_reminders" in request.POST:
members_to_remind = Member.objects.filter(balance__lt=0)
for member in members_to_remind:
member.send_reminder_negative_balance(auto=True)
return HttpResponseRedirect('../')
else:
form = WizardImportPaymentCSV()
......
......@@ -14,19 +14,23 @@
<div id="content-main">
<form method="POST" action="." enctype="multipart/form-data">
{% csrf_token %}
<fieldset style="text-align:center;">
<fieldset style="text-align:center; padding: 15px;">
{{ adminform.as_p }}
{% if not new_payments %}
<input type="submit" value="Analser (simulation)" class="default" style="float: none; margin: 0 auto;"/>
{% else %}
<input type="checkbox" id="commit" name="commit" value="1" style="display:None" checked />
<input type="submit" value="Importer pour de vrai !" class="default" style="float: none; margin: 0 auto; background: #ffee77; color: black;"/>
<p style="color: red;">
Les paiements suivants seront importés. Passez en revue les membres matchés avant de cliquer sur 'Import' !
</p>
<p>
N.B. : Il faut resélectionner le fichier (désolé~).
<strong style="color: red;">Les paiements suivants seront importés. Passez en revue les membres matchés avant de cliquer sur 'Import' !</strong>
<br>
<strong>N.B. : Il faut resélectionner le fichier (désolé~).</strong>
</p>
<input type="submit" value="Importer pour de vrai !" class="default" style="float: none; margin: 0 auto; background: #ffee77; color: black;"/>
<br>
<input type="checkbox" id="send_reminders" name="send_reminders" value="1" checked />
<label for="send_reminders" style="color: blue;">Après l'import, envoyer un rappel par mail aux membres ayant un solde négatif.</label>
<br>
<br>
<table style="margin: 0 auto;">
<tr>
<th>Date</th>
......
......@@ -24,7 +24,6 @@ from coin.offers.models import Offer, OfferSubscription
from coin.mixins import CoinLdapSyncMixin
from coin import utils
class MemberQuerySet(models.QuerySet):
paidup_q = Q(
# we have at least one fee
......@@ -390,6 +389,37 @@ class Member(CoinLdapSyncMixin, AbstractUser):
return False
def send_reminder_negative_balance(self, auto=False):
# We only send these reminders if (strictly) more than 14€ is due
if self.balance >= -14:
return
from coin.isp_database.models import ISPInfo
isp_info = ISPInfo.objects.first()
kwargs = {}
# Il peut ne pas y avir d'ISPInfo, ou bien pas d'administrative_email
if isp_info and isp_info.administrative_email:
kwargs['from_email'] = isp_info.administrative_email
url_to_billing_screen = reverse('members:invoices')
# Not sure what's the proper way to build an absolute url :/
if settings.ALLOWED_HOSTS:
url_to_billing_screen = "https://" + settings.ALLOWED_HOSTS[0] + url_to_billing_screen
# Si le dernier courriel de relance a été envoyé il y a moins de trois
# semaines, n'envoi pas un nouveau courriel
utils.send_templated_email(
to=self.email,
subject_template='members/emails/reminder_negative_balance_subject.txt',
body_template='members/emails/reminder_negative_balance.html',
context={'member': self,
'url_to_billing_screen': url_to_billing_screen,
'branding': isp_info,
'auto_sent': auto},
**kwargs)
class Meta:
verbose_name = 'membre'
......
<p>Bonjour {{ member }},</p>
<p>
Ce message est un petit rappel qu'il y a des notes en attente de paiement.
Tu peux voir le détail sur ton espace adhérent :
<a href="{{ url_to_billing_screen }}">{{ url_to_billing_screen }}</a>
</p>
<p>
N'hésite pas à nous contacter en cas de soucis !
</p>
<p>L'équipe de l'association {{ branding.shortname|capfirst }}</p>
{% if auto_sent %}
<p>(Ceci est un message automatique)</p>
{% endif %}
Notes en attente de paiements pour {{ branding.shortname|capfirst }}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment