From 8bb1579c1b0dbb2b11062235c77dfd91268062d5 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Sun, 6 Oct 2013 13:09:10 +0530 Subject: [PATCH] Fix: Issue form had stopped working Feature: Employee-list search saves query string on navigation. --- brewman/brewman/static/scripts/employee.js | 16 +++++++++++++-- brewman/brewman/static/scripts/overlord.js | 2 +- .../views/services/voucher/__init__.py | 20 +++++++++---------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/brewman/brewman/static/scripts/employee.js b/brewman/brewman/static/scripts/employee.js index 77cca0c2..65e6ec1d 100644 --- a/brewman/brewman/static/scripts/employee.js +++ b/brewman/brewman/static/scripts/employee.js @@ -1,6 +1,7 @@ 'use strict'; -var EmployeeListCtrl = ['$scope', 'employees', function ($scope, employees) { +var EmployeeListCtrl = ['$scope', '$location', '$routeParams', 'employees', function ($scope, $location, $routeParams, employees) { + $scope.search = $routeParams.q || ''; $scope.info = employees; var re = /((([^ ]+):\s*('[^':]+'|"[^":]+"|[^ ]+))|[^ ]+[^: '"]*)/g; @@ -11,7 +12,18 @@ var EmployeeListCtrl = ['$scope', 'employees', function ($scope, employees) { }); }; - $scope.getEmployees = _.memoize(function (q) { + $scope.getEmployees = function (q) { + if (q !== $scope._search) { + $scope._search = q; + if (angular.isUndefined(q) || q === '') { + $location.path('/Employees').search('q', null).replace(); + } else { + $location.path('/Employees').search({'q': q}).replace(); + } + } + return $scope.doFilter(q); + }; + $scope.doFilter = _.memoize(function (q) { var matches = [], i, len; if (angular.isUndefined(q) || q === '') { return $scope.info; diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index 4d0f9157..a30249c4 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -69,7 +69,7 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte when('/Account', {templateUrl: '/partial/account-detail.html', controller: AccountCtrl, resolve: AccountCtrl.resolve}). when('/Account/:id', {templateUrl: '/partial/account-detail.html', controller: AccountCtrl, resolve: AccountCtrl.resolve}). - when('/Employees', {templateUrl: '/partial/employee-list.html', controller: EmployeeListCtrl, resolve: EmployeeListCtrl.resolve}). + when('/Employees', {templateUrl: '/partial/employee-list.html', controller: EmployeeListCtrl, resolve: EmployeeListCtrl.resolve, reloadOnSearch:false}). when('/Employee', {templateUrl: '/partial/employee-detail.html', controller: EmployeeCtrl, resolve: EmployeeCtrl.resolve}). when('/Employee/:id', {templateUrl: '/partial/employee-detail.html', controller: EmployeeCtrl, resolve: EmployeeCtrl.resolve}). diff --git a/brewman/brewman/views/services/voucher/__init__.py b/brewman/brewman/views/services/voucher/__init__.py index 2d353c15..fddfd17b 100644 --- a/brewman/brewman/views/services/voucher/__init__.py +++ b/brewman/brewman/views/services/voucher/__init__.py @@ -219,16 +219,7 @@ def blank_voucher(info): elif type == 'Purchase Return': json_voucher['Journals'].append({'Ledger': LedgerBase.local_purchase(), 'Amount': 0, 'Debit': 1}) elif type == 'Issue': - if info is None: - json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()}, - 'Amount': 0, - 'Debit': -1, - 'CostCenter': {'CostCenterID': CostCenter.cost_center_purchase()}}) - json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()}, - 'Amount': 0, - 'Debit': 1, - 'CostCenter': {'CostCenterID': CostCenter.cost_center_kitchen()}}) - elif 'Source' in info and 'Destination' in info: + if 'Source' in info and 'Destination' in info: json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()}, 'Amount': 0, 'Debit': -1, @@ -237,6 +228,15 @@ def blank_voucher(info): 'Amount': 0, 'Debit': 1, 'CostCenter': {'CostCenterID': info['Destination']}}) + elif 'Journals' not in info: + json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()}, + 'Amount': 0, + 'Debit': -1, + 'CostCenter': {'CostCenterID': CostCenter.cost_center_purchase()}}) + json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()}, + 'Amount': 0, + 'Debit': 1, + 'CostCenter': {'CostCenterID': CostCenter.cost_center_kitchen()}}) else: json_voucher['Date'] = info['Date'] for item in info['Journals']: