Fixed errors where matchdict.get[] was used.

Checking in delete product while updating purchase changed to proper checking instead of just full value.
This commit is contained in:
Tanshu 2013-02-09 18:52:05 +05:30
parent 89f2457749
commit 0f29356f0d
5 changed files with 10 additions and 7 deletions

View File

@ -17,7 +17,7 @@ def html(request):
@view_config(request_method='POST', route_name='api_client_id', renderer='json', permission='Clients')
@TryCatchFunction
def update(request):
item = Client.by_id(uuid.UUID(request.matchdict.get['id']))
item = Client.by_id(uuid.UUID(request.matchdict['id']))
item.enabled = request.json_body['Enabled']
transaction.commit()
return {}

View File

@ -30,7 +30,7 @@ def save(request):
@view_config(request_method='POST', route_name='api_cost_center_id', renderer='json', permission='Cost Centers')
@TryCatchFunction
def update(request):
item = CostCenter.by_id(uuid.UUID(request.matchdict.get['id']))
item = CostCenter.by_id(uuid.UUID(request.matchdict['id']))
item.name = request.json_body['Name']
transaction.commit()
return cost_center_info(item.id)

View File

@ -6,7 +6,7 @@ from pyramid.view import view_config
import transaction
from brewman.models.master import Product, CostCenter, LedgerType, Ledger
from brewman.models.validation_exception import ValidationError, TryCatchFunction
from brewman.models.validation_exception import TryCatchFunction
@view_config(route_name='product_list', renderer='brewman:templates/angular_base.mako', permission='Authenticated')
@view_config(request_method='GET', route_name='product_id', renderer='brewman:templates/angular_base.mako',
@ -32,7 +32,7 @@ def save(request):
@view_config(request_method='POST', route_name='api_product_id', renderer='json', permission='Products')
@TryCatchFunction
def update(request):
item = Product.by_id(uuid.UUID(request.matchdict.get['id']))
item = Product.by_id(uuid.UUID(request.matchdict['id']))
item.name = request.json_body['Name']
item.units = request.json_body['Units']
item.fraction = Decimal(request.json_body['Fraction'])

View File

@ -31,7 +31,7 @@ def save(request):
@view_config(request_method='POST', route_name='api_product_group_id', renderer='json', permission='Product Groups')
@TryCatchFunction
def update(request):
item = ProductGroup.by_id(uuid.UUID(request.matchdict.get['id']))
item = ProductGroup.by_id(uuid.UUID(request.matchdict['id']))
item.name = request.json_body['Name']
transaction.commit()
return product_group_info(item.id)

View File

@ -1,6 +1,7 @@
import datetime
from decimal import Decimal
import uuid
from sqlalchemy import func
from brewman.models import DBSession
from brewman.models.master import Product, LedgerBase
from brewman.models.operations import journals_valid, inventory_valid
@ -113,8 +114,10 @@ def purchase_update_inventory(voucher, newInventories, date):
#TODO: Update all references of the batch with the new rates
break
if not found:
#TODO: Check to see if the batch is issued not just quantity remaining is full
if item.quantity != item.batch.quantity_remaining:
uses = DBSession.query(func.count(Inventory.id)) \
.filter(Inventory.batch_id == item.batch.id) \
.filter(Inventory.id != item.id).scalar()
if uses > 0:
raise ValidationError("{0} has been issued, it cannot be deleted".format(item.product.name))
else:
DBSession.delete(item.batch)