From 0be9ce91d9169e23f279dd950bd333cbb9ce785b Mon Sep 17 00:00:00 2001
From: Tanshu
Date: Thu, 11 Oct 2012 23:31:04 +0530
Subject: [PATCH] Added route for user management Removed route for user groups
and related views / templates User management created. Updated journal to
full angular with routes Added User service in angular Added Journal Route.
Changed auth in BaseCtrl to use Permission service and do away with function.
---
brewman/brewman/__init__.py | 8 +-
brewman/brewman/models/auth.py | 1 +
brewman/brewman/static/partial/journal.html | 89 +++++++++++++++
.../brewman/static/partial/user-detail.html | 49 ++++++++
brewman/brewman/static/partial/user-list.html | 21 ++++
.../brewman/static/scripts/angular_service.js | 8 ++
.../brewman/static/scripts/autocomplete.js | 15 +--
brewman/brewman/static/scripts/journal.js | 21 +++-
brewman/brewman/static/scripts/user.js | 25 +++++
brewman/brewman/templates/angular_base.mako | 4 +
brewman/brewman/templates/auth/user_groups.pt | 57 ----------
brewman/brewman/templates/base.mako | 2 +
brewman/brewman/templates/nav_bar/login.pt | 10 +-
.../brewman/templates/transaction/issue.mako | 6 +-
.../templates/transaction/journal.mako | 106 ------------------
.../templates/transaction/payment.mako | 8 +-
.../templates/transaction/purchase.mako | 8 +-
.../templates/transaction/receipt.mako | 8 +-
brewman/brewman/views/auth/user.py | 97 ++++++++++++++++
brewman/brewman/views/auth/user_groups.py | 75 -------------
brewman/brewman/views/services/session.py | 10 +-
.../views/services/voucher/__init__.py | 26 ++---
brewman/brewman/views/transactions/journal.py | 16 +--
23 files changed, 364 insertions(+), 306 deletions(-)
create mode 100644 brewman/brewman/static/partial/journal.html
create mode 100644 brewman/brewman/static/partial/user-detail.html
create mode 100644 brewman/brewman/static/partial/user-list.html
create mode 100644 brewman/brewman/static/scripts/user.js
delete mode 100644 brewman/brewman/templates/auth/user_groups.pt
delete mode 100644 brewman/brewman/templates/transaction/journal.mako
create mode 100644 brewman/brewman/views/auth/user.py
delete mode 100644 brewman/brewman/views/auth/user_groups.py
diff --git a/brewman/brewman/__init__.py b/brewman/brewman/__init__.py
index fd936d63..8911c3a1 100644
--- a/brewman/brewman/__init__.py
+++ b/brewman/brewman/__init__.py
@@ -61,6 +61,10 @@ def main(global_config, **settings):
config.add_route('account', '/Account')
config.add_route('account_list', '/Accounts')
+ config.add_route('user_id', '/User/{id}')
+ config.add_route('user', '/User')
+ config.add_route('user_list', '/Users')
+
config.add_route('product_id', '/Product/{id}')
config.add_route('product', '/Product')
config.add_route('product_list', '/Products')
@@ -109,10 +113,6 @@ def main(global_config, **settings):
config.add_route('profit_loss', '/Reports/ProfitLoss')
config.add_route('trial_balance', '/Reports/TrialBalance')
- config.add_route('user_groups_id', '/Admin/UserGroups/{id}')
- config.add_route('user_groups', '/Admin/UserGroups')
- config.add_route('save_user_groups', '/Admin/UserGroupsSave')
-
config.add_route('group_roles_id', '/Admin/GroupRoles/{id}')
config.add_route('group_roles', '/Admin/GroupRoles')
config.add_route('save_group_roles', '/Admin/GroupRolesSave')
diff --git a/brewman/brewman/models/auth.py b/brewman/brewman/models/auth.py
index ff85a584..bcccdde2 100644
--- a/brewman/brewman/models/auth.py
+++ b/brewman/brewman/models/auth.py
@@ -73,6 +73,7 @@ class User(Base):
self.name = name
if self.password != password:
self.password = encrypt(password)
+ self.locked_out = locked_out
@classmethod
def get_by_name(cls, name):
diff --git a/brewman/brewman/static/partial/journal.html b/brewman/brewman/static/partial/journal.html
new file mode 100644
index 00000000..4f471d12
--- /dev/null
+++ b/brewman/brewman/static/partial/journal.html
@@ -0,0 +1,89 @@
+
diff --git a/brewman/brewman/static/partial/user-detail.html b/brewman/brewman/static/partial/user-detail.html
new file mode 100644
index 00000000..2fd06dce
--- /dev/null
+++ b/brewman/brewman/static/partial/user-detail.html
@@ -0,0 +1,49 @@
+
+ User Detail
+
+
+
+
+
+
+
+
+
diff --git a/brewman/brewman/static/partial/user-list.html b/brewman/brewman/static/partial/user-list.html
new file mode 100644
index 00000000..955e8ba2
--- /dev/null
+++ b/brewman/brewman/static/partial/user-list.html
@@ -0,0 +1,21 @@
+Accounts
+
+
+
+ Name
+ Locked Out
+ Groups
+
+
+
+
+ {{item.Name}}
+ {{item.LockedOut}}
+
+
+
+
+
+
diff --git a/brewman/brewman/static/scripts/angular_service.js b/brewman/brewman/static/scripts/angular_service.js
index 84aaf022..1db9e564 100644
--- a/brewman/brewman/static/scripts/angular_service.js
+++ b/brewman/brewman/static/scripts/angular_service.js
@@ -108,3 +108,11 @@ overlord_service.factory('AccountType', ['$resource', function ($resource) {
return $resource('/AccountTypes');
}]);
+// TODO: Replace hardcoded url with route_url
+overlord_service.factory('User', ['$resource', function ($resource) {
+ return $resource('/User/:id',
+ {id:'@UserID'}, {
+ query:{method:'GET', params:{list:true}, isArray:true}
+ });
+}]);
+
diff --git a/brewman/brewman/static/scripts/autocomplete.js b/brewman/brewman/static/scripts/autocomplete.js
index 3b715de4..f62db7b8 100644
--- a/brewman/brewman/static/scripts/autocomplete.js
+++ b/brewman/brewman/static/scripts/autocomplete.js
@@ -1,8 +1,14 @@
var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filter', 'overlord.service']).
config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
+ when('/Journal', {templateUrl: '/partial/journal.html', controller: JournalCtrl}).
+ when('/Journal/:id', {templateUrl: '/partial/journal.html', controller: JournalCtrl}).
+
when('/Accounts', {templateUrl: '/partial/account-list.html', controller: AccountListCtrl}).
- when('/Account/:id', {templateUrl: '/partial/account-detail.html', controller: AccountCtrl});
+ when('/Account/:id', {templateUrl: '/partial/account-detail.html', controller: AccountCtrl}).
+
+ when('/Users', {templateUrl: '/partial/user-list.html', controller: UserListCtrl}).
+ when('/User/:id', {templateUrl: '/partial/user-detail.html', controller: UserCtrl});
// .otherwise({redirectTo: '/phones'});
$locationProvider.html5Mode(true);
}]);
@@ -32,12 +38,7 @@ function AutoComplete(matchFieldName, lookupURL) {
function BaseCtrl($scope, Permission) {
- $scope.auth = {
- perms:Permission.query(),
- isUserInRole:function (role) {
- return $scope.auth.perms.indexOf(role) !== -1;
- }
- };
+ $scope.perms = Permission.get();
$scope.toasts = [];
$scope.clearToast = function(item) {
diff --git a/brewman/brewman/static/scripts/journal.js b/brewman/brewman/static/scripts/journal.js
index 4d6df122..7b7f0666 100644
--- a/brewman/brewman/static/scripts/journal.js
+++ b/brewman/brewman/static/scripts/journal.js
@@ -1,5 +1,13 @@
-function JournalCtrl($scope, Voucher) {
- $scope.voucher = new Voucher(voucher);
+function JournalCtrl($scope, $routeParams, $location, Voucher) {
+ console.log('loading')
+
+ if (typeof $routeParams.id === 'undefined'){
+ $scope.voucher = Voucher.get({type:'Journal'});
+ } else {
+ console.log('getting voucher' + $routeParams.id)
+ $scope.voucher = Voucher.get({id:$routeParams.id});
+ }
+
$scope.name = '';
$scope.debit = 1;
$scope.addJournal = function () {
@@ -32,8 +40,10 @@
$scope.$watch('voucher.Journals', function (journals, oldValue) {
var amount = 0;
- for (var i = 0, l = journals.length; i < l; i++) {
- amount += (journals[i].Amount * journals[i].Debit);
+ if (typeof journals !== 'undefined') {
+ for (var i = 0, l = journals.length; i < l; i++) {
+ amount += (journals[i].Amount * journals[i].Debit);
+ }
}
$scope.amount = Math.abs(amount);
}, true);
@@ -49,6 +59,7 @@
$scope.save = function () {
$scope.voucher.$save(function (u, putResponseHeaders) {
$scope.toasts.push({Type:'Success', Message:u.Code});
+ $location.path('/Journal/' + u.VoucherID)
}, function (data, status) {
$scope.toasts.push({Type:'Error', Message:data.data});
});
@@ -57,6 +68,8 @@
$scope.delete = function () {
$scope.voucher.$delete(function (u, putResponseHeaders) {
$scope.toasts.push({Type:'Success', Message:''});
+ $location.path('/Journal')
+
}, function (data, status) {
$scope.toasts.push({Type:'Error', Message:data.data});
});
diff --git a/brewman/brewman/static/scripts/user.js b/brewman/brewman/static/scripts/user.js
new file mode 100644
index 00000000..6a531152
--- /dev/null
+++ b/brewman/brewman/static/scripts/user.js
@@ -0,0 +1,25 @@
+function UserListCtrl($scope, User) {
+ $scope.info = User.query();
+}
+
+function UserCtrl($scope, $routeParams, User) {
+ $scope.user = User.get({id: $routeParams.id});
+
+ $scope.save = function () {
+ $scope.user.$save(function (u, putResponseHeaders) {
+ $scope.toasts.push({Type:'Success', Message:u.Code});
+ }, function (data, status) {
+ $scope.toasts.push({Type:'Error', Message:data.data});
+ });
+ };
+
+ $scope.delete = function () {
+ $scope.user.$delete(function (u, putResponseHeaders) {
+ $scope.toasts.push({Type:'Success', Message:''});
+ }, function (data, status) {
+ $scope.toasts.push({Type:'Error', Message:data.data});
+ });
+ };
+ $('#txtName').focus();
+
+}
diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako
index f44aa5ee..ebfcffe3 100644
--- a/brewman/brewman/templates/angular_base.mako
+++ b/brewman/brewman/templates/angular_base.mako
@@ -36,7 +36,11 @@
${h.ScriptLink(request, 'angular_filter.js')}
${h.ScriptLink(request, 'angular_service.js')}
${h.ScriptLink(request, 'session.js')}
+
+ ${h.ScriptLink(request, 'journal.js')}
+
${h.ScriptLink(request, 'account.js')}
+ ${h.ScriptLink(request, 'user.js')}
diff --git a/brewman/brewman/templates/auth/user_groups.pt b/brewman/brewman/templates/auth/user_groups.pt
deleted file mode 100644
index 7a1e776a..00000000
--- a/brewman/brewman/templates/auth/user_groups.pt
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
- ${h.JsLink(request, 'voucher.js')}
- ${h.JsLink(request, 'user_groups.js')}
-
-
-
-
-
- ${h.CsrfToken(request.session)}
-
- ${user}
-
-
-
-
-
- ${h.SubmitButton('btnSave', 'Save', 'save')}
-
- ${h.EndForm()}
-
-
-
-
\ No newline at end of file
diff --git a/brewman/brewman/templates/base.mako b/brewman/brewman/templates/base.mako
index 009f6de6..c1563aa9 100644
--- a/brewman/brewman/templates/base.mako
+++ b/brewman/brewman/templates/base.mako
@@ -35,6 +35,8 @@
${h.ScriptLink(request, 'angular_filter.js')}
${h.ScriptLink(request, 'angular_service.js')}
${h.ScriptLink(request, 'session.js')}
+ ${h.ScriptLink(request, 'account.js')}
+ ${h.ScriptLink(request, 'user.js')}
<%block name="header" />
diff --git a/brewman/brewman/templates/nav_bar/login.pt b/brewman/brewman/templates/nav_bar/login.pt
index 31648a1b..bbbf29c7 100644
--- a/brewman/brewman/templates/nav_bar/login.pt
+++ b/brewman/brewman/templates/nav_bar/login.pt
@@ -3,10 +3,8 @@
@@ -15,10 +13,8 @@
User
@@ -28,7 +24,6 @@
Logout ${user.name}
Change Password
- User Groups
Group Roles
Add User
Disable User
@@ -39,7 +34,6 @@
Home
Log in
- User Groups
Group Roles
Add User
Disable User
diff --git a/brewman/brewman/templates/transaction/issue.mako b/brewman/brewman/templates/transaction/issue.mako
index 1d2b8d53..2890e923 100644
--- a/brewman/brewman/templates/transaction/issue.mako
+++ b/brewman/brewman/templates/transaction/issue.mako
@@ -135,17 +135,17 @@
Save
+ ng-disabled="!perms['Issue Create']">Save
+ ng-disabled="!perms['Issue Update']">
Update
New Entry
+ ng-disabled="!perms['Issue Delete']">
Delete
diff --git a/brewman/brewman/templates/transaction/journal.mako b/brewman/brewman/templates/transaction/journal.mako
deleted file mode 100644
index f53dbed3..00000000
--- a/brewman/brewman/templates/transaction/journal.mako
+++ /dev/null
@@ -1,106 +0,0 @@
-# -*- coding: utf-8 -*-
-<%inherit file="../base.mako"/>
-<%block name="header">
-
- ${h.ScriptLink(request, 'journal.js')}
-
-%block>
-<%block name="content">
-
- ${h.CsrfToken(request.session)}
-
-
-
-
Add
-
-
-
- Dr
- Cr
-
-
-
- ₹
-
-
Add
-
-
-
-
-
-
-
-
-
- Debit
- Name
- Amount
- Delete
-
-
-
-
- {{journal.Debit | debit}}
- {{journal.Ledger.Name}}
- {{journal.Amount}}
-
- Delete
-
-
-
-
-
-
-
-
-
-
- Save
-
-
- Update
-
- {{voucher.Posted | posted}}
-
-
- Delete
-
-
-
- Created on {{voucher.CreationDate}} and Last Edited on {{voucher.LastEditDate}} by {{voucher.User}}. Posted
- by {{voucher.Poster}}
-
-
-%block>
\ No newline at end of file
diff --git a/brewman/brewman/templates/transaction/payment.mako b/brewman/brewman/templates/transaction/payment.mako
index 10e5f55d..9edd77d1 100644
--- a/brewman/brewman/templates/transaction/payment.mako
+++ b/brewman/brewman/templates/transaction/payment.mako
@@ -92,17 +92,17 @@
Save
+ ng-disabled="!perms['Payment Create']">Save
+ ng-disabled="!perms['Payment Update'] || (voucher.Posted && !perms['EditPosted'])">
Update
{{voucher.Posted | posted}}
+ ng-disabled="voucher.Posted || !perms['PostTransactions']">{{voucher.Posted | posted}}
+ ng-disabled="!perms['Payment Delete'] || (voucher.Posted && !perms['EditPosted'])">
Delete
diff --git a/brewman/brewman/templates/transaction/purchase.mako b/brewman/brewman/templates/transaction/purchase.mako
index 522a55a2..4041d2c9 100644
--- a/brewman/brewman/templates/transaction/purchase.mako
+++ b/brewman/brewman/templates/transaction/purchase.mako
@@ -107,18 +107,18 @@
Save
+ ng-disabled="!perms['Purchase Create']">Save
+ ng-disabled="!perms['Purchase Update'] || (voucher.Posted && !perms['EditPosted'])">
Update
{{voucher.Posted |
+ ng-disabled="voucher.Posted || !perms['PostTransactions']">{{voucher.Posted |
posted}}
+ ng-disabled="!perms['Purchase Delete'] || (voucher.Posted && !perms['EditPosted'])">
Delete
diff --git a/brewman/brewman/templates/transaction/receipt.mako b/brewman/brewman/templates/transaction/receipt.mako
index 1a6d2a13..119e18d3 100644
--- a/brewman/brewman/templates/transaction/receipt.mako
+++ b/brewman/brewman/templates/transaction/receipt.mako
@@ -95,17 +95,17 @@
Save
+ ng-disabled="!perms['Receipt Create']">Save
+ ng-disabled="!perms['Receipt Update'] || (voucher.Posted && !perms['EditPosted'])">
Update
{{voucher.Posted | posted}}
+ ng-disabled="voucher.Posted || !perms['PostTransactions']">{{voucher.Posted | posted}}
+ ng-disabled="!perms['Receipt Delete'] || (voucher.Posted && !perms['EditPosted'])">
Delete
diff --git a/brewman/brewman/views/auth/user.py b/brewman/brewman/views/auth/user.py
new file mode 100644
index 00000000..e6750c3e
--- /dev/null
+++ b/brewman/brewman/views/auth/user.py
@@ -0,0 +1,97 @@
+import uuid
+from pyramid.response import Response
+
+from pyramid.view import view_config
+import transaction
+from brewman.models import DBSession
+from brewman.models.auth import User, Group
+
+from brewman.models.validation_exception import ValidationError
+
+@view_config(route_name='user_list', renderer='brewman:templates/angular_base.mako', permission='ManageRoles')
+@view_config(request_method='GET', route_name='user_id', renderer='brewman:templates/angular_base.mako',
+ xhr=False, permission='ManageRoles')
+@view_config(request_method='GET', route_name='user', renderer='brewman:templates/angular_base.mako',
+ xhr=False, permission='ManageRoles')
+def html(request):
+ return {}
+
+
+@view_config(request_method='POST', route_name='user_id', renderer='json', xhr=True, permission='CreateUser')
+@view_config(request_method='POST', route_name='user', renderer='json', xhr=True, permission='CreateUser')
+def save_update(request):
+ try:
+ id = request.matchdict.get('id', None)
+ if id is None:
+ user = User(request.json_body['Name'], request.json_body['Password'], request.json_body['LockedOut'])
+ DBSession.add(user)
+ else:
+ user = User.get_by_id(uuid.UUID(id))
+ user.name = request.json_body['Name']
+ user.locked_out = request.json_body['LockedOut']
+ if request.json_body['Password'] != '' and request.json_body['Password'] != user.password:
+ user.password = request.json_body['Password']
+ for group in request.json_body['Groups']:
+ print(group)
+ id = uuid.UUID(group['GroupID'])
+ ug = [g for g in user.groups if g.id == id]
+ ug = None if len(ug) == 0 else ug[0]
+ if group['Enabled'] and ug is None:
+ user.groups.append(Group.get_by_id(id))
+ elif not group['Enabled'] and ug:
+ user.groups.remove(ug)
+ transaction.commit()
+ return user_info(user.id)
+ except ValidationError as ex:
+ transaction.abort()
+ response = Response("Failed validation: {0}".format(ex.message))
+ response.status_int = 500
+ return response
+
+
+@view_config(request_method='DELETE', route_name='user_id', renderer='json', xhr=True, permission='CreateUser')
+def delete(request):
+ id = request.matchdict.get('id', None)
+ if id is None:
+ response = Response("User is Null")
+ response.status_int = 500
+ return response
+ else:
+ response = Response("User deletion not implemented")
+ response.status_int = 500
+ return response
+
+
+@view_config(request_method='GET', route_name='user_id', renderer='json', xhr=True, permission='ManageRoles')
+@view_config(request_method='GET', route_name='user', renderer='json', xhr=True, permission='ManageRoles')
+def show(request):
+ list = request.GET.get('list', None)
+
+ if list:
+ list = User.list()
+ users = []
+ for item in list:
+ user = {'Name': item.name, 'LockedOut': item.locked_out,
+ 'Groups': [], 'Url': request.route_url('user_id', id=item.id)}
+ for group in item.groups:
+ user['Groups'].append(group.name)
+ users.append(user)
+ return users
+ else:
+ id = request.matchdict.get('id', None)
+ id = None if id is None else uuid.UUID(id)
+ return user_info(id)
+
+
+def user_info(id):
+ if id is None:
+ return {'Name': '', 'LockedOut': False, 'Groups': []}
+ else:
+ user = User.get_by_id(id)
+ account = {'UserID': user.id, 'Name': user.name, 'Password': '', 'LockedOut': user.locked_out, 'Groups': []}
+ for item in Group.list():
+ account['Groups'].append(
+ {'GroupID': item.id, 'Name': item.name, 'Enabled': True if item in user.groups else False})
+ return account
+
+
diff --git a/brewman/brewman/views/auth/user_groups.py b/brewman/brewman/views/auth/user_groups.py
deleted file mode 100644
index 6812a759..00000000
--- a/brewman/brewman/views/auth/user_groups.py
+++ /dev/null
@@ -1,75 +0,0 @@
-import uuid
-
-from pyramid.view import view_config
-import transaction
-from brewman.helpers import Literal, SelectInput
-from brewman.models.auth import User, Group
-
-@view_config(request_method='GET', route_name='user_groups', permission='ManageRoles',
- renderer='brewman:templates/auth/user_groups.pt')
-@view_config(request_method='GET', route_name='user_groups_id', permission='ManageRoles',
- renderer='brewman:templates/auth/user_groups.pt')
-def user_groups_get(request):
- id = request.matchdict.get('id', None)
- id = None if id is None else uuid.UUID(id)
- user = SelectInput('ddlUser', list=User.list(), displayField='name', valueField='id', defaultValue=id)
- body, footer = build_report(request, id)
- body = Literal(body)
- footer = Literal(footer)
-
- return {'title': 'User Groups',
- 'pageclass': "page-blogpost page-sidebar-right",
- 'pagecontentclass': "page-content grid_12",
- 'page_header': '',
- 'user': user,
- 'body': body,
- 'footer': footer}
-
-
-@view_config(request_method='POST', route_name='user_groups', permission='ManageRoles', renderer='json', xhr=True)
-@view_config(request_method='POST', route_name='user_groups_id', permission='ManageRoles', renderer='json', xhr=True)
-def user_groups_post(request):
- id = request.json_body['user_id']
- body, footer = build_report(request, uuid.UUID(id))
- url = request.route_url('user_groups_id', id=id)
- return {'user_id': id,
- 'url': url,
- 'body': body}
-
-
-@view_config(request_method='POST', route_name='save_user_groups', permission='ManageRoles', renderer='json', xhr=True)
-def user_groups_save(request):
- id = request.json_body['user_id']
- user = User.get_by_id(uuid.UUID(id))
- for item in request.json_body['selected_groups']:
- group = Group.get_by_id(uuid.UUID(item['group_id']))
- selected = item['selected']
- if selected and group not in user.groups:
- user.groups.append(group)
- elif not selected and group in user.groups:
- user.groups.remove(group)
- transaction.commit()
- return 'Groups Updated'
-
-
-def build_report(request, id):
- body = ''
- if id is None:
- for item in Group.list():
- body += '{0} '\
- '{1} '\
- .format(str(item.id), item.name)
- else:
- user = User.get_by_id(id)
- for item in Group.list():
- if item in user.groups:
- checked = ' checked="checked"'
- else:
- checked = ''
- body += '{0} '\
- '{1} '\
- .format(str(item.id), item.name, checked)
- footer = ' '
- return body, footer
-
-
diff --git a/brewman/brewman/views/services/session.py b/brewman/brewman/views/services/session.py
index a0fd9c86..c1ee4adc 100644
--- a/brewman/brewman/views/services/session.py
+++ b/brewman/brewman/views/services/session.py
@@ -2,6 +2,7 @@ from datetime import date, timedelta
import json
from pyramid.view import view_config
+from brewman.models.auth import Role
from brewman.views.transactions import session_current_date
@view_config(route_name='services_session_current_date', renderer='json', xhr=True)
@@ -47,8 +48,13 @@ def is_user_in_roles(request):
@view_config(route_name='user_permissions', renderer='json', xhr=True)
def user_permission(request):
- print(json.dumps(request.session['perms']))
- return request.session['perms']
+ session_perms = request.session['perms']
+ perms = {}
+
+ for item in Role.list():
+ perms[item.name] = True if item.name in session_perms else False
+
+ return perms
def get_first_day(dt, d_years=0, d_months=0):
diff --git a/brewman/brewman/views/services/voucher/__init__.py b/brewman/brewman/views/services/voucher/__init__.py
index 5d9b4454..bf282abf 100644
--- a/brewman/brewman/views/services/voucher/__init__.py
+++ b/brewman/brewman/views/services/voucher/__init__.py
@@ -1,4 +1,3 @@
-import json
import uuid
from pyramid.response import Response
from pyramid.security import authenticated_userid
@@ -9,10 +8,10 @@ from brewman.models.auth import User
from brewman.models.master import LedgerBase, CostCenter
from brewman.models.validation_exception import ValidationError
from brewman.models.voucher import Voucher, VoucherType
-from brewman.views import DecimalEncoder
from brewman.views.services.voucher.issue import issue_create_voucher, issue_update_voucher
from brewman.views.services.voucher.journal import journal_update_voucher, journal_create_voucher
from brewman.views.services.voucher.purchase import purchase_create_voucher, purchase_update_voucher
+from brewman.views.transactions import session_current_date
__author__ = 'tanshu'
@@ -108,17 +107,14 @@ def delete(request):
def get(request):
id = request.matchdict.get('id', None)
voucher_type = request.GET.get('type', None)
- if id is None:
- response = Response("Voucher is Null")
+ if id:
+ return voucher_info(Voucher.by_id(uuid.UUID(id)))
+ elif voucher_type:
+ return blank_voucher(type=voucher_type, date=session_current_date(request))
+ else:
+ response = Response("Voucher ID and Type, both are Null")
response.status_int = 500
return response
- else:
- voucher = voucher_info(Voucher.by_id(uuid.UUID(id)))
- if voucher_type is None:
- return voucher
- else:
-# voucher = json.dumps(voucher, cls=DecimalEncoder)
- return blank_voucher(type=voucher_type, additionalInfo=voucher)
def voucher_info(voucher):
@@ -140,10 +136,10 @@ def voucher_info(voucher):
'CostCenter': {'CostCenterID': item.cost_center_id}})
for item in voucher.inventories:
json_voucher['Inventories'].append(
- {'InventoryID': item.id, 'Quantity': item.quantity, 'Rate': item.rate,
- 'Tax': item.tax, 'Discount': item.discount, 'Amount': item.amount,
- 'Product': {'ProductID': item.product.id, 'Name': item.product.name, 'Units': item.product.units},
- 'Batch': {'BatchID': item.batch.id, 'QuantityRemaining': item.batch.quantity_remaining}})
+ {'InventoryID': item.id, 'Quantity': item.quantity, 'Rate': item.rate,
+ 'Tax': item.tax, 'Discount': item.discount, 'Amount': item.amount,
+ 'Product': {'ProductID': item.product.id, 'Name': item.product.name, 'Units': item.product.units},
+ 'Batch': {'BatchID': item.batch.id, 'QuantityRemaining': item.batch.quantity_remaining}})
return json_voucher
diff --git a/brewman/brewman/views/transactions/journal.py b/brewman/brewman/views/transactions/journal.py
index 2051690f..c364dd6f 100644
--- a/brewman/brewman/views/transactions/journal.py
+++ b/brewman/brewman/views/transactions/journal.py
@@ -10,19 +10,9 @@ from brewman.views import DecimalEncoder
from brewman.views.services.voucher import voucher_info, blank_voucher
from brewman.views.transactions import session_current_date
-@view_config(request_method='GET', route_name='journal_id', renderer='brewman:templates/transaction/journal.mako',
+@view_config(request_method='GET', route_name='journal_id', renderer='brewman:templates/angular_base.mako',
permission='Journal Update')
-@view_config(request_method='GET', route_name='journal', renderer='brewman:templates/transaction/journal.mako',
+@view_config(request_method='GET', route_name='journal', renderer='brewman:templates/angular_base.mako',
permission='Journal Create')
def journal_get(request):
- id = request.matchdict.get('id', None)
- perms = Literal(json.dumps(request.session['perms']))
- if id is None:
- json_voucher = Literal(json.dumps(blank_voucher('Journal', session_current_date(request)), cls=DecimalEncoder))
- else:
- voucher = Voucher.by_id(uuid.UUID(id))
- json_voucher = Literal(json.dumps(voucher_info(voucher), cls=DecimalEncoder))
- return {'title': 'Hops n Grains - Journal Entry',
- 'id': id,
- 'perms': perms,
- 'json_voucher': json_voucher}
\ No newline at end of file
+ return {}
\ No newline at end of file