From 5a3bd5bbb82b8fa826a6bc20b1016060bdb33ead Mon Sep 17 00:00:00 2001 From: Gael Le Mignot Date: Mon, 1 Mar 2021 11:07:41 +0100 Subject: [PATCH] Initial working payment integration --- teleforma/admin.py | 2 +- .../commands/teleforma-send-payment-emails.py | 4 +- teleforma/templates/payment/email_initial.txt | 2 +- .../templates/payment/email_reminder.txt | 2 +- teleforma/views/crfpa.py | 47 ++++++------------- teleforma/views/payment.py | 7 +-- 6 files changed, 22 insertions(+), 42 deletions(-) diff --git a/teleforma/admin.py b/teleforma/admin.py index aa26ce32..2e489b9e 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -423,7 +423,7 @@ admin.site.register(Training, TrainingAdmin) admin.site.register(CourseType) admin.site.register(StreamingServer) admin.site.register(LiveStream) -# admin.site.register(Student, StudentAdmin) +admin.site.register(Student, StudentAdmin) # admin.site.register(Corrector, CorrectorAdmin) # admin.site.register(Professor, ProfessorAdmin) # admin.site.register(StudentGroup, StudentGroupAdmin) diff --git a/teleforma/management/commands/teleforma-send-payment-emails.py b/teleforma/management/commands/teleforma-send-payment-emails.py index cc031e86..b13c57ef 100644 --- a/teleforma/management/commands/teleforma-send-payment-emails.py +++ b/teleforma/management/commands/teleforma-send-payment-emails.py @@ -38,18 +38,16 @@ class Command(BaseCommand): def handle(self, *args, **options): log_file = args[-1] - period_name = args[-2] logger = Logger(log_file) logger.logger.info('########### Processing #############') - period = Period.objects.get(name=period_name) students = Student.objects.all() translation.activate(self.language_code) today = datetime.date.today() for student in students: - if student.is_subscribed and student.user.email and student.period == period: + if student.is_subscribed and student.user.email: for payment in student.payments.filter(type = 'online').exclude(online_paid = True).filter(scheduled__lte = today): if payment.scheduled == today: self.email(student, 'initial', payment) diff --git a/teleforma/templates/payment/email_initial.txt b/teleforma/templates/payment/email_initial.txt index 2aa44539..981ed99e 100644 --- a/teleforma/templates/payment/email_initial.txt +++ b/teleforma/templates/payment/email_initial.txt @@ -1,7 +1,7 @@ {% url teleforma-payment-start payment.pk as payment_url %} Bonjour, -Suite à votre inscription à la formation {{ period }}, une échéance de +Suite à votre inscription à la formation avocat étranger, une échéance de {{ payment.value }} € est arrivée. Pour effectuer votre paiement, veuillez cliquer sur l’URL suivante : diff --git a/teleforma/templates/payment/email_reminder.txt b/teleforma/templates/payment/email_reminder.txt index 90a3ae12..571c2d4c 100644 --- a/teleforma/templates/payment/email_reminder.txt +++ b/teleforma/templates/payment/email_reminder.txt @@ -3,7 +3,7 @@ Bonjour, A ce jour, nous restons dans l’attente de votre échéance de paiement de {{ payment.value }} € relative à vos frais d’inscription à notre -formation {{ period }}. +formation avocat étranger. Merci de bien vouloir procéder à votre règlement dans les meilleurs délais en cliquant sur l'URL suivante : diff --git a/teleforma/views/crfpa.py b/teleforma/views/crfpa.py index 6bb9c1ad..1beae399 100644 --- a/teleforma/views/crfpa.py +++ b/teleforma/views/crfpa.py @@ -645,12 +645,6 @@ class ReceiptPDFView(PDFTemplateResponseMixin, TemplateView): context['site'] = Site.objects.get_current() student = user.student.all()[0] - - if not student.training and student.trainings.all(): - student.training = student.trainings.all()[0] - training = student.training - period = training.period - student.save() profile = user.profile.all()[0] context['student'] = student @@ -666,44 +660,29 @@ class ReceiptPDFView(PDFTemplateResponseMixin, TemplateView): student.receipt_id = receipt_id student.save() - period_name = period.name.split() - period_name = period_name[0].upper() + period = student.period.all()[0] + date_begin = period.date_begin or datetime.date.today() + date_end = period.date_end or datetime.date.today() + period_name = period.name + if period_name.startswith('Session '): + period_name = period_name[8:] + period_name = 'AE_%s' % period_name context['receipt_id'] = "%s_%04d_%05d" % (period_name, - period.date_begin.year, + date_begin.year, receipt_id) self.receipt_id = context['receipt_id'] # Added items to pay items = [] - if student.application_fees: - substract = student.default_application_fees - items.append({ 'label': "Frais de dossier", - 'unit_price': substract, - 'amount': 1, - 'discount': None, },) - else: - substract = 0 + substract = 0 - label = u"Préparation à l'examen du CRFPA
" - label += u"%s — %s
" % (period, training.name) - label += u"%d heures de formation du %s au %s" % (training.duration, - period.date_begin.strftime('%d/%m/%Y'), - period.date_end.strftime('%d/%m/%Y'),) + label = u"Préparation à l'examen d'équivalence au barreau
français - article 100

" + label += u"130h d’enseignement – 28 simulations du %s
au %s
" % (date_begin.strftime('%d/%m/%Y'), date_end.strftime('%d/%m/%Y'),) - oral_1 = student.oral_1 and student.oral_1.title != 'Aucune' - - if oral_1: - substract += ORAL_OPTION_PRICE - items.append({ 'label': label, 'unit_price': student.total_fees - substract - student.total_discount, 'amount': 1, 'discount': student.total_discount, }, ) - if oral_1: - items.append({ 'label': "Option langue", - 'unit_price': ORAL_OPTION_PRICE, - 'amount': 1, - 'discount': 0, }, ) for item in items: item['total'] = item['unit_price'] * item['amount'] if item['discount']: @@ -711,7 +690,9 @@ class ReceiptPDFView(PDFTemplateResponseMixin, TemplateView): # Add payments payments = Payment.objects.filter(student = student) - receipt_last = receipt_date = student.date_subscribed.date() + start = student.date_subscribed + start = start and start.date() or datetime.date(1970, 1, 1) + receipt_last = receipt_date = start for payment in payments: date = payment.scheduled or payment.date_modified.date() receipt_last = max(date, receipt_last) diff --git a/teleforma/views/payment.py b/teleforma/views/payment.py index 4559d869..46ed25af 100644 --- a/teleforma/views/payment.py +++ b/teleforma/views/payment.py @@ -57,9 +57,10 @@ def process_payment(request, payment): Process a payment to Sherlocks """ params = dict(settings.PAYMENT_PARAMETERS) - period = payment.student.period - period_short_name = period.name.split()[0] - params['merchant_id'] = params['merchant_id'][period_short_name] + if isinstance(params['merchant_id'], dict): + period = payment.student.period + period_short_name = period.name.split()[0] + params['merchant_id'] = params['merchant_id'][period_short_name] merchant_id = params['merchant_id'] params['amount'] = str(int(payment.value*100)) params['order_id'] = str(payment.pk) -- 2.39.5