diff --git a/requirements.txt b/requirements.txt
index 957513ab..91629e91 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,5 +5,6 @@ pytz==2024.1
freezegun==1.5.1
Django-Select2==8.1.2
django-debug-toolbar==4.3.0
+django-constance==3.1.0
requests==2.31.0
qrcode==7.4.2
diff --git a/stregsystem/forms.py b/stregsystem/forms.py
index 62dd6ddd..d82e7d56 100644
--- a/stregsystem/forms.py
+++ b/stregsystem/forms.py
@@ -1,5 +1,6 @@
import datetime
+from constance import config
from django import forms
from stregsystem.models import MobilePayment, Member
@@ -28,7 +29,7 @@ def __init__(self, *args, **kwargs):
class QRPaymentForm(forms.Form):
member = forms.CharField(max_length=16)
- amount = forms.DecimalField(min_value=50, decimal_places=2, required=False)
+ amount = forms.DecimalField(min_value=int(config.MINIMUM_PAYMENT_STREGOERE) / 100, decimal_places=2, required=False)
class PurchaseForm(forms.Form):
diff --git a/stregsystem/templates/stregsystem/menu_userpay.html b/stregsystem/templates/stregsystem/menu_userpay.html
index 51ddff5e..7b309219 100644
--- a/stregsystem/templates/stregsystem/menu_userpay.html
+++ b/stregsystem/templates/stregsystem/menu_userpay.html
@@ -37,7 +37,7 @@
{{amount | floatformat:2}} kr.
-
+
{% mobilepay_qr member.username amount %}
|
@@ -46,7 +46,7 @@
Valgfrit beløb
-
+
{% mobilepay_qr member.username %}
diff --git a/stregsystem/tests.py b/stregsystem/tests.py
index b2db8a45..5a3cdd66 100644
--- a/stregsystem/tests.py
+++ b/stregsystem/tests.py
@@ -4,6 +4,7 @@
from copy import deepcopy
from unittest.mock import patch
+from constance import config
import pytz
from django.utils.dateparse import parse_datetime
import stregsystem.parser as parser
@@ -1656,7 +1657,7 @@ def test_ignore_lt_50_20(self):
def test_ignore_lt_50_49(self):
comment = 'tester'
MobilePayment.objects.create(
- amount=4999,
+ amount=int(config.MINIMUM_PAYMENT_STREGOERE) - 1,
comment=comment,
timestamp=parse_datetime("2022-05-16T13:51:08.8574424+01:00"),
transaction_id='156E027485173228',
@@ -1672,7 +1673,7 @@ def test_ignore_lt_50_49(self):
def test_approve_gte_50(self):
comment = 'tester'
MobilePayment.objects.create(
- amount=5000,
+ amount=int(config.MINIMUM_PAYMENT_STREGOERE),
comment=comment,
timestamp=parse_datetime("2022-05-16T13:51:09.8574424+01:00"),
transaction_id='156E027485173229',
diff --git a/stregsystem/utils.py b/stregsystem/utils.py
index edbc3cd6..d90bdc41 100644
--- a/stregsystem/utils.py
+++ b/stregsystem/utils.py
@@ -2,6 +2,7 @@
import re
import csv
+from constance import config
from django.utils.dateparse import parse_datetime
from django.conf import settings
from django.core.exceptions import ValidationError
@@ -76,7 +77,10 @@ def make_unprocessed_member_filled_mobilepayment_query() -> QuerySet:
from stregsystem.models import MobilePayment # import locally to avoid circular import
return MobilePayment.objects.filter(
- Q(payment__isnull=True) & Q(status=MobilePayment.UNSET) & Q(amount__gte=5000) & Q(member__isnull=False)
+ Q(payment__isnull=True)
+ & Q(status=MobilePayment.UNSET)
+ & Q(amount__gte=int(config.MINIMUM_PAYMENT_STREGOERE))
+ & Q(member__isnull=False)
)
diff --git a/stregsystem/views.py b/stregsystem/views.py
index dcc48afc..08bc70d5 100644
--- a/stregsystem/views.py
+++ b/stregsystem/views.py
@@ -2,6 +2,7 @@
import random
from typing import List
+from constance import config
import pytz
from pytz import UTC
from collections import Counter
@@ -281,6 +282,8 @@ def menu_userpay(request, room_id, member_id):
amounts = sorted(amounts)
+ myshop_number = config.VIPPS_MYSHOP_NUMBER
+
return render(request, 'stregsystem/menu_userpay.html', locals())
@@ -504,7 +507,7 @@ def qr_payment(request):
if not form.is_valid():
return HttpResponseBadRequest("Invalid input for MobilePay QR code generation")
- query = {'phone': '90601', 'comment': form.cleaned_data.get('member')}
+ query = {'phone': config.VIPPS_MYSHOP_NUMBER, 'comment': form.cleaned_data.get('member')}
if form.cleaned_data.get("amount") is not None:
query['amount'] = form.cleaned_data.get("amount")
diff --git a/stregsystem/vipps_api.py b/stregsystem/vipps_api.py
index 1cce3170..a0620e19 100644
--- a/stregsystem/vipps_api.py
+++ b/stregsystem/vipps_api.py
@@ -1,6 +1,6 @@
from datetime import datetime, timedelta, date
from django.utils.dateparse import parse_datetime
-
+from constance import config
from requests.auth import HTTPBasicAuth
import requests
from pathlib import Path
@@ -17,7 +17,7 @@ class AccountingAPI(object):
tokens_file_backup = (Path(__file__).parent / 'vipps-tokens.json.bak').as_posix()
tokens = None
- myshop_number = 90601
+ myshop_number = config.VIPPS_MYSHOP_NUMBER
logger = logging.getLogger(__name__)
@classmethod
diff --git a/treo/settings.py b/treo/settings.py
index 4994f69b..e77fb54f 100644
--- a/treo/settings.py
+++ b/treo/settings.py
@@ -91,6 +91,8 @@
# Application definition
INSTALLED_APPS = [
+ 'constance',
+ 'constance.backends.database',
'stregsystem',
'stregreport',
'kiosk',
@@ -249,3 +251,14 @@
}
}
}
+
+CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
+
+CONSTANCE_CONFIG = {
+ 'VIPPS_MYSHOP_NUMBER': ('90601', 'MobilePay Myshop Number'),
+ 'MINIMUM_PAYMENT_STREGOERE': (5000, 'Minimum Pay Amount in Stregoere'),
+}
+
+CONSTANCE_CONFIG_FIELDSETS = {
+ 'Accounting': ('VIPPS_MYSHOP_NUMBER', 'MINIMUM_PAYMENT_STREGOERE',),
+}
|