diff --git a/brewman/brewman/static/offline.appcache b/brewman/brewman/static/offline.appcache
index 3304c41b..cd92621f 100644
--- a/brewman/brewman/static/offline.appcache
+++ b/brewman/brewman/static/offline.appcache
@@ -1,6 +1,6 @@
CACHE MANIFEST
-# version 2013-05-17.1
+# version 2013-05-18.1
CACHE:
/partial/404.html
@@ -8,6 +8,7 @@ CACHE:
/partial/account-list.html
/partial/attendance.html
/partial/cash-flow.html
+/partial/client-detail.html
/partial/client-list.html
/partial/closing-stock.html
/partial/cost-center-detail.html
diff --git a/brewman/brewman/static/partial/client-detail.html b/brewman/brewman/static/partial/client-detail.html
new file mode 100644
index 00000000..4fe09ce5
--- /dev/null
+++ b/brewman/brewman/static/partial/client-detail.html
@@ -0,0 +1,41 @@
+
diff --git a/brewman/brewman/static/partial/client-list.html b/brewman/brewman/static/partial/client-list.html
index ec7717b0..13a054b9 100644
--- a/brewman/brewman/static/partial/client-list.html
+++ b/brewman/brewman/static/partial/client-list.html
@@ -11,7 +11,7 @@
{{item.Code}} |
- {{item.Name}} |
+ {{item.Name}} |
{{item.Enabled}} |
{{item.OTP}} |
diff --git a/brewman/brewman/static/scripts/client.js b/brewman/brewman/static/scripts/client.js
index 99adc672..88b4ec27 100644
--- a/brewman/brewman/static/scripts/client.js
+++ b/brewman/brewman/static/scripts/client.js
@@ -1,10 +1,10 @@
'use strict';
-var ClientCtrl = ['$scope', 'clients', function ($scope, clients) {
+var ClientListCtrl = ['$scope', 'clients', function ($scope, clients) {
$scope.info = clients;
}]
-ClientCtrl.resolve = {
+ClientListCtrl.resolve = {
clients:['$q', 'Client', function ($q, Client) {
var deferred = $q.defer();
@@ -16,3 +16,41 @@ ClientCtrl.resolve = {
return deferred.promise;
}]
};
+
+var ClientCtrl = ['$scope', '$location', 'client', function ($scope, $location, client) {
+ $scope.client = client;
+
+ $scope.save = function () {
+ $scope.client.$save(function (u, putResponseHeaders) {
+ $scope.toasts.push({Type:'Success', Message:''});
+ $location.path('/Clients')
+ }, function (data, status) {
+ $scope.toasts.push({Type:'Error', Message:data.data});
+ });
+ };
+
+ $scope.delete = function () {
+ $scope.client.$delete(function (u, putResponseHeaders) {
+ $scope.toasts.push({Type:'Success', Message:''});
+ $location.path('/Clients')
+ }, function (data, status) {
+ $scope.toasts.push({Type:'Error', Message:data.data});
+ });
+ };
+ $('#txtName').focus();
+
+}]
+
+ClientCtrl.resolve = {
+ client:['$q', '$route', 'Client', function ($q, $route, Client) {
+ var deferred = $q.defer();
+
+ var id = $route.current.params.id;
+ var successCb = function (result) {
+ deferred.resolve(result);
+ };
+
+ Client.get({id: id}, successCb);
+ return deferred.promise;
+ }]
+};
diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js
index 59ca1ae0..8401895f 100644
--- a/brewman/brewman/static/scripts/overlord.js
+++ b/brewman/brewman/static/scripts/overlord.js
@@ -86,7 +86,8 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte
when('/Group', {templateUrl: '/partial/group-detail.html', controller: GroupCtrl, resolve: GroupCtrl.resolve}).
when('/Group/:id', {templateUrl: '/partial/group-detail.html', controller: GroupCtrl, resolve: GroupCtrl.resolve}).
- when('/Clients', {templateUrl: '/partial/client-list.html', controller: ClientCtrl, resolve: ClientCtrl.resolve}).
+ when('/Clients', {templateUrl: '/partial/client-list.html', controller: ClientListCtrl, resolve: ClientListCtrl.resolve}).
+ when('/Client/:id', {templateUrl: '/partial/client-detail.html', controller: ClientCtrl, resolve: ClientCtrl.resolve}).
otherwise({templateUrl: '/partial/404.html'});
$locationProvider.html5Mode(true).hashPrefix('!');
diff --git a/brewman/brewman/views/auth/client.py b/brewman/brewman/views/auth/client.py
index 6b578c69..ed3519ff 100644
--- a/brewman/brewman/views/auth/client.py
+++ b/brewman/brewman/views/auth/client.py
@@ -3,13 +3,14 @@ from pyramid.response import Response
from pyramid.view import view_config
import transaction
+from brewman.models import DBSession
from brewman.models.auth import Client
-from brewman.models.validation_exception import ValidationError, TryCatchFunction
+from brewman.models.validation_exception import TryCatchFunction
@view_config(request_method='GET', route_name='client_list', renderer='brewman:templates/angular_base.mako',
- permission='Clients')
+ permission='Clients')
def html(request):
return {}
@@ -18,16 +19,46 @@ def html(request):
@TryCatchFunction
def update(request):
item = Client.by_id(uuid.UUID(request.matchdict['id']))
- item.enabled = request.json_body['Enabled']
+ if item.otp is None:
+ item.enabled = request.json_body['Enabled']
+ item.name = request.json_body['Name']
transaction.commit()
return {}
+@view_config(request_method='DELETE', route_name='api_client_id', renderer='json', permission='Clients')
+def delete(request):
+ id = request.matchdict.get('id', None)
+ if id is None:
+ response = Response("Client is Null")
+ response.status_int = 500
+ return response
+
+ client = Client.by_id(id)
+ if client.enabled:
+ response = Response("Client is enabled and cannot be deleted")
+ response.status_int = 500
+ return response
+ else:
+ DBSession.delete(client)
+ transaction.commit()
+ return {}
+
+
@view_config(request_method='GET', route_name='api_client', request_param='list', renderer='json', permission='Clients')
def show_list(request):
list = Client.list()
clients = []
for item in list:
clients.append(
- {'ClientID': item.id, 'Code': item.code, 'Name': item.name, 'Enabled': item.enabled, 'OTP': item.otp})
- return clients
\ No newline at end of file
+ {'ClientID': item.id, 'Code': item.code, 'Name': item.name, 'Enabled': item.enabled, 'OTP': item.otp,
+ 'Url': request.route_url('client_id', id=item.id)})
+ return clients
+
+
+@view_config(request_method='GET', route_name='api_client_id', renderer='json', permission='Clients')
+def show_id(request):
+ item = Client.by_id(request.matchdict['id'])
+ return {'ClientID': item.id, 'Code': item.code, 'Name': item.name, 'Enabled': item.enabled, 'OTP': item.otp}
+
+
diff --git a/brewman/brewman/views/services/voucher/purchase_return.py b/brewman/brewman/views/services/voucher/purchase_return.py
index 0a34a1b1..0c1ca5d4 100644
--- a/brewman/brewman/views/services/voucher/purchase_return.py
+++ b/brewman/brewman/views/services/voucher/purchase_return.py
@@ -115,7 +115,7 @@ def purchase_return_update_journals(voucher, journals):
journals[ledger.id].amount += round(item.amount, 2)
else:
journals[ledger.id] = Journal(debit=-1, cost_center_id=ledger.costcenter_id, ledger_id=ledger.id,
- amount=round(item.amount), 2)
+ amount=round(item.amount, 2))
journals[otherLedger.id] = Journal(debit=1, cost_center_id=otherLedger.costcenter_id, ledger_id=otherLedger.id,
amount=amount)
for i in range(len(voucher.journals), 0, -1):
diff --git a/brewman/development.ini b/brewman/development.ini
index ea197ba7..4d73a7ce 100644
--- a/brewman/development.ini
+++ b/brewman/development.ini
@@ -8,6 +8,7 @@ pyramid.debug_routematch = false
pyramid.default_locale_name = en
# pyramid.includes =
# pyramid_debugtoolbar
+# sqlalchemy.url = postgresql://hops:123456@localhost:8765/hops
sqlalchemy.url = sqlite:///%(here)s/database/brewman.db
[server:main]