Skip to content

Commit

Permalink
Optionally restrict stock label printing based on item unit
Browse files Browse the repository at this point in the history
Add an option to control printing of stock labels for items that
will not be individually checked during a stock take. This option
defaults to "off".

Add an option to print a delivery checklist on the receipt printer.

Closes #269 on github.
  • Loading branch information
sde1000 committed Jan 24, 2024
1 parent 3ee3291 commit 53e79f3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
44 changes: 41 additions & 3 deletions quicktill/delivery.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from . import ui, stock, td, keyboard, printer, tillconfig, stocktype
from . import user, usestock
from . import config
from decimal import Decimal
from .models import Delivery, Supplier, StockUnit, StockItem
from .models import StockType, Unit
from .models import penny
from .plugins import InstancePluginMount
import datetime
Expand All @@ -12,6 +14,18 @@
log = logging.getLogger(__name__)


# Do we print stock labels for items where
# StockItem.stocktype.unit.stocktake_by_items is False? (I.e. where
# individual stock items will not be checked, only a total will be
# entered.)
label_everything = config.BooleanConfigItem(
'core:label_everything', False, display_name="Label all stock items?",
description="Should stock labels be printed for all items in a delivery, "
"including items that will not be checked individually during a stock "
"take? (I.e. where the Unit for the item's stock type has the stock take "
"method set to 'total quantity'.)")


@user.permission_required('deliveries', "List deliveries")
def deliverymenu():
"""Display a list of deliveries and call the edit function.
Expand Down Expand Up @@ -241,13 +255,37 @@ def deleteline(self):
title="Confirm Delete",
keymap={keyboard.K_CASH: (self.reallydeleteline, None, True)})

def _label_query(self):
q = td.s.query(StockItem)\
.join(StockType)\
.join(Unit)\
.filter(StockItem.deliveryid == self.dn)\
.order_by(StockItem.id)
if not label_everything():
q = q.filter(Unit.stocktake_by_items == True)
return q

def _print_labels(self, label_printer):
labels = self._label_query().all()
with label_printer as f:
for l in labels:
printer.stock_label(f, l)

def printout(self):
if self.dn is None:
return
menu = [(f"Print labels on {x}",
printer.label_print_delivery, (x, self.dn))
for x in tillconfig.label_printers]
num_labels = self._label_query().count()
menu = []
if tillconfig.receipt_printer:
menu.append(("Print a delivery checklist",
printer.print_delivery_checklist,
(tillconfig.receipt_printer, self.dn)))

if num_labels > 0:
menu.extend((f"Print labels on {x}", self._print_labels, (x,))
for x in tillconfig.label_printers)
ui.automenu(menu, title="Delivery print options",
blurb=[f"There are {num_labels} stock labels to print."],
colour=ui.colour_confirm)

def reallyconfirm(self):
Expand Down
27 changes: 20 additions & 7 deletions quicktill/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,26 @@ def print_deferred_payment_wrapper(printer, trans, paytype, amount, user_name):
d.printline()


def print_delivery_checklist(printer, dn):
d = td.s.query(Delivery).get(dn)
if not d:
return
printtime = ui.formattime(now())
with printer as p:
p.printline(f"\tDelivery {dn} checklist")
p.printline(f"\tFrom {d.supplier.name}")
if d.docnumber:
p.printline(f"\tRef {d.docnumber}")
p.printline(f"\tPrinted {printtime}")
p.printline()
for item in d.items:
p.printline(f"{item.id}: {item.stocktype}")
p.printline(f"{item.description}\t\t[ ]")
p.printline()
p.printline()
p.printline()


def stock_label(f, d):
"""Draw a stock label (d) on a PDF canvas (f). d is a Stock instance
"""
Expand Down Expand Up @@ -272,13 +292,6 @@ def fits(s):
f.showPage()


def label_print_delivery(p, delivery):
d = td.s.query(Delivery).get(delivery)
with p as f:
for s in d.items:
stock_label(f, s)


def print_restock_list(printer, rl):
"""
Print a list of (stockline,stockmovement) tuples.
Expand Down

0 comments on commit 53e79f3

Please sign in to comment.