Updated voucher save/update to catch more exceptions.

Updated ValidatinException to return message on str().
This commit is contained in:
Tanshu 2012-12-17 00:09:45 +05:30
parent 6bbf79a1db
commit fa809b4225
4 changed files with 9 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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