Added 'supply' page to create negative register transactions, updated translation
This commit is contained in:
parent
80b407069d
commit
86ea7c0000
10 changed files with 278 additions and 68 deletions
|
@ -49,6 +49,10 @@ class CustomUserAdmin(UserAdmin):
|
|||
{"fields": ("balance", "allow_order_with_negative_balance")},
|
||||
))
|
||||
fieldsets_.insert(2, (
|
||||
"Supply",
|
||||
{"fields": ("allowed_to_supply",)},
|
||||
))
|
||||
fieldsets_.insert(3, (
|
||||
"Profile Picture",
|
||||
{"fields": ("profile_picture_filename",)},
|
||||
))
|
||||
|
|
|
@ -21,6 +21,7 @@ class User(AbstractUser):
|
|||
balance = models.DecimalField(max_digits=8, decimal_places=2, default=0.00)
|
||||
allow_order_with_negative_balance = models.BooleanField(default=False)
|
||||
profile_picture_filename = models.CharField(default="default.svg", max_length=25)
|
||||
allowed_to_supply = models.BooleanField(default=False)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.balance = 0
|
||||
|
|
61
application/app/templates/supply.html
Normal file
61
application/app/templates/supply.html
Normal file
|
@ -0,0 +1,61 @@
|
|||
{% extends "baseLayout.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load l10n %}
|
||||
|
||||
{% block title %}
|
||||
{% translate "Drinks - Supply" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block headAdditional %}
|
||||
<link rel="stylesheet" href="/static/css/supply.css">
|
||||
<link rel="stylesheet" href="/static/css/customNumberInput.css">
|
||||
{% endblock %}
|
||||
|
||||
{% block heading %}
|
||||
{% translate "Supply" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if user.is_superuser or user.allowed_to_supply %}
|
||||
|
||||
<form id="supplyForm">
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="row">
|
||||
<div class="column">{% translate "Description" %}:</div>
|
||||
<input type="text" name="supplyDescription" id="supplyDescription" autofocus>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="column">{% translate "Price" %} ({{ currency_suffix }}):</div>
|
||||
<div class="column">
|
||||
<input type="number" name="supplyPrice" id="supplyPrice" max="9999.99" min="1.00" step="0.01">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="statusInfo"></div>
|
||||
|
||||
<div class="horizontalButtonList">
|
||||
<a href="/" class="button">{% translate "cancel" %}</a>
|
||||
<input type="submit" id="supplySubmitBtn" class="button" value='{% translate "submit" %}'>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<script src="/static/js/supply.js"></script>
|
||||
<script src="/static/js/customNumberInput.js"></script>
|
||||
|
||||
{% else %}
|
||||
|
||||
<div class="centeringFlex">
|
||||
<p>{% translate "You are not allowed to view this site." %}</p>
|
||||
<a href="/">{% translate "back" %}</a>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
<script src="/static/js/autoreload.js"></script>
|
||||
|
||||
{% endblock %}
|
|
@ -32,6 +32,9 @@
|
|||
{% if user.is_superuser or user.is_staff %}
|
||||
<a class="button dropDownChoice" href="/admin/">Admin Panel</a>
|
||||
{% endif %}
|
||||
{% if user.is_superuser or user.allowed_to_supply %}
|
||||
<a class="button dropDownChoice" href="/supply/">{% translate "Supply" %}</a>
|
||||
{% endif %}
|
||||
<a class="button dropDownChoice" href="/accounts/password_change/">{% translate "Change Password" %}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,6 +10,7 @@ urlpatterns = [
|
|||
path('history/', views.history),
|
||||
path('deposit/', views.deposit),
|
||||
path('statistics/', views.statistics),
|
||||
path('supply/', views.supply),
|
||||
path('accounts/login/', views.login_page, name="login"),
|
||||
path('accounts/logout/', auth_views.LogoutView.as_view(), name='logout'),
|
||||
path('accounts/password_change/', auth_views.PasswordChangeView.as_view(), name='password_change'),
|
||||
|
@ -18,5 +19,6 @@ urlpatterns = [
|
|||
# API #
|
||||
path('api/order-drink', views.api_order_drink),
|
||||
path('api/deposit', views.api_deposit),
|
||||
path('api/supply', views.api_supply)
|
||||
#path('api/get-statistics', views.api_get_statistics)
|
||||
]
|
|
@ -103,6 +103,10 @@ def statistics(request):
|
|||
}
|
||||
return render(request, "statistics.html", context)
|
||||
|
||||
@login_required
|
||||
def supply(request):
|
||||
return render(request, "supply.html")
|
||||
|
||||
@login_required
|
||||
def redirect_home(request):
|
||||
return HttpResponseRedirect("/")
|
||||
|
@ -132,7 +136,7 @@ def api_order_drink(request):
|
|||
else:
|
||||
return HttpResponse("notAvailable", status=400)
|
||||
|
||||
else: raise Exception("Balance below zero.")
|
||||
else: raise Exception("Unexpected input or missing privileges.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An exception occured while processing an order: User: {user.username} - Exception: {e}", file=sys.stderr)
|
||||
|
@ -163,5 +167,33 @@ def api_deposit(request):
|
|||
else: raise Exception("Deposit amount too big or small.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An exception occured while processing an transaction: User: {user.username} - Exception: {e}", file=sys.stderr)
|
||||
print(f"An exception occured while processing a transaction: User: {user.username} - Exception: {e}", file=sys.stderr)
|
||||
return HttpResponse(b"", status=500)
|
||||
|
||||
@login_required
|
||||
def api_supply(request):
|
||||
|
||||
# check request -> supply
|
||||
|
||||
user = request.user
|
||||
|
||||
try:
|
||||
|
||||
price = decimal.Decimal(request.POST["supplyPrice"])
|
||||
description = str(request.POST["supplyDescription"])
|
||||
|
||||
if 0.00 < price < 9999.99 and (user.allowed_to_supply or user.is_superuser):
|
||||
# create transaction
|
||||
RegisterTransaction.objects.create(
|
||||
transaction_sum=-price,
|
||||
comment=f"Supply: {description}",
|
||||
is_user_deposit=False,
|
||||
user=user
|
||||
)
|
||||
#
|
||||
return HttpResponse("success", status=200)
|
||||
else: raise Exception("Unexpected input or missing privileges.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"An exception occured while processing a supply transaction: User: {user.username} - Exception: {e}", file=sys.stderr)
|
||||
return HttpResponse(b"", status=500)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue