From 218a1781a86455435218e9e64bc59da10d922588 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Thu, 3 Oct 2013 15:58:16 +0530 Subject: [PATCH] Feature: Discontinued Ledgers / Products will not show up in Vouchers reducing confusion. --- brewman/brewman/models/master.py | 12 ++++++++---- brewman/brewman/static/scripts/journal.js | 6 +++--- brewman/brewman/static/scripts/payment.js | 2 +- brewman/brewman/static/scripts/purchase-return.js | 2 +- brewman/brewman/static/scripts/purchase.js | 6 +++--- brewman/brewman/static/scripts/receipt.js | 7 +++---- brewman/brewman/views/account.py | 11 +++++------ brewman/brewman/views/product.py | 4 +++- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/brewman/brewman/models/master.py b/brewman/brewman/models/master.py index fac9a82a..254b723a 100644 --- a/brewman/brewman/models/master.py +++ b/brewman/brewman/models/master.py @@ -52,8 +52,10 @@ class Product(Base): return "{0} ({1})".format(self.name, self.units) @classmethod - def list(cls, name): + def list(cls, name, active): query = DBSession.query(cls) + if active is not None: + query = query.filter(cls.discontinued != active) for item in name.split(): query = query.filter(cls.name.ilike('%' + item + '%')) return query.order_by(cls.name) @@ -197,14 +199,16 @@ class LedgerBase(Base): return DBSession.query(cls).all() @classmethod - def list(cls, type, name, is_reconcilable): + def list(cls, type, name, reconcilable, active): query = DBSession.query(cls) if type is not None: if not isinstance(type, int): type = int(type) query = query.filter(cls.type == type) - if is_reconcilable is not None: - query = query.filter(cls.is_reconcilable == is_reconcilable) + if reconcilable is not None: + query = query.filter(cls.is_reconcilable == reconcilable) + if active is not None: + query = query.filter(cls.is_active == active) if name is not None: for item in name.split(): query = query.filter(cls.name.ilike('%' + item + '%')) diff --git a/brewman/brewman/static/scripts/journal.js b/brewman/brewman/static/scripts/journal.js index 5cb9f736..b516fc34 100644 --- a/brewman/brewman/static/scripts/journal.js +++ b/brewman/brewman/static/scripts/journal.js @@ -152,12 +152,12 @@ var JournalCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher $scope.accounts = function ($viewValue) { var deferred = $q.defer(); - Account.autocomplete({term: $viewValue, count: 20}, function (result) { + Account.autocomplete({term: $viewValue, count: 20, a:true}, function (result) { deferred.resolve(result); }); return deferred.promise; - } -}] + }; +}]; JournalCtrl.resolve = { voucher: ['$q', '$route', 'Voucher', function ($q, $route, Voucher) { diff --git a/brewman/brewman/static/scripts/payment.js b/brewman/brewman/static/scripts/payment.js index 08f6bebd..e1af7564 100644 --- a/brewman/brewman/static/scripts/payment.js +++ b/brewman/brewman/static/scripts/payment.js @@ -152,7 +152,7 @@ var PaymentCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher $scope.accounts = function ($viewValue) { var deferred = $q.defer(); - Account.autocomplete({term: $viewValue, count: 20}, function (result) { + Account.autocomplete({term: $viewValue, count: 20, a:true}, function (result) { deferred.resolve(result); }); return deferred.promise; diff --git a/brewman/brewman/static/scripts/purchase-return.js b/brewman/brewman/static/scripts/purchase-return.js index 55a9fcd3..93687eca 100644 --- a/brewman/brewman/static/scripts/purchase-return.js +++ b/brewman/brewman/static/scripts/purchase-return.js @@ -159,7 +159,7 @@ var PurchaseReturnCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', ' $scope.accounts = function ($viewValue) { var deferred = $q.defer(); - Account.autocomplete({term: $viewValue, count: 20}, function (result) { + Account.autocomplete({term: $viewValue, count: 20, a:true}, function (result) { deferred.resolve(result); }); return deferred.promise; diff --git a/brewman/brewman/static/scripts/purchase.js b/brewman/brewman/static/scripts/purchase.js index 841c1a80..d0c357e7 100644 --- a/brewman/brewman/static/scripts/purchase.js +++ b/brewman/brewman/static/scripts/purchase.js @@ -164,15 +164,15 @@ var PurchaseCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'vouche $scope.accounts = function ($viewValue) { var deferred = $q.defer(); - Account.autocomplete({term: $viewValue, count: 20}, function (result) { + Account.autocomplete({term: $viewValue, count: 20, a:true}, function (result) { deferred.resolve(result); }); return deferred.promise; - } + }; $scope.products = function ($viewValue) { var deferred = $q.defer(); - Product.autocomplete({term: $viewValue, count: 20}, function (result) { + Product.autocomplete({term: $viewValue, count: 20, a:true}, function (result) { deferred.resolve(result); }); return deferred.promise; diff --git a/brewman/brewman/static/scripts/receipt.js b/brewman/brewman/static/scripts/receipt.js index a0c54199..b6bb2730 100644 --- a/brewman/brewman/static/scripts/receipt.js +++ b/brewman/brewman/static/scripts/receipt.js @@ -152,13 +152,12 @@ var ReceiptCtrl = ['$scope', '$routeParams', '$location', '$q', 'dateFilter', '$ $scope.accounts = function ($viewValue) { var deferred = $q.defer(); - Account.autocomplete({term: $viewValue, count: 20}, function (result) { + Account.autocomplete({term: $viewValue, count: 20, 'a':true}, function (result) { deferred.resolve(result); }); return deferred.promise; - } - -}] + }; +}]; ReceiptCtrl.resolve = { voucher: ['$q', '$route', 'Voucher', function ($q, $route, Voucher) { diff --git a/brewman/brewman/views/account.py b/brewman/brewman/views/account.py index 4f684663..7a0487f9 100644 --- a/brewman/brewman/views/account.py +++ b/brewman/brewman/views/account.py @@ -94,16 +94,15 @@ def show_term(request): type = int(type) if type is not None else None filter = request.GET.get('term', None) filter = filter if filter is not None and filter is not '' else None - is_reconcilable = request.GET.get('r', None) - is_reconcilable = is_reconcilable if is_reconcilable is not None else None + reconcilable = request.GET.get('r', None) + reconcilable = reconcilable if reconcilable is not None else None + active = request.GET.get('a', None) + active = active if active is not None else None count = request.GET.get('count', None) count = None if count is None or count == '' else int(count) - return ledger_list(type, filter, count, is_reconcilable) - -def ledger_list(type=None, filter=None, count=None, is_reconcilable=None): list = [] - for index, item in enumerate(LedgerBase.list(type, filter, is_reconcilable)): + for index, item in enumerate(LedgerBase.list(type, filter, reconcilable, active)): list.append({'LedgerID': item.id, 'Name': item.name}) if count is not None and index == count - 1: break diff --git a/brewman/brewman/views/product.py b/brewman/brewman/views/product.py index 24de4f03..85588443 100644 --- a/brewman/brewman/views/product.py +++ b/brewman/brewman/views/product.py @@ -95,10 +95,12 @@ def show_list(request): def show_term(request): term = request.GET.get('term', None) term = term if term is not None and term is not '' else None + active = request.GET.get('a', None) + active = active if active is not None else None count = request.GET.get('count', None) count = None if count is None or count == '' else int(count) list = [] - for index, item in enumerate(Product.list(term)): + for index, item in enumerate(Product.list(term, active)): list.append({'ProductID': item.id, 'Name': item.full_name, 'Price': item.price}) if count is not None and index == count - 1: break