Updated voucher save/update to catch more exceptions.
Updated ValidatinException to return message on str().
This commit is contained in:
parent
6bbf79a1db
commit
fa809b4225
@ -5,4 +5,6 @@ class ValidationError(Exception):
|
||||
Exception.__init__(self, message)
|
||||
|
||||
# Now for your custom code...
|
||||
self.Errors = Errors
|
||||
self.Errors = Errors
|
||||
def __str__(self):
|
||||
return self.message
|
@ -28,6 +28,8 @@ def purchase_create_inventory(voucher, item, date):
|
||||
if 'Product' not in item or 'ProductID' not in item['Product']:
|
||||
raise ValidationError('No Product in item')
|
||||
product = Product.by_id(uuid.UUID(item['Product']['ProductID']))
|
||||
if product is None:
|
||||
raise ValidationError('No Product in item')
|
||||
inventory_id = uuid.UUID(item['InventoryID']) if 'InventoryID' in item else None
|
||||
quantity = round(Decimal(item['Quantity']), 2)
|
||||
rate = round(Decimal(item['Rate']), 2)
|
||||
|
@ -69,8 +69,8 @@ class save_voucher(object):
|
||||
transaction.commit()
|
||||
session_current_date_set(self.request,self.json['Date'])
|
||||
return voucher_info(Voucher.by_id(voucher.id))
|
||||
except ValidationError as ex:
|
||||
except (ValidationError, ValueError, KeyError) as ex:
|
||||
transaction.abort()
|
||||
response = Response("Failed validation: {0}".format(ex.message))
|
||||
response = Response("Failed validation: {0}".format(str(ex)))
|
||||
response.status_int = 500
|
||||
return response
|
||||
|
@ -86,8 +86,8 @@ class update_voucher(object):
|
||||
transaction.commit()
|
||||
session_current_date_set(self.request,self.json['Date'])
|
||||
return voucher_info(Voucher.by_id(voucher.id))
|
||||
except ValidationError as ex:
|
||||
except (ValidationError, ValueError, KeyError) as ex:
|
||||
transaction.abort()
|
||||
response = Response("Failed validation: {0}".format(ex.message))
|
||||
response = Response("Failed validation: {0}".format(str(ex)))
|
||||
response.status_int = 500
|
||||
return response
|
||||
|
Loading…
x
Reference in New Issue
Block a user