Skip to content

Commit

Permalink
Enable stock line type to be changed through web interface
Browse files Browse the repository at this point in the history
Closes #293 on github.
  • Loading branch information
sde1000 committed Jun 25, 2024
1 parent f951a5f commit a1b3873
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 43 deletions.
34 changes: 34 additions & 0 deletions quicktill/tillweb/templates/tillweb/stockline-continuous.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<button class="btn btn-secondary mb-2" type="button" data-toggle="modal" data-target="#changeModal">
Change details
</button>
<button class="btn btn-secondary mb-2" type="button" data-toggle="modal" data-target="#changeLineTypeModal">
Change line type
</button>
<div class="modal fade" id="changeModal" tabindex="-1" aria-labelledby="changeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
Expand Down Expand Up @@ -59,6 +62,37 @@ <h5 class="modal-title" id="changeModalLabel">Edit stock line</h5>
</div>
</div>
</div>
<div class="modal fade" id="changeLineTypeModal" tabindex="-1" aria-labelledby="changeLineTypeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="changeLineTypeModalLabel">Change line type</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="" method="post">{% csrf_token %}
<div class="modal-body">
<p>This is currently a continuous stock line — all stock
items of the specified type are available for sale, and
the till will switch from one to the next when the first
one is used up.</p>
<p>You can choose to change this to a regular stock line —
you will need to tell the till explicitly when a stock
item is put on sale and when it is finished.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button class="btn btn-primary" type="submit" name="submit_conv_regular">
Change to regular stock line
</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}

{% if stockline.stocktype.stockonsale %}
Expand Down
79 changes: 58 additions & 21 deletions quicktill/tillweb/templates/tillweb/stockline-display.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,70 @@
<button class="btn btn-secondary mb-2" type="button" data-toggle="modal" data-target="#changeModal">
Change details
</button>
<button class="btn btn-secondary mb-2" type="button" data-toggle="modal" data-target="#changeLineTypeModal">
Change line type
</button>
<div class="modal fade" id="changeModal" tabindex="-1" aria-labelledby="changeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="changeModalLabel">Edit stock line</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h5 class="modal-title" id="changeModalLabel">Edit stock line</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="" method="post">{% csrf_token %}
<div class="modal-body">
{% include "form-horizontal.html" %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button class="btn btn-danger" type="submit" name="submit_delete" formnovalidate{% if stockline.stockonsale %} disabled{% endif %}>
Delete stock line
</button>
<button class="btn btn-primary" type="submit" name="submit_update">
Update stock line
</button>
</div>
<datalist id="locations">
{% for l in locations %}<option value="{{l}}">{% endfor %}
</datalist>
</form>
</div>
</div>
</div>
<div class="modal fade" id="changeLineTypeModal" tabindex="-1" aria-labelledby="changeLineTypeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="changeLineTypeModalLabel">Change line type</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="" method="post">{% csrf_token %}
<div class="modal-body">
{% include "form-horizontal.html" %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button class="btn btn-danger" type="submit" name="submit_delete" formnovalidate{% if stockline.stockonsale %} disabled{% endif %}>
Delete stock line
</button>
<button class="btn btn-primary" type="submit" name="submit_update">
Update stock line
</button>
</div>
<datalist id="locations">
{% for l in locations %}<option value="{{l}}">{% endfor %}
</datalist>
<div class="modal-body">
<p>This is currently a display stock line — multiple stock
items of a particular type are on sale, and the till keeps
track of how many are in storage and how many are on
display and ready to sell.</p>
<p>You can choose to change this to a continuous stock line
— all items of that type will be available for use and the
till will switch from one to the next when the first is
used up. The till won't keep track of how many items are
on display and ready to sell, it will assume that all
items are ready for sale.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button class="btn btn-primary" type="submit" name="submit_conv_continuous">
Change to continuous stock line
</button>
</div>
</form>
</div>
</div>
Expand Down
82 changes: 61 additions & 21 deletions quicktill/tillweb/templates/tillweb/stockline-regular.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,73 @@
<button class="btn btn-secondary mb-2" type="button" data-toggle="modal" data-target="#changeModal">
Change details
</button>
<button class="btn btn-secondary mb-2" type="button" data-toggle="modal" data-target="#changeLineTypeModal">
Change line type
</button>
<div class="modal fade" id="changeModal" tabindex="-1" aria-labelledby="changeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="changeModalLabel">Edit stock line</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h5 class="modal-title" id="changeModalLabel">Edit stock line</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="" method="post">{% csrf_token %}
<div class="modal-body">
{% include "form-horizontal.html" %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button class="btn btn-danger" type="submit" name="submit_delete" formnovalidate{% if stockline.stockonsale %} disabled{% endif %}>
Delete stock line
</button>
<button class="btn btn-primary" type="submit" name="submit_update">
Update stock line
</button>
</div>
<datalist id="locations">
{% for l in locations %}<option value="{{l}}">{% endfor %}
</datalist>
</form>
</div>
</div>
</div>
<div class="modal fade" id="changeLineTypeModal" tabindex="-1" aria-labelledby="changeLineTypeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="changeLineTypeModalLabel">Change line type</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="" method="post">{% csrf_token %}
<div class="modal-body">
{% include "form-horizontal.html" %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button class="btn btn-danger" type="submit" name="submit_delete" formnovalidate{% if stockline.stockonsale %} disabled{% endif %}>
Delete stock line
</button>
<button class="btn btn-primary" type="submit" name="submit_update">
Update stock line
</button>
</div>
<datalist id="locations">
{% for l in locations %}<option value="{{l}}">{% endfor %}
</datalist>
<div class="modal-body">
<p>This is currently a regular stock line — a single stock
item is on sale at once and you must tell the till with the
Use Stock function when you change to a new item.</p>
<p>You can choose to change this to a continuous stock line
— all items of a particular type will be available for use
and the till will switch from one to the next when the
first is used up.</p>
{% if not stockline.stockonsale and not stockline.stocktype %}
<div class="alert alert-warning">You must either put an item
on sale or change the stock line to restrict items to a
particular stock type before you can change this to be a
continuous stock line.</div>
{% endif %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button class="btn btn-primary" type="submit" name="submit_conv_continuous"{% if not stockline.stockonsale and not stockline.stocktype %} disabled{% endif %}>
Change to continuous stock line
</button>
</div>
</form>
</div>
</div>
Expand Down
38 changes: 37 additions & 1 deletion quicktill/tillweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.http import JsonResponse
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.template.loader import render_to_string
from django.conf import settings
from django import forms
Expand Down Expand Up @@ -2118,6 +2118,7 @@ def stockline_regular(request, info, s):
s.stocktype = cd['stocktype']
s.department = cd['department']
s.pullthru = cd['pullthru']
user.log(f"Updated stock line {s.logref}")
try:
td.s.commit()
messages.success(request, "Stock line updated")
Expand All @@ -2133,6 +2134,22 @@ def stockline_regular(request, info, s):
td.s.commit()
messages.success(request, "Stock line deleted")
return HttpResponseRedirect(info.reverse("tillweb-stocklines"))
elif request.method == 'POST' \
and 'submit_conv_continuous' in request.POST: # noqa: E127
if not s.stockonsale and not s.stocktype:
messages.error(request, "Could not change line type")
return redirect(s)
for si in list(s.stockonsale):
si.stockline = None
s.pullthru = None
s.department = None
s.stocktype = si.stocktype
messages.success(request, "Stock line converted to Continuous")
user.log(f"Converted stock line {s.logref} from Regular to "
f"Continuous, selling {s.stocktype.logref}")
s.linetype = "continuous"
td.s.commit()
return redirect(s)
else:
form = RegularStockLineForm(info, initial={
"name": s.name,
Expand Down Expand Up @@ -2212,6 +2229,18 @@ def stockline_display(request, info, s):
td.s.commit()
messages.success(request, "Stock line deleted")
return HttpResponseRedirect(info.reverse("tillweb-stocklines"))
elif request.method == 'POST' \
and 'submit_conv_continuous' in request.POST: # noqa: E127
for si in list(s.stockonsale):
si.stockline = None
si.displayqty = None
s.capacity = None
s.linetype = "continuous"
messages.success(request, "Stock line converted to Continuous")
user.log(f"Converted stock line {s.logref} from Display to "
f"Continuous, selling {s.stocktype.logref}")
td.s.commit()
return redirect(s)
else:
form = DisplayStockLineForm(info, initial={
"name": s.name,
Expand Down Expand Up @@ -2279,6 +2308,13 @@ def stockline_continuous(request, info, s):
td.s.commit()
messages.success(request, "Stock line deleted")
return HttpResponseRedirect(info.reverse("tillweb-stocklines"))
elif request.method == 'POST' and 'submit_conv_regular' in request.POST:
s.linetype = "regular"
messages.success(request, "Stock line converted to Regular")
user.log(f"Converted stock line {s.logref} from Continuous to "
f"Regular, selling only {s.stocktype.logref}")
td.s.commit()
return redirect(s)
else:
form = ContinuousStockLineForm(info, initial={
"name": s.name,
Expand Down

0 comments on commit a1b3873

Please sign in to comment.