From 0f29356f0d987cfe26232ba1bce564c9ff49ceb6 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Sat, 9 Feb 2013 18:52:05 +0530 Subject: [PATCH] Fixed errors where matchdict.get[] was used. Checking in delete product while updating purchase changed to proper checking instead of just full value. --- brewman/brewman/views/auth/client.py | 2 +- brewman/brewman/views/cost_center.py | 2 +- brewman/brewman/views/product.py | 4 ++-- brewman/brewman/views/product_group.py | 2 +- brewman/brewman/views/services/voucher/purchase.py | 7 +++++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/brewman/brewman/views/auth/client.py b/brewman/brewman/views/auth/client.py index 00723b68..6b578c69 100644 --- a/brewman/brewman/views/auth/client.py +++ b/brewman/brewman/views/auth/client.py @@ -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 {} diff --git a/brewman/brewman/views/cost_center.py b/brewman/brewman/views/cost_center.py index a6d5aa0c..56d2323f 100644 --- a/brewman/brewman/views/cost_center.py +++ b/brewman/brewman/views/cost_center.py @@ -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) diff --git a/brewman/brewman/views/product.py b/brewman/brewman/views/product.py index ca936c0f..4b22cbd6 100644 --- a/brewman/brewman/views/product.py +++ b/brewman/brewman/views/product.py @@ -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']) diff --git a/brewman/brewman/views/product_group.py b/brewman/brewman/views/product_group.py index c6a16657..46e8adcc 100644 --- a/brewman/brewman/views/product_group.py +++ b/brewman/brewman/views/product_group.py @@ -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) diff --git a/brewman/brewman/views/services/voucher/purchase.py b/brewman/brewman/views/services/voucher/purchase.py index c77670b1..71c14322 100644 --- a/brewman/brewman/views/services/voucher/purchase.py +++ b/brewman/brewman/views/services/voucher/purchase.py @@ -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)