Skip to content

Commit

Permalink
Add a "note" column to the stocklines table
Browse files Browse the repository at this point in the history
Closes #272 on github.
  • Loading branch information
sde1000 committed Jan 26, 2024
1 parent 70fea3a commit f7d6959
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 9 deletions.
3 changes: 3 additions & 0 deletions quicktill/localutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from . import usestock
from . import recordwaste
from . import stock
from . import stocklines
from . import register
from . import ui
from . import td
Expand Down Expand Up @@ -489,6 +490,8 @@ def register_hotkeys(appsmenu=None):
'R': recordwaste.popup,
'm': managetill.popup,
'M': managetill.popup,
'n': stocklines.stocklinenotemenu,
'N': stocklines.stocklinenotemenu,
}
if appsmenu:
hk[K_APPS] = appsmenu
Expand Down
4 changes: 4 additions & 0 deletions quicktill/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,10 @@ class StockLine(Base, Logged):
pullthru = Column(quantity, doc='If a "Regular" stockline, the amount '
'of stock that should be disposed of the first time the '
'stock is sold each day.')
note = Column(String(), nullable=False, server_default='',
doc='Note about the status of this stock line. If stock '
'is present, the note should be treated for display '
'purposes as an abnormal condition.')
stocktype_id = Column(
'stocktype', Integer, ForeignKey('stocktypes.stocktype'),
nullable=True)
Expand Down
33 changes: 33 additions & 0 deletions quicktill/stocklines.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,30 @@ def reload_bindings(self):
self.kbs.set(kbl)


class note(user.permission_checked, ui.dismisspopup):
permission_required = (
'stockline-note', 'Change the note on a stock line')

def __init__(self, stockline):
td.s.add(stockline)
self.stocklineid = stockline.id
super().__init__(7, 60, title=f"Set the note on {stockline.name}",
colour=ui.colour_input)
self.win.drawstr(2, 2, 6, "Note: ", align=">")
self.notefield = ui.editfield(2, 8, 47, f=stockline.note, keymap={
keyboard.K_CLEAR: (self.dismiss, None)})
self.b = ui.buttonfield(4, 26, 7, "Set", keymap={
keyboard.K_CASH: (self.enter, None)})
ui.map_fieldlist([self.notefield, self.b])
self.notefield.focus()

def enter(self):
stockline = td.s.query(StockLine).get(self.stocklineid)
if stockline:
stockline.note = self.notefield.f
self.dismiss()


class listunbound(user.permission_checked, ui.listpopup):
"""Pop up a list of stock lines with no key bindings on any keyboard."""
permission_required = ('list-unbound-stocklines',
Expand Down Expand Up @@ -673,6 +697,15 @@ def stocklinemenu():
"stock line.", create_new=True)


def stocklinenotemenu():
"""Menu allowing notes to be set on stocklines
"""
selectline(
note, blurb="Choose a stock line from the list below, or press "
"a line key that is bound to the stock line.",
linetypes=["regular"], create_new=False)


def selectlocation(func, title="Stock Locations", blurb="Choose a location",
linetypes=None):
"""A pop-up menu of stock locations.
Expand Down
20 changes: 14 additions & 6 deletions quicktill/stockterminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,29 @@ def drawlines(self, h):
f = ui.tableformatter("pl l L r rp")
header = f("Line", "StockID", "Stock", "Used", "Remaining")

# Format note. It should be possible to make better use of the
# available screen space, but we'd need ui.tableformatter to
# support multi-column spans first.
def ln(line, text):
if line.note:
return f"⚠ {line.note}; {text}"
return f"{text}"

def fl(line):
if line.linetype == "regular" and line.stockonsale:
sos = line.stockonsale[0]
return (line.name, sos.id, sos.stocktype.format(),
return (line.name, sos.id, ln(line, sos.stocktype),
sos.stocktype.unit.format_stock_qty(sos.used),
sos.stocktype.unit.format_stock_qty(sos.remaining))
elif line.linetype == "continuous":
return (line.name, "", line.stocktype.format(), "",
return (line.name, "", ln(line, line.stocktype), "",
line.stocktype.unit.format_stock_qty(
line.stocktype.remaining))
elif line.linetype == "display":
return (line.name, "", line.stocktype.format(), "",
"{}+{} {}".format(line.ondisplay, line.instock,
line.stocktype.unit.name))
return (line.name, "", "", "", "")
return (line.name, "", ln(line, line.stocktype), "",
f"{line.ondisplay}+{line.instock} "
f"{line.stocktype.unit.name}")
return (line.name, "", line.note or "", "", "")

ml = [header] + [f(*fl(line)) for line in sl]
y = 0
Expand Down
5 changes: 3 additions & 2 deletions quicktill/tillweb/templates/tillweb/stocklines.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2 id="regular">Regular stock lines</h2>
<th scope="col">Location</th>
<th scope="col">Department</th>
<th scope="col">Pullthru?</th>
<th scope="col">Stock</th>
<th scope="col">Stock / state</th>
</tr>
</thead>
<tbody>
Expand All @@ -31,7 +31,8 @@ <h2 id="regular">Regular stock lines</h2>
<td><a href="{% url "tillweb-location" pubname=pubname location=line.location %}">{{line.location}}</a></td>
<td>{% if line.department %}<a href="{{line.department.get_absolute_url}}">{{line.department}}</a>{% endif %}</td>
<td>{% if line.pullthru %}{{line.pullthru}}{% endif %}</td>
<td>{% if line.stockonsale %}<a href="{{line.stockonsale.0.get_absolute_url}}">{{line.stockonsale.0.id}}: {{line.stockonsale.0.stocktype}}</a>{% endif %}</td>
<td>{% if line.stockonsale %}<a href="{{line.stockonsale.0.get_absolute_url}}">{{line.stockonsale.0.id}}: {{line.stockonsale.0.stocktype}}</a>{% endif %}
{% if line.note %}<span class="badge badge-{% if line.stockonsale %}warning{% else %}info{% endif %}">{{line.note}}</span>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
1 change: 1 addition & 0 deletions quicktill/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ class default_groups:
"auto-allocate",
"manage-stockline-associations",
"annotate",
"stockline-note",
"cancel-cash-payment",
])

Expand Down
9 changes: 9 additions & 0 deletions quicktill/usestock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from . import ui, td, keyboard, stock, stocklines, user, linekeys
from . import stocktype
from . import config
from .plugins import InstancePluginMount
from .models import StockLine, FinishCode, StockItem, Delivery
from .models import StockAnnotation
Expand All @@ -10,6 +11,12 @@
import logging
log = logging.getLogger(__name__)

clear_stockline_note_on_new_stock = config.BooleanConfigItem(
'core:clear_stockline_note_on_new_stock', False,
display_name="Clear stock line note when changing stock",
description="Should the note on a stock line be cleared automatically "
"when a new stock item is put on sale on that stock line?")


# The "Use Stock" popup has several different functions:

Expand Down Expand Up @@ -189,6 +196,8 @@ def put_on_sale(line, si):
si.stockline = line
if line.linetype == "display":
si.displayqty = si.used
if clear_stockline_note_on_new_stock() and line.linetype == "regular":
line.note = ''
td.s.add(StockAnnotation(stockitem=si, atype='start', text=line.name,
user=user.current_dbuser()))
td.s.flush()
Expand Down
5 changes: 4 additions & 1 deletion release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ To upgrade the database:
BEGIN;
ALTER TABLE users
ADD COLUMN last_seen timestamp without time zone;
ADD COLUMN last_seen timestamp without time zone;
ALTER TABLE stocklines
ADD COLUMN note character varying DEFAULT ''::character varying NOT NULL;
COMMIT;
```
Expand Down

0 comments on commit f7d6959

Please sign in to comment.