From cb6e58d79c66d7cb7b901e2e359ed04121ecafa6 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Mon, 5 Oct 2015 18:03:52 +0200 Subject: [PATCH] define minimal payment amount per regie (#8511) --- .../0010_regie_payment_min_amount.py | 20 +++++++++++++++++++ lingo/models.py | 2 ++ lingo/templates/lingo/combo/item.html | 2 +- lingo/templates/lingo/combo/items.html | 2 +- lingo/views.py | 4 ++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 lingo/migrations/0010_regie_payment_min_amount.py diff --git a/lingo/migrations/0010_regie_payment_min_amount.py b/lingo/migrations/0010_regie_payment_min_amount.py new file mode 100644 index 0000000..7098886 --- /dev/null +++ b/lingo/migrations/0010_regie_payment_min_amount.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('lingo', '0009_auto_20150917_1456'), + ] + + operations = [ + migrations.AddField( + model_name='regie', + name='payment_min_amount', + field=models.DecimalField(default=0, verbose_name='Minimal payment amount', max_digits=7, decimal_places=2), + preserve_default=True, + ), + ] diff --git a/lingo/models.py b/lingo/models.py index c961bf2..7b2eb8a 100644 --- a/lingo/models.py +++ b/lingo/models.py @@ -71,6 +71,8 @@ class Regie(models.Model): verbose_name=_('Payment Service Options')) webservice_url = models.URLField(_('Webservice URL to retrieve remote items'), blank=True) + payment_min_amount = models.DecimalField(_('Minimal payment amount'), + max_digits=7, decimal_places=2, default=0) def is_remote(self): return self.webservice_url != '' diff --git a/lingo/templates/lingo/combo/item.html b/lingo/templates/lingo/combo/item.html index 7ebbbc1..c3c219c 100644 --- a/lingo/templates/lingo/combo/item.html +++ b/lingo/templates/lingo/combo/item.html @@ -29,7 +29,7 @@ {% if item.payment_date %} {% endif %} - {% if item.online_payment %} + {% if item.amount >= regie.payment_min_amount %} {% csrf_token %} diff --git a/lingo/templates/lingo/combo/items.html b/lingo/templates/lingo/combo/items.html index 04a027e..ea902e3 100644 --- a/lingo/templates/lingo/combo/items.html +++ b/lingo/templates/lingo/combo/items.html @@ -26,7 +26,7 @@ {% trans "View" %} - {% if item.online_payment %}{% trans "and pay" %}{% endif %} + {% if item.amount >= item.regie.payment_min_amount %}{% trans "and pay" %}{% endif %} {% if item.has_pdf %} / diff --git a/lingo/views.py b/lingo/views.py index 767eebb..745c52f 100644 --- a/lingo/views.py +++ b/lingo/views.py @@ -20,6 +20,7 @@ import json from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponseForbidden from django.template.response import TemplateResponse from django.utils import timezone from django.views.decorators.csrf import csrf_exempt @@ -132,6 +133,9 @@ class PayView(View): else: total_amount = sum([x.amount for x in items]) + if total_amount < regie.payment_min_amount: + return HttpResponseForbidden() + payment = eopayment.Payment(regie.service, regie.service_options) return_url = request.build_absolute_uri( reverse('lingo-callback', kwargs={'regie_pk': regie.id}))