Skip to content

Commit

Permalink
Prevent stock type deletion if referenced by stock line
Browse files Browse the repository at this point in the history
If a stock type is referenced by a display or continuous stock line, it
cannot be deleted: setting stockline.stocktype to null will cause a
constraint violation.

Closes #260 on github.
  • Loading branch information
sde1000 committed Jun 16, 2023
1 parent 1ea9017 commit fa14409
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion quicktill/tillweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,10 @@ def stocktype(request, info, stocktype_id):
.options(undefer_group('qtys'),
joinedload('delivery'))\
.order_by(desc(StockItem.id))
may_delete = may_alter and items.count() == 0
stocklines = td.s.query(StockLine)\
.filter(StockLine.stocktype == s)\
.filter(StockLine.linetype != "regular")
may_delete = may_alter and items.count() == 0 and stocklines.count() == 0

if may_delete and request.method == 'POST' \
and 'submit_delete' in request.POST:
Expand Down

0 comments on commit fa14409

Please sign in to comment.