From 2d451c57282a61571da2fd27845b51759d839ab5 Mon Sep 17 00:00:00 2001 From: Stephen Early Date: Tue, 25 Jun 2024 20:13:21 +0100 Subject: [PATCH] Don't lock the register if a transaction closes within 3 seconds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a Square transaction was in progress when the user locked the register, it is likely to complete very quickly the next time the user taps in. If this happens within 3 seconds of the user tapping in, don't lock automatically — the user probably wants to start a new transaction. See #288 on github. --- quicktill/register.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/quicktill/register.py b/quicktill/register.py index a19e8bd..ff87dc6 100644 --- a/quicktill/register.py +++ b/quicktill/register.py @@ -29,6 +29,7 @@ from . import tillconfig import math +import time from . import td, ui, keyboard, printer import quicktill.stocktype from . import linekeys @@ -778,6 +779,7 @@ def __init__(self, user, hotkeys, autolock=None, timeout=300): # trans and user are needed for "pagename" which is called in # basicpage.__init__() # transid is now a transaction ID, not a models.Transaction object + self._start_time = time.time() self.transid = None self.user = user log.info("Page created for %s", self.user.fullname) @@ -1017,7 +1019,9 @@ def close_if_balanced(self): self.balance = zero td.s.flush() self._clear_marks() - if self._autolock: + # Check how long it has been since the register was + # created — if it's under a few seconds, do not lock + if self._autolock and time.time() - self._start_time >= 3.0: self.locked = True def linekey(self, kb):