Skip to content

Commit

Permalink
Check carefully for optional form fields
Browse files Browse the repository at this point in the history
EditDeliveryForm fields are mostly optional; they are left
blank when not adding a new item. Don't assume that
cleaned_data contains all the keys we expect.

Closes #257 on github.
  • Loading branch information
sde1000 committed Jun 16, 2023
1 parent 81cd278 commit 1ea9017
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions quicktill/tillweb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,15 +1207,16 @@ def clean(self):
if cd['stocktype'] or cd['itemsize'] or cd['quantity'] \
or cd['costprice'] or cd['saleprice'] or cd['bestbefore']:
msg = 'Required when adding stock to a delivery'
if not cd['stocktype']:
if not cd.get('stocktype'):
self.add_error('stocktype', msg)
if not cd['itemsize']:
if not cd.get('itemsize'):
self.add_error('itemsize', msg)
if not cd['quantity']:
if not cd.get('quantity'):
self.add_error('quantity', msg)
if cd['itemsize'].unit != cd['stocktype'].unit:
self.add_error('itemsize', 'Item size is not valid for '
'the selected stock type')
if cd.get('itemsize') and cd.get('stocktype'):
if cd['itemsize'].unit != cd['stocktype'].unit:
self.add_error('itemsize', 'Item size is not valid for '
'the selected stock type')


@tillweb_view
Expand Down

0 comments on commit 1ea9017

Please sign in to comment.