Skip to content

Commit

Permalink
Remove more session.query(model).get(key) calls
Browse files Browse the repository at this point in the history
Hopefully these are the last remaining query(model).get(key) calls,
and all have now been converted to session.get(model, key)

See #310 on github.
  • Loading branch information
sde1000 committed Jan 24, 2025
1 parent 83d3929 commit 54d3694
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
14 changes: 7 additions & 7 deletions quicktill/tillweb/stocktake.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def lookup_code(d, k):
if form.is_valid():
new_stockid = form.cleaned_data['stockid']
if new_stockid:
si = td.s.query(StockItem).get(new_stockid)
si = td.s.get(StockItem, new_stockid)
if si:
if si.stocktype.stocktake == stocktake:
# Take snapshot of item
Expand Down Expand Up @@ -334,9 +334,9 @@ def lookup_code(d, k):
st_adjusting = True
with td.s.no_autoflush:
adjustment = (
td.s.query(StockTakeAdjustment)
.get((stocktake.id, ss.stock_id,
st_adjustreason.id))
td.s.get(StockTakeAdjustment,
(stocktake.id, ss.stock_id,
st_adjustreason.id))
or StockTakeAdjustment(
snapshot=ss, removecode=st_adjustreason,
qty=Decimal(0))
Expand Down Expand Up @@ -368,9 +368,9 @@ def lookup_code(d, k):
ss.checked = True
with td.s.no_autoflush:
adjustment = (
td.s.query(StockTakeAdjustment)
.get((stocktake.id, ss.stock_id,
ss_adjustreason.id))
td.s.get(StockTakeAdjustment,
(stocktake.id, ss.stock_id,
ss_adjustreason.id))
or StockTakeAdjustment(
snapshot=ss, removecode=ss_adjustreason,
qty=Decimal(0))
Expand Down
27 changes: 12 additions & 15 deletions quicktill/tillweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,12 @@ class TransactionNotesForm(forms.Form):

@tillweb_view
def transaction(request, info, transid):
t = td.s.query(Transaction)\
.options(subqueryload(Transaction.payments),
joinedload(Transaction.lines)
.joinedload(Transline.department),
joinedload(Transaction.lines)
.joinedload(Transline.user),
undefer(Transaction.total),
undefer(Transaction.discount_total))\
.get(transid)
t = td.s.get(Transaction, transid, options=[
subqueryload(Transaction.payments),
joinedload(Transaction.lines).joinedload(Transline.department),
joinedload(Transaction.lines).joinedload(Transline.user),
undefer(Transaction.total),
undefer(Transaction.discount_total)])
if not t:
raise Http404

Expand Down Expand Up @@ -856,7 +853,7 @@ def clean(self):

@tillweb_view
def paytype(request, info, paytype):
pt = td.s.query(PayType).get(paytype)
pt = td.s.get(PayType, paytype)
if not pt:
raise Http404

Expand Down Expand Up @@ -985,7 +982,7 @@ class SupplierForm(forms.Form):

@tillweb_view
def supplier(request, info, supplierid):
s = td.s.query(Supplier).get(supplierid)
s = td.s.get(Supplier, supplierid)
if not s:
raise Http404

Expand Down Expand Up @@ -1842,7 +1839,7 @@ class UnitForm(forms.Form):

@tillweb_view
def unit(request, info, unit_id):
u = td.s.query(Unit).get(unit_id)
u = td.s.get(Unit, unit_id)
if not u:
raise Http404

Expand Down Expand Up @@ -1962,7 +1959,7 @@ class StockUnitForm(forms.Form):

@tillweb_view
def stockunit(request, info, stockunit_id):
su = td.s.query(StockUnit).get(stockunit_id)
su = td.s.get(StockUnit, stockunit_id)
if not su:
raise Http404

Expand Down Expand Up @@ -2469,7 +2466,7 @@ def barcodelist(request, info):

if form.is_valid():
cd = form.cleaned_data
barcode = td.s.query(Barcode).get(cd['barcode'])
barcode = td.s.get(Barcode, cd['barcode'])
if barcode:
return HttpResponseRedirect(barcode.get_absolute_url())
messages.error(request, f"Barcode {cd['barcode']} is not known")
Expand Down Expand Up @@ -2563,7 +2560,7 @@ class DepartmentNumberForm(forms.Form):

def clean_number(self):
n = self.cleaned_data['number']
d = td.s.query(Department).get(n)
d = td.s.get(Department, n)
if d:
raise ValidationError(f"Department {n} already exists")
return n
Expand Down

0 comments on commit 54d3694

Please sign in to comment.