Skip to content

Commit

Permalink
Add a transaction line summary report to the web interface
Browse files Browse the repository at this point in the history
This report lists the number occurrences of transaction line
descriptions in a department over a date range.

There is an option to truncate the description at '. ' or '; ' which can
help reduce noise from comments and options on food lines, when the
default food ordering system is used.
  • Loading branch information
sde1000 committed Oct 6, 2023
1 parent 08ad82d commit a14201d
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 2 deletions.
4 changes: 2 additions & 2 deletions quicktill/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,11 +1175,11 @@ class Transline(Base, Logged):
name="discount_name_constraint"),
)

@property
@hybrid_property
def original_amount(self):
"""The original amount of the transaction line before any discounts
"""
return self.amount + (self.discount or zero)
return self.amount + self.discount

transaction = relationship(
Transaction,
Expand Down
50 changes: 50 additions & 0 deletions quicktill/tillweb/spreadsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
StockItem,
Unit,
Transaction,
zero,
)
import datetime
from sqlalchemy.orm import undefer
Expand Down Expand Up @@ -757,3 +758,52 @@ def stocksold(start=None, end=None, dates="transaction", tillname="Till"):

doc.add_table(sheet)
return doc.as_response()


def translinesummary(start=None, end=None, dates="transaction",
department=None, simplify=False, tillname="Till"):
what = Transline.text

if simplify:
what = func.regexp_replace(what, '[.;] .*', '')

tl = td.s.query(what, func.sum(Transline.items))\
.select_from(Transline)\
.filter(Transline.original_amount != zero)\
.group_by(what)\
.order_by(func.sum(Transline.items).desc())

if department:
tl = tl.filter(Transline.dept_id == department.id)

if dates == "transaction":
tl = tl.join(Transaction, Session)
if start:
tl = tl.filter(Session.date >= start)
if end:
tl = tl.filter(Session.date <= end)
else:
if start:
tl = tl.filter(Transline.time >= start)
if end:
tl = tl.filter(
Transline.time < (end + datetime.timedelta(days=1)))

filename = "{}-transline-summary.ods".format(tillname)
doc = Document(filename)

sheet = Sheet("Transaction line summary")
# Columns are:
# Text Count
# Manufacturer Name ABV Dept qty Unit
sheet.cell(0, 0, doc.headercell("Description"))
sheet.cell(1, 0, doc.headercell("Count"))

row = 1
for text, count in tl.all():
sheet.cell(0, row, doc.textcell(text))
sheet.cell(1, row, doc.numbercell(count))
row += 1

doc.add_table(sheet)
return doc.as_response()
1 change: 1 addition & 0 deletions quicktill/tillweb/templates/tillweb/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ <h2>Reports</h2>
<li class="nav-item"><a class="nav-link" href="{% url 'tillweb-report-wasted-stock' pubname=pubname %}">Wasted stock</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'tillweb-report-stock-sold' pubname=pubname %}">Stock sold</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'tillweb-stockcheck' pubname=pubname %}">Buying list</a></li>
<li class="nav-item"><a class="nav-link" href="{% url "tillweb-report-transline-summary" pubname=pubname %}">Transaction lines</a></li>
</ul>

{% endblock %}
1 change: 1 addition & 0 deletions quicktill/tillweb/templates/tillweb/tillweb.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<a class="dropdown-item" href="{% url "tillweb-report-wasted-stock" pubname=pubname %}">Wasted stock</a>
<a class="dropdown-item" href="{% url "tillweb-report-stock-sold" pubname=pubname %}">Stock sold</a>
<a class="dropdown-item" href="{% url "tillweb-stockcheck" pubname=pubname %}">Buying list</a>
<a class="dropdown-item" href="{% url "tillweb-report-transline-summary" pubname=pubname %}">Transaction lines</a>
</div>
</li>
</ul>
Expand Down
47 changes: 47 additions & 0 deletions quicktill/tillweb/templates/tillweb/transline-summary-report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends "tillweb/tillweb.html" %}

{% block title %}{{till}} — Transaction line summary{% endblock %}

{% block tillcontent %}

<h2 class="mt-3">Transaction line summary</h2>

<p>This report shows transaction line descriptions in a department,
along with the number of times they occurred within the time
period. Voids are treated as negative occurrences, i.e. a unique
transaction line description that is sold and then voided will show
up with a count of zero.</p>

<p>Transaction lines that have a price of zero are not included. These
are typically used as comments (eg. table number for food
sales). Transaction lines that have a price but have been discounted
to zero <em>are</em> included.</p>

<p>There are two dates associated with transaction lines, and you can
choose either one when setting up this report:</p>
<ol>
<li>Transaction Date: the date of the transaction in which the
transaction line occurs. This can change if a transaction is
deferred from one session to the next. Transactions that are
currently deferred (i.e. not attached to a session) are not
counted at all.</li>
<li>Date entered: the date on which the transaction line was
created. This will not change even when the transaction is
deferred.</li>
</ol>

<form action="" method="post">{% csrf_token %}
{% include "form-horizontal.html" %}
<button class="btn btn-secondary" type="submit" name="submit_transline_summary">Download</button>
</form>

<script type="text/javascript">
var dtpicker_options = {firstDay: 1,
dateFormat: 'yy-mm-dd'};
$(document).ready(function(){
$("#id_startdate").datepicker(dtpicker_options);
$("#id_enddate").datepicker(dtpicker_options);
});
</script>

{% endblock %}
2 changes: 2 additions & 0 deletions quicktill/tillweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
path('reports/stock-sold/', views.stock_sold_report,
name="tillweb-report-stock-sold"),
path('reports/stockcheck/', views.stockcheck, name="tillweb-stockcheck"),
path('reports/translines/', views.transline_summary_report,
name="tillweb-report-transline-summary"),

path('datatable/sessions.json', datatable.sessions,
name="tillweb-datatable-sessions"),
Expand Down
36 changes: 36 additions & 0 deletions quicktill/tillweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3019,3 +3019,39 @@ def stock_sold_report(request, info):
],
'stocksoldform': stocksoldform,
})


class TranslineSummaryReportForm(StockSoldReportForm):
department = SQLAModelChoiceField(
Department,
query_filter=lambda q: q.order_by(Department.id))

simplify = forms.BooleanField(
required=False, label="Attempt to simplify food descriptions "
"by removing all text after '. ' or '; '")


@tillweb_view
def transline_summary_report(request, info):
if request.method == 'POST' and "submit_transline_summary" in request.POST:
form = TranslineSummaryReportForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
return spreadsheets.translinesummary(
start=cd['startdate'],
end=cd['enddate'],
dates=cd['dates'],
department=cd['department'],
simplify=cd['simplify'],
tillname=info.tillname)
else:
form = TranslineSummaryReportForm()

return ('transline-summary-report.html', {
'nav': [
("Reports", info.reverse("tillweb-reports")),
("Transaction lines", info.reverse(
"tillweb-report-transline-summary")),
],
'form': form,
})

0 comments on commit a14201d

Please sign in to comment.