Skip to content

Commit

Permalink
Remove use of negative slice index in ORM query
Browse files Browse the repository at this point in the history
The "slice index" feature of Query no longer accepts negative indices
in sqlalchemy-2.0.

See #310 on github.
  • Loading branch information
sde1000 committed Jan 24, 2025
1 parent 1ee3fdc commit 83d3929
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions quicktill/till.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from .version import version
from .models import Session, PayType, Business, Register, zero
import subprocess
from sqlalchemy import Date
from sqlalchemy.sql.expression import func, cast
from sqlalchemy.orm import joinedload

# The following imports are to ensure subcommands are loaded
Expand Down Expand Up @@ -362,10 +364,13 @@ def add_arguments(parser):
@staticmethod
def run(args):
with td.orm_session():
sessions = td.s.query(Session)\
.filter(Session.endtime != None)\
.options(joinedload(Session.actual_totals))\
.order_by(Session.id)[-args.days:]
sessions = \
td.s.query(Session)\
.filter(Session.endtime != None)\
.filter(cast(func.now(), Date) - Session.date <= args.days)\
.options(joinedload(Session.actual_totals))\
.order_by(Session.id)\
.all()
businesses = td.s.query(Business).order_by(Business.id).all()
paytypes = td.s.query(PayType)\
.order_by(PayType.order, PayType.paytype)\
Expand Down

0 comments on commit 83d3929

Please sign in to comment.