Fix: Product Yield needs to be > 0 and <= 1

This commit is contained in:
Amritanshu 2014-04-30 13:12:29 +05:30
parent 0436a5de2c
commit a5ec16b644
3 changed files with 8 additions and 10 deletions

View File

@ -15,7 +15,7 @@
<th class="text-right">Code</th> <th class="text-right">Code</th>
<th>Name</th> <th>Name</th>
<th class="text-right">Price</th> <th class="text-right">Price</th>
<th ng-if="show_extended">Yield</th> <th ng-if="show_extended" class="text-right">Yield</th>
<th>Type</th> <th>Type</th>
<th>Is Active?</th> <th>Is Active?</th>
</tr> </tr>
@ -25,7 +25,7 @@
<td class="text-right">{{item.Code}}</td> <td class="text-right">{{item.Code}}</td>
<td><a href="{{item.Url}}">{{item.Name}} ({{show_extended ? item.Fraction + ' ' + item.FractionUnits + ' = 1 ' : ''}}{{item.Units}})</a></td> <td><a href="{{item.Url}}">{{item.Name}} ({{show_extended ? item.Fraction + ' ' + item.FractionUnits + ' = 1 ' : ''}}{{item.Units}})</a></td>
<td class="text-right">{{item.Price | currency}}</td> <td class="text-right">{{item.Price | currency}}</td>
<td ng-if="show_extended">{{item.ProductYield * 100 | number:2}}%</td> <td ng-if="show_extended" class="text-right">{{item.ProductYield * 100 | number:2}}%</td>
<td>{{item.ProductGroup}}</td> <td>{{item.ProductGroup}}</td>
<td>{{item.IsActive}}</td> <td>{{item.IsActive}}</td>
</tr> </tr>

View File

@ -47,10 +47,10 @@ def save(request):
try: try:
product_yield = Decimal(json.get('ProductYield', 1)) product_yield = Decimal(json.get('ProductYield', 1))
if product_yield < 0 or product_yield > 1: if product_yield <= 0 or product_yield > 1:
raise ValidationError("Yield must be a decimal >= 0 <= 1") raise ValidationError("Yield must be a decimal > 0 <= 1")
except (ValueError, InvalidOperation): except (ValueError, InvalidOperation):
raise ValidationError("Yield must be a decimal >= 0 <= 1") raise ValidationError("Yield must be a decimal > 0 <= 1")
product_group = json.get('ProductGroup', None) product_group = json.get('ProductGroup', None)
if product_group is None: if product_group is None:
@ -87,10 +87,10 @@ def update(request):
try: try:
item.product_yield = Decimal(request.json_body['ProductYield']) item.product_yield = Decimal(request.json_body['ProductYield'])
if item.product_yield < 0 or item.product_yield > 1: if item.product_yield <= 0 or item.product_yield > 1:
raise ValidationError("Yield must be a decimal >= 0 <= 1") raise ValidationError("Yield must be a decimal > 0 <= 1")
except (ValueError, InvalidOperation): except (ValueError, InvalidOperation):
raise ValidationError("Yield must be a decimal >= 0 <= 1") raise ValidationError("Yield must be a decimal > 0 <= 1")
item.product_group_id = uuid.UUID(request.json_body['ProductGroup']['ProductGroupID']) item.product_group_id = uuid.UUID(request.json_body['ProductGroup']['ProductGroupID'])
item.ledger_id = Ledger.all_purchases() item.ledger_id = Ledger.all_purchases()

View File

@ -6,8 +6,6 @@ pyramid.debug_authorization = false
pyramid.debug_notfound = false pyramid.debug_notfound = false
pyramid.debug_routematch = false pyramid.debug_routematch = false
pyramid.default_locale_name = en pyramid.default_locale_name = en
# pyramid.includes =
# pyramid_debugtoolbar
# sqlalchemy.url = postgresql://hops:123456@localhost:8765/hops # sqlalchemy.url = postgresql://hops:123456@localhost:8765/hops
sqlalchemy.url = postgresql://postgres:123456@localhost:5432/hops sqlalchemy.url = postgresql://postgres:123456@localhost:5432/hops