diff --git a/Conversion/SqliteDB.txt b/Conversion/SqliteDB.txt index d0198d9c..2fd93715 100644 --- a/Conversion/SqliteDB.txt +++ b/Conversion/SqliteDB.txt @@ -44,3 +44,76 @@ CREATE TABLE [Entities_Products] ( ); INSERT INTO "Entities_Products" SELECT "ProductID", "Code", "Name", "Units", "Fraction", "FractionUnits", "Yeild", "ShowForPurchase", "PurchasePrice", "Discontinued", "ProductGroupID", "PurchaseLedgerID" FROM "Entities_Products_old"; DROP TABLE "Entities_Products_old"; + + +--------------------- +Roles -- Run one line at a time, not all at once + +-- Accounts +UPDATE Auth_Roles SET Name = 'Accounts' WHERE RoleID = X'F438262F72DD2F4E91865ABC3AF44FBA'; +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'7117853BD6A1F44FAA7919195338C857', X'4DC8B2094C33114F9656D91F62999F6B', X'A5174D3F2D5B3B40AA1FD20D1BB292E5', X'457143A70A4E4C4CBB2DA65BF608624E'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'7117853BD6A1F44FAA7919195338C857', X'4DC8B2094C33114F9656D91F62999F6B', X'A5174D3F2D5B3B40AA1FD20D1BB292E5', X'457143A70A4E4C4CBB2DA65BF608624E'); +-- Check for attendance +-- Backdated Vouchers +UPDATE Auth_Roles SET Name = 'Backdated Vouchers' WHERE RoleID = X'B67B20625CA7134F82585D284DD92426'; +-- Check for Cash Flow +-- Closing Stock +UPDATE Auth_Roles SET Name = 'Closing Stock' WHERE RoleID = X'9751573224E4C94D9585D4BD7F6C7891'; +-- Cost Centers +UPDATE Auth_Roles SET Name = 'Cost Centers' WHERE RoleID = X'6FCC1A206AECE840B3341632B34AEAB8'; +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'652E18DBE591764C8F6FC92301BBE550', X'F106324728D8EA41AD3F3BC36A2D6AF8', X'98E29DA602182040B603FD5B2EB0D047', X'14B9761096BB394890898CD14C07EE2E'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'652E18DBE591764C8F6FC92301BBE550', X'F106324728D8EA41AD3F3BC36A2D6AF8', X'98E29DA602182040B603FD5B2EB0D047', X'14B9761096BB394890898CD14C07EE2E'); +-- Daybook +UPDATE Auth_Roles SET Name = 'Daybook' WHERE RoleID = X'C3EDB554A0578942803037B8E926D583'; +-- Edit Other User's Vouchers +UPDATE Auth_Roles SET Name = "Edit Other User's Vouchers" WHERE RoleID = X'A83288917CE2A9438C292EABC1FFEEA3'; +-- Edit Posted Vouchers +UPDATE Auth_Roles SET Name = 'Edit Posted Vouchers' WHERE RoleID = X'D6675817DDF5BF409DE6FA223EB4AAA6'; +-- Employees +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'70143ACE40D913488A120B199DD7F8AC', X'82D53E90D6840C45808BBD5A13C061C3', X'D2C5437D4E32DC4CA6AEAA621A581EFE', X'6C68900DFE11FC468E67F30E120D4418'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'70143ACE40D913488A120B199DD7F8AC', X'82D53E90D6840C45808BBD5A13C061C3', X'D2C5437D4E32DC4CA6AEAA621A581EFE', X'6C68900DFE11FC468E67F30E120D4418'); +-- Fingerprints +UPDATE Auth_Roles SET Name = 'Fingerprints' WHERE RoleID = X'D9C45323F997BA4694078A7145F0828B'; +-- Issue +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'3B1155DBF0440B44ADF34E36285F59FF', X'469E180D83B6E64DB8B399A9AEFB5E67', X'5E767672AFE51D4DBD3F5C57F498BE60', X'35849AACC5E87C428C287C2D134B3289'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'3B1155DBF0440B44ADF34E36285F59FF', X'469E180D83B6E64DB8B399A9AEFB5E67', X'5E767672AFE51D4DBD3F5C57F498BE60', X'35849AACC5E87C428C287C2D134B3289'); +-- Journal +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'3497E69B62BA4A41941446DC05772A39', X'500AC902EDB4CA4E8323DB0B16D6BE8E', X'C75E6DBA274FC74182218361BC7F50E0', X'AF56518AC9BB63489E60A087CC8CECBE'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'3497E69B62BA4A41941446DC05772A39', X'500AC902EDB4CA4E8323DB0B16D6BE8E', X'C75E6DBA274FC74182218361BC7F50E0', X'AF56518AC9BB63489E60A087CC8CECBE'); +-- Ledger +UPDATE Auth_Roles SET Name = 'Ledger' WHERE RoleID = X'A2120944243F3F49BE570AD633CE4801'; +-- Payment +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'0517A2C862F8124BA916E00B70EF4523', X'BF4DC51A98CA8D4BA70CB376814FEF35', X'ED4CA3AFF0FC71458749F765DF6AC9BA', X'E66BD1AD2C60774EA6D1D113F4CB2EFE'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'0517A2C862F8124BA916E00B70EF4523', X'BF4DC51A98CA8D4BA70CB376814FEF35', X'ED4CA3AFF0FC71458749F765DF6AC9BA', X'E66BD1AD2C60774EA6D1D113F4CB2EFE'); +-- Post Vouchers +UPDATE Auth_Roles SET Name = 'Post Vouchers' WHERE RoleID = X'36E741DA1A57B047A59EDCD58FCF4338'; +-- Product Groups +UPDATE Auth_Roles SET Name = 'Product Groups' WHERE RoleID = X'08413A22CF88FD43B2B7365D2951D99F'; +-- Product Ledger +UPDATE Auth_Roles SET Name = 'Product Ledger' WHERE RoleID = X'62612AF1F7ED3347A7483C0884B070F3'; +-- Products +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'62612AF1F7ED3347A7483C0884B070F3', X'42930329038355469C0042FD15BDD280', X'0945BC32E25D244EB3204DFFAFEC945E'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'62612AF1F7ED3347A7483C0884B070F3', X'42930329038355469C0042FD15BDD280', X'0945BC32E25D244EB3204DFFAFEC945E'); +-- Profit & Loss +UPDATE Auth_Roles SET Name = 'Profit & Loss' WHERE RoleID = X'0492EBB376F3204EAB94BBFE880F0691'; +-- Purchase +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'73290D72B106F04B86696A3EA4E3DE4A', X'FEC8D32F048ED241AE781BCCE84B00FC', X'E18D34283E474F499205315C283A9E4F'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'73290D72B106F04B86696A3EA4E3DE4A', X'FEC8D32F048ED241AE781BCCE84B00FC', X'E18D34283E474F499205315C283A9E4F'); +-- Purchase Entries +UPDATE Auth_Roles SET Name = 'Purchase Entries' WHERE RoleID = X'78A6422BAA11174C9DFA412A99E87E02'; +-- Purchase Return +UPDATE Auth_Roles SET Name = 'Purchase Return' WHERE RoleID = X'AB33196ED9E4114CAC8C997954363756'; +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'FC33E7F759745547A9FD7C411A896695', X'A35451B7502F8B4E9808F739225BEA93', X'9C4A3C81E60CAA4199D0C9571FA25512', X'F522EB8B20745648887DC63A54F683B3'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'FC33E7F759745547A9FD7C411A896695', X'A35451B7502F8B4E9808F739225BEA93', X'9C4A3C81E60CAA4199D0C9571FA25512', X'F522EB8B20745648887DC63A54F683B3'); +-- Raw Material Cost +UPDATE Auth_Roles SET Name = 'Raw Material Cost' WHERE RoleID = X'D462842BBAF1234395E5FFDBA9BBC163'; +-- Receipt +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'9E02EEC8D498F844AB83EF2017BEE919', X'0385EC9182A5FD42B9BBD2BD8201C566', X'AFB0C2EF72657B49A0A7431A08347779', X'92D70E801C32384D959EABF84B804696'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'9E02EEC8D498F844AB83EF2017BEE919', X'0385EC9182A5FD42B9BBD2BD8201C566', X'AFB0C2EF72657B49A0A7431A08347779', X'92D70E801C32384D959EABF84B804696'); +-- Trial Balance +UPDATE Auth_Roles SET Name = 'Trial Balance' WHERE RoleID = X'3B099FECDDC54243B30EAFB78D9CA14A'; +-- Users +UPDATE Auth_Roles SET Name = 'Users' WHERE RoleID = X'C5B7D9D7F1780E458EA4BF4E08EC901B' +-- Cleanup +DELETE FROM Auth_RoleGroups WHERE RoleID IN (X'018A2408E804144690C5B015829DA6BA', X'CFAD44F0F2A9704589D79019CF0F371A'); +DELETE FROM Auth_Roles WHERE RoleID IN (X'018A2408E804144690C5B015829DA6BA', X'CFAD44F0F2A9704589D79019CF0F371A'); diff --git a/brewman/brewman/__init__.py b/brewman/brewman/__init__.py index 2f07bb62..0c6ff811 100644 --- a/brewman/brewman/__init__.py +++ b/brewman/brewman/__init__.py @@ -131,7 +131,6 @@ def main(global_config, **settings): config.add_route('services_product_list', '/Services/ProductsList') config.add_route('services_products', '/Services/Products') - config.add_route('services_product_rate', '/Services/ProductRate') config.add_route('services_batch_list', '/Services/Batches') config.add_route('account_type_list', '/AccountTypes') @@ -139,13 +138,6 @@ def main(global_config, **settings): config.add_route('voucher', '/Voucher/{id}') config.add_route('voucher_new', '/Voucher') - config.add_route('is_user_in_role', '/Services/IsUserInRole/{id}') - config.add_route('is_user_in_roles', '/Services/IsUserInRoles') - - config.add_route('table', '/table/{id}') - config.add_route('sales', '/sales') - config.add_route('sse', '/sse') - config.add_route('favicon', '/favicon.ico') config.scan() diff --git a/brewman/brewman/models/voucher.py b/brewman/brewman/models/voucher.py index 5e179d0a..6230e537 100644 --- a/brewman/brewman/models/voucher.py +++ b/brewman/brewman/models/voucher.py @@ -1,4 +1,5 @@ from datetime import datetime +from pyramid.security import Allow from sqlalchemy.ext.hybrid import hybrid_property import uuid diff --git a/brewman/brewman/security.py b/brewman/brewman/security.py index c614acb2..04670c72 100644 --- a/brewman/brewman/security.py +++ b/brewman/brewman/security.py @@ -1,5 +1,6 @@ import uuid from brewman.models.auth import User +from brewman.models.voucher import Voucher class VoucherFactory(object): __acl__ = [] @@ -8,10 +9,10 @@ class VoucherFactory(object): self.request = request def __getitem__(self, key): - user = USERS[key] - user.__parent__ = self - user.__name__ = key - return user + voucher = Voucher.by_id(uuid.UUID(key)) + voucher.__parent__ = self + voucher.__name__ = key + return voucher def groupfinder(user_id, request): perms = [] diff --git a/brewman/brewman/static/partial/attendance.html b/brewman/brewman/static/partial/attendance.html index cffa1f71..e4d2ae15 100644 --- a/brewman/brewman/static/partial/attendance.html +++ b/brewman/brewman/static/partial/attendance.html @@ -1,4 +1,4 @@ -
+ Attendance
diff --git a/brewman/brewman/static/partial/cash-flow.html b/brewman/brewman/static/partial/cash-flow.html index a8fa5092..4c7edceb 100644 --- a/brewman/brewman/static/partial/cash-flow.html +++ b/brewman/brewman/static/partial/cash-flow.html @@ -1,4 +1,4 @@ - + Cash Flow
diff --git a/brewman/brewman/static/partial/closing-stock.html b/brewman/brewman/static/partial/closing-stock.html index 9a368da1..0d13e887 100644 --- a/brewman/brewman/static/partial/closing-stock.html +++ b/brewman/brewman/static/partial/closing-stock.html @@ -1,4 +1,4 @@ - + Closing Stock
diff --git a/brewman/brewman/static/partial/daybook.html b/brewman/brewman/static/partial/daybook.html index ae76868e..14453642 100644 --- a/brewman/brewman/static/partial/daybook.html +++ b/brewman/brewman/static/partial/daybook.html @@ -1,4 +1,4 @@ - + Daybook
diff --git a/brewman/brewman/static/partial/employee-attendance.html b/brewman/brewman/static/partial/employee-attendance.html index 92b04951..e48cbb39 100644 --- a/brewman/brewman/static/partial/employee-attendance.html +++ b/brewman/brewman/static/partial/employee-attendance.html @@ -1,4 +1,4 @@ - + Employee Attendance
diff --git a/brewman/brewman/static/partial/journal.html b/brewman/brewman/static/partial/journal.html index 0beb3aa1..fc0d6a58 100644 --- a/brewman/brewman/static/partial/journal.html +++ b/brewman/brewman/static/partial/journal.html @@ -1,4 +1,5 @@ + Journal Edit / New
diff --git a/brewman/brewman/static/partial/ledger.html b/brewman/brewman/static/partial/ledger.html index f7f0bdbf..9c971f10 100644 --- a/brewman/brewman/static/partial/ledger.html +++ b/brewman/brewman/static/partial/ledger.html @@ -1,4 +1,4 @@ - + Ledger
diff --git a/brewman/brewman/static/partial/product-ledger.html b/brewman/brewman/static/partial/product-ledger.html index 3f0aa15a..c4ab081d 100644 --- a/brewman/brewman/static/partial/product-ledger.html +++ b/brewman/brewman/static/partial/product-ledger.html @@ -1,4 +1,4 @@ - + Product Ledger
diff --git a/brewman/brewman/static/partial/profit-loss.html b/brewman/brewman/static/partial/profit-loss.html index d9a1ecc6..d1593b47 100644 --- a/brewman/brewman/static/partial/profit-loss.html +++ b/brewman/brewman/static/partial/profit-loss.html @@ -1,4 +1,4 @@ - + Profit & Loss
diff --git a/brewman/brewman/static/partial/purchase-entries.html b/brewman/brewman/static/partial/purchase-entries.html index 7ae8a212..5ea7e93f 100644 --- a/brewman/brewman/static/partial/purchase-entries.html +++ b/brewman/brewman/static/partial/purchase-entries.html @@ -1,4 +1,4 @@ - + Purchase Entries
diff --git a/brewman/brewman/static/partial/purchase.html b/brewman/brewman/static/partial/purchase.html index daad1c71..2b566f40 100644 --- a/brewman/brewman/static/partial/purchase.html +++ b/brewman/brewman/static/partial/purchase.html @@ -1,5 +1,5 @@ -

Purchase Edit / New

+ Purchase Edit / New
diff --git a/brewman/brewman/static/partial/raw-material-cost-detail.html b/brewman/brewman/static/partial/raw-material-cost-detail.html index fddc64a2..622c7f46 100644 --- a/brewman/brewman/static/partial/raw-material-cost-detail.html +++ b/brewman/brewman/static/partial/raw-material-cost-detail.html @@ -1,4 +1,4 @@ - + Raw Material Cost Detail
diff --git a/brewman/brewman/static/partial/raw-material-cost.html b/brewman/brewman/static/partial/raw-material-cost.html index d6c60a35..aa5e4527 100644 --- a/brewman/brewman/static/partial/raw-material-cost.html +++ b/brewman/brewman/static/partial/raw-material-cost.html @@ -1,4 +1,4 @@ - + Raw Material Cost
diff --git a/brewman/brewman/static/partial/trial-balance.html b/brewman/brewman/static/partial/trial-balance.html index ac94f4f0..8a36a4e0 100644 --- a/brewman/brewman/static/partial/trial-balance.html +++ b/brewman/brewman/static/partial/trial-balance.html @@ -1,4 +1,4 @@ - + Trial Balance
diff --git a/brewman/brewman/static/partial/unposted.html b/brewman/brewman/static/partial/unposted.html index b3722dcd..78fcae12 100644 --- a/brewman/brewman/static/partial/unposted.html +++ b/brewman/brewman/static/partial/unposted.html @@ -1,4 +1,4 @@ - + Unposted Entries
diff --git a/brewman/brewman/static/scripts/attendance.js b/brewman/brewman/static/scripts/attendance.js index 18c43f00..ae1e7ce9 100644 --- a/brewman/brewman/static/scripts/attendance.js +++ b/brewman/brewman/static/scripts/attendance.js @@ -22,9 +22,9 @@ AttendanceCtrl.resolve = { }; if (typeof date === 'undefined') { - return Attendance.get({}, successCb); + Attendance.get({}, successCb); } else { - return Attendance.get({date:date}, successCb); + Attendance.get({date:date}, successCb); } return deferred.promise; }, diff --git a/brewman/brewman/static/scripts/closing-stock.js b/brewman/brewman/static/scripts/closing-stock.js index 307fc8bf..3aeaf597 100644 --- a/brewman/brewman/static/scripts/closing-stock.js +++ b/brewman/brewman/static/scripts/closing-stock.js @@ -16,9 +16,9 @@ ClosingStockCtrl.resolve = { }; if (typeof date === 'undefined') { - return ClosingStock.get({}, successCb); + ClosingStock.get({}, successCb); } else { - return ClosingStock.get({date:date}, successCb); + ClosingStock.get({date:date}, successCb); } return deferred.promise; } diff --git a/brewman/brewman/static/scripts/daybook.js b/brewman/brewman/static/scripts/daybook.js index 28121dad..c77f9a5f 100644 --- a/brewman/brewman/static/scripts/daybook.js +++ b/brewman/brewman/static/scripts/daybook.js @@ -1,15 +1,26 @@ -function DaybookCtrl($scope, $routeParams, $location, Daybook) { - if (typeof $routeParams.StartDate === 'undefined') { - $scope.info = Daybook.get({}); - } else if (typeof $routeParams.id === 'undefined') { - $scope.info = Daybook.get({StartDate:$routeParams.StartDate, FinishDate:$routeParams.FinishDate}); - } +function DaybookCtrl($scope, $location, info) { + $scope.info = info; $scope.show = function () { - $scope.info = Daybook.get({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate}, function (u, putResponseHeaders) { - $location.path('/Daybook').search({StartDate:u.StartDate, FinishDate:u.FinishDate}); - }, function (data, status) { - $scope.toasts.push({Type:'Error', Message:data.data}); - }); + $location.path('/Daybook').search({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate}); }; $('#txtStartDate').focus(); } +DaybookCtrl.resolve = { + info:function ($q, $route, Daybook) { + var deferred = $q.defer(); + + var start_date = $route.current.params.StartDate; + var finish_date = $route.current.params.FinishDate; + + var successCb = function(result){ + deferred.resolve(result); + }; + + if (typeof start_date === 'undefined' || typeof finish_date === 'undefined') { + Daybook.get({}, successCb); + } else { + Daybook.get({StartDate:start_date, FinishDate:finish_date}, successCb); + } + return deferred.promise; + } +} \ No newline at end of file diff --git a/brewman/brewman/static/scripts/employee-attendance.js b/brewman/brewman/static/scripts/employee-attendance.js index e5376586..0d7010a0 100644 --- a/brewman/brewman/static/scripts/employee-attendance.js +++ b/brewman/brewman/static/scripts/employee-attendance.js @@ -25,10 +25,9 @@ EmployeeAttendanceCtrl.resolve = { deferred.resolve(result); }; if (typeof id === 'undefined') { - return EmployeeAttendance.get({}, successCb); + EmployeeAttendance.get({}, successCb); } else { - console.log('Getting employee with id'); - return EmployeeAttendance.get({id:id, StartDate:start_date, FinishDate:finish_date}, successCb); + EmployeeAttendance.get({id:id, StartDate:start_date, FinishDate:finish_date}, successCb); } return deferred.promise; }, diff --git a/brewman/brewman/static/scripts/issue.js b/brewman/brewman/static/scripts/issue.js index b4161e3a..f73cb8cc 100644 --- a/brewman/brewman/static/scripts/issue.js +++ b/brewman/brewman/static/scripts/issue.js @@ -124,7 +124,7 @@ }; $scope.save = function () { - $scope.voucher.$save(function (u, putResponseHeaders) { + $scope.voucher.$save({type:'Issue'}, function (u, putResponseHeaders) { $location.path('/Issue/' + u.VoucherID); $scope.toasts.push({Type:'Success', Message:u.Code}); $scope.updateGrid(); diff --git a/brewman/brewman/static/scripts/journal.js b/brewman/brewman/static/scripts/journal.js index 22e0341e..d76b8bf8 100644 --- a/brewman/brewman/static/scripts/journal.js +++ b/brewman/brewman/static/scripts/journal.js @@ -54,7 +54,7 @@ }; $scope.save = function () { - $scope.voucher.$save(function (u, putResponseHeaders) { + $scope.voucher.$save({type:'Journal'}, function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:u.Code}); $location.path('/Journal/' + u.VoucherID) }, function (data, status) { diff --git a/brewman/brewman/static/scripts/ledger.js b/brewman/brewman/static/scripts/ledger.js index b40253b5..14d97f2c 100644 --- a/brewman/brewman/static/scripts/ledger.js +++ b/brewman/brewman/static/scripts/ledger.js @@ -1,30 +1,30 @@ -function LedgerCtrl($scope, $routeParams, $location, Ledger) { - if (typeof $routeParams.id === 'undefined') { - $scope.info = Ledger.get({}); - } else { - $scope.info = Ledger.get({id:$routeParams.id, StartDate:$routeParams.StartDate, FinishDate:$routeParams.FinishDate}); - - } +function LedgerCtrl($scope, $routeParams, $location, ledger) { + $scope.info = ledger; $scope.show = function () { - $scope.info = Ledger.get({id:$scope.info.Ledger.LedgerID, StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate}, function (u, putResponseHeaders) { - $location.path('/Ledger/' + u.Ledger.LedgerID); - $location.search('StartDate', u.StartDate); - $location.search('FinishDate', u.FinishDate); - }, function (data, status) { - $scope.toasts.push({Type:'Error', Message:data.data}); - }); + $location.path('/Ledger/' + $scope.info.Ledger.LedgerID).search('StartDate', $scope.info.StartDate).search('FinishDate', $scope.info.FinishDate); }; $('#txtLedger').focus(); } -//LedgerCtrl.resolve = { -// ledger_data:function ($route, Ledger) { -// var params = $route.current.params; -// if (typeof params.id === 'undefined') { -// return Ledger.get({}); -// } else { -// return Ledger.get({id:params.id, StartDate:params.StartDate, FinishDate:params.FinishDate}); -// -// } -// } -//} \ No newline at end of file +LedgerCtrl.resolve = { + ledger:function ($q, $route, Ledger) { + var deferred = $q.defer(); + + var id = $route.current.params.id; + var start_date = $route.current.params.StartDate; + var finish_date = $route.current.params.FinishDate; + + var successCb = function(result){ + deferred.resolve(result); + }; + + if (typeof id === 'undefined') { + Ledger.get({}, successCb); + } else { + Ledger.get({id:id, StartDate:start_date, FinishDate:finish_date}, successCb); + } + return deferred.promise; + } +} + + diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index 8a44bb62..6c61a8c1 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -1,112 +1,157 @@ 'use strict'; var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filter', 'overlord.service']) - .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { - $routeProvider. - when('/', {templateUrl:'/partial/home.html'}). - when('/login', {templateUrl:'/partial/login.html', controller:LoginCtrl}). + .config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { + $routeProvider. + when('/', {templateUrl:'/partial/home.html'}). + when('/login', {templateUrl:'/partial/login.html', controller:LoginCtrl}). - when('/Journal', {templateUrl:'/partial/journal.html', controller:JournalCtrl}). - when('/Journal/:id', {templateUrl:'/partial/journal.html', controller:JournalCtrl}). + when('/Journal', {templateUrl:'/partial/journal.html', controller:JournalCtrl}). + when('/Journal/:id', {templateUrl:'/partial/journal.html', controller:JournalCtrl}). - when('/Payment', {templateUrl:'/partial/payment.html', controller:PaymentCtrl}). - when('/Payment/:id', {templateUrl:'/partial/payment.html', controller:PaymentCtrl}). + when('/Payment', {templateUrl:'/partial/payment.html', controller:PaymentCtrl}). + when('/Payment/:id', {templateUrl:'/partial/payment.html', controller:PaymentCtrl}). - when('/Receipt', {templateUrl:'/partial/receipt.html', controller:ReceiptCtrl}). - when('/Receipt/:id', {templateUrl:'/partial/receipt.html', controller:ReceiptCtrl}). + when('/Receipt', {templateUrl:'/partial/receipt.html', controller:ReceiptCtrl}). + when('/Receipt/:id', {templateUrl:'/partial/receipt.html', controller:ReceiptCtrl}). - when('/Purchase', {templateUrl:'/partial/purchase.html', controller:PurchaseCtrl}). - when('/Purchase/:id', {templateUrl:'/partial/purchase.html', controller:PurchaseCtrl}). + when('/Purchase', {templateUrl:'/partial/purchase.html', controller:PurchaseCtrl}). + when('/Purchase/:id', {templateUrl:'/partial/purchase.html', controller:PurchaseCtrl}). - when('/Issue', {templateUrl:'/partial/issue.html', controller:IssueCtrl}). - when('/Issue/:id', {templateUrl:'/partial/issue.html', controller:IssueCtrl}). + when('/Issue', {templateUrl:'/partial/issue.html', controller:IssueCtrl}). + when('/Issue/:id', {templateUrl:'/partial/issue.html', controller:IssueCtrl}). - when('/Ledger', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl}). - when('/Ledger/:id', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl}). + when('/Ledger', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl, resolve:LedgerCtrl.resolve}). + when('/Ledger/:id', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl, resolve:LedgerCtrl.resolve}). - when('/ProductLedger', {templateUrl:'/partial/product-ledger.html', controller:ProductLedgerCtrl}). - when('/ProductLedger/:id', {templateUrl:'/partial/product-ledger.html', controller:ProductLedgerCtrl}). + when('/ProductLedger', {templateUrl:'/partial/product-ledger.html', controller:ProductLedgerCtrl}). + when('/ProductLedger/:id', {templateUrl:'/partial/product-ledger.html', controller:ProductLedgerCtrl}). - when('/CashFlow', {templateUrl:'/partial/cash-flow.html', controller:CashFlowCtrl}). - when('/CashFlow/:id', {templateUrl:'/partial/cash-flow.html', controller:CashFlowCtrl}). + when('/CashFlow', {templateUrl:'/partial/cash-flow.html', controller:CashFlowCtrl}). + when('/CashFlow/:id', {templateUrl:'/partial/cash-flow.html', controller:CashFlowCtrl}). - when('/RawMaterialCost', {templateUrl:'/partial/raw-material-cost.html', controller:RawMaterialCostCtrl}). - when('/RawMaterialCost/:id', {templateUrl:'/partial/raw-material-cost-detail.html', controller:RawMaterialCostCtrl}). + when('/RawMaterialCost', {templateUrl:'/partial/raw-material-cost.html', controller:RawMaterialCostCtrl}). + when('/RawMaterialCost/:id', {templateUrl:'/partial/raw-material-cost-detail.html', controller:RawMaterialCostCtrl}). - when('/Attendance', {templateUrl:'/partial/attendance.html', controller:AttendanceCtrl, resolve: AttendanceCtrl.resolve}). - when('/Attendance/:date', {templateUrl:'/partial/attendance.html', controller:AttendanceCtrl, resolve: AttendanceCtrl.resolve}). + when('/Attendance', {templateUrl:'/partial/attendance.html', controller:AttendanceCtrl, resolve:AttendanceCtrl.resolve}). + when('/Attendance/:date', {templateUrl:'/partial/attendance.html', controller:AttendanceCtrl, resolve:AttendanceCtrl.resolve}). - when('/EmployeeAttendance', {templateUrl:'/partial/employee-attendance.html', controller:EmployeeAttendanceCtrl, resolve: EmployeeAttendanceCtrl.resolve}). - when('/EmployeeAttendance/:id', {templateUrl:'/partial/employee-attendance.html', controller:EmployeeAttendanceCtrl, resolve: EmployeeAttendanceCtrl.resolve}). + when('/EmployeeAttendance', {templateUrl:'/partial/employee-attendance.html', controller:EmployeeAttendanceCtrl, resolve:EmployeeAttendanceCtrl.resolve}). + when('/EmployeeAttendance/:id', {templateUrl:'/partial/employee-attendance.html', controller:EmployeeAttendanceCtrl, resolve:EmployeeAttendanceCtrl.resolve}). - when('/Daybook', {templateUrl:'/partial/daybook.html', controller:DaybookCtrl}). - when('/Unposted', {templateUrl:'/partial/unposted.html', controller:UnpostedCtrl}). - when('/ProfitLoss', {templateUrl:'/partial/profit-loss.html', controller:ProfitLossCtrl}). - when('/PurchaseEntries', {templateUrl:'/partial/purchase-entries.html', controller:PurchaseEntriesCtrl}). + when('/Daybook', {templateUrl:'/partial/daybook.html', controller:DaybookCtrl, resolve:DaybookCtrl.resolve}). + when('/Unposted', {templateUrl:'/partial/unposted.html', controller:UnpostedCtrl}). + when('/ProfitLoss', {templateUrl:'/partial/profit-loss.html', controller:ProfitLossCtrl}). + when('/PurchaseEntries', {templateUrl:'/partial/purchase-entries.html', controller:PurchaseEntriesCtrl}). - when('/TrialBalance', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}). - when('/TrialBalance/:date', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}). + when('/TrialBalance', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}). + when('/TrialBalance/:date', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}). - when('/ClosingStock', {templateUrl:'/partial/closing-stock.html', controller:ClosingStockCtrl, resolve:ClosingStockCtrl.resolve}). - when('/ClosingStock/:date', {templateUrl:'/partial/closing-stock.html', controller:ClosingStockCtrl, resolve:ClosingStockCtrl.resolve}). + when('/ClosingStock', {templateUrl:'/partial/closing-stock.html', controller:ClosingStockCtrl, resolve:ClosingStockCtrl.resolve}). + when('/ClosingStock/:date', {templateUrl:'/partial/closing-stock.html', controller:ClosingStockCtrl, resolve:ClosingStockCtrl.resolve}). - when('/Accounts', {templateUrl:'/partial/account-list.html', controller:AccountListCtrl}). - when('/Account', {templateUrl:'/partial/account-detail.html', controller:AccountCtrl}). - when('/Account/:id', {templateUrl:'/partial/account-detail.html', controller:AccountCtrl}). + when('/Accounts', {templateUrl:'/partial/account-list.html', controller:AccountListCtrl}). + when('/Account', {templateUrl:'/partial/account-detail.html', controller:AccountCtrl}). + when('/Account/:id', {templateUrl:'/partial/account-detail.html', controller:AccountCtrl}). - when('/Employees', {templateUrl:'/partial/employee-list.html', controller:EmployeeListCtrl}). - when('/Employee', {templateUrl:'/partial/employee-detail.html', controller:EmployeeCtrl}). - when('/Employee/:id', {templateUrl:'/partial/employee-detail.html', controller:EmployeeCtrl}). + when('/Employees', {templateUrl:'/partial/employee-list.html', controller:EmployeeListCtrl}). + when('/Employee', {templateUrl:'/partial/employee-detail.html', controller:EmployeeCtrl}). + when('/Employee/:id', {templateUrl:'/partial/employee-detail.html', controller:EmployeeCtrl}). - when('/CostCenters', {templateUrl:'/partial/cost-center-list.html', controller:CostCenterListCtrl}). - when('/CostCenter', {templateUrl:'/partial/cost-center-detail.html', controller:CostCenterCtrl}). - when('/CostCenter/:id', {templateUrl:'/partial/cost-center-detail.html', controller:CostCenterCtrl}). + when('/CostCenters', {templateUrl:'/partial/cost-center-list.html', controller:CostCenterListCtrl}). + when('/CostCenter', {templateUrl:'/partial/cost-center-detail.html', controller:CostCenterCtrl}). + when('/CostCenter/:id', {templateUrl:'/partial/cost-center-detail.html', controller:CostCenterCtrl}). - when('/Products', {templateUrl:'/partial/product-list.html', controller:ProductListCtrl}). - when('/Product', {templateUrl:'/partial/product-detail.html', controller:ProductCtrl}). - when('/Product/:id', {templateUrl:'/partial/product-detail.html', controller:ProductCtrl}). + when('/Products', {templateUrl:'/partial/product-list.html', controller:ProductListCtrl}). + when('/Product', {templateUrl:'/partial/product-detail.html', controller:ProductCtrl}). + when('/Product/:id', {templateUrl:'/partial/product-detail.html', controller:ProductCtrl}). - when('/ProductGroups', {templateUrl:'/partial/product-group-list.html', controller:ProductGroupListCtrl}). - when('/ProductGroup', {templateUrl:'/partial/product-group-detail.html', controller:ProductGroupCtrl}). - when('/ProductGroup/:id', {templateUrl:'/partial/product-group-detail.html', controller:ProductGroupCtrl}). + when('/ProductGroups', {templateUrl:'/partial/product-group-list.html', controller:ProductGroupListCtrl}). + when('/ProductGroup', {templateUrl:'/partial/product-group-detail.html', controller:ProductGroupCtrl}). + when('/ProductGroup/:id', {templateUrl:'/partial/product-group-detail.html', controller:ProductGroupCtrl}). - when('/Users', {templateUrl:'/partial/user-list.html', controller:UserListCtrl}). - when('/User', {templateUrl:'/partial/user-detail.html', controller:UserCtrl}). - when('/User/:id', {templateUrl:'/partial/user-detail.html', controller:UserCtrl}). + when('/Users', {templateUrl:'/partial/user-list.html', controller:UserListCtrl}). + when('/User', {templateUrl:'/partial/user-detail.html', controller:UserCtrl}). + when('/User/:id', {templateUrl:'/partial/user-detail.html', controller:UserCtrl}). - when('/Groups', {templateUrl:'/partial/group-list.html', controller:GroupListCtrl}). - when('/Group', {templateUrl:'/partial/group-detail.html', controller:GroupCtrl}). - when('/Group/:id', {templateUrl:'/partial/group-detail.html', controller:GroupCtrl}). + when('/Groups', {templateUrl:'/partial/group-list.html', controller:GroupListCtrl}). + when('/Group', {templateUrl:'/partial/group-detail.html', controller:GroupCtrl}). + when('/Group/:id', {templateUrl:'/partial/group-detail.html', controller:GroupCtrl}). - otherwise({templateUrl:'/partial/404.html'}); - $locationProvider.html5Mode(true).hashPrefix('!'); - }]) - .config(function ($httpProvider) { - $httpProvider.responseInterceptors.push('spinnerInterceptor'); - var spinnerFunction = function (data, headersGetter) { - $('#spinner').show(); - return data; - }; - $httpProvider.defaults.transformRequest.push(spinnerFunction); - }) - .factory('spinnerInterceptor', function ($q, $window) { - return function (promise) { - return promise.then(function (response) { - $('#spinner').hide(); - return response; + otherwise({templateUrl:'/partial/404.html'}); + $locationProvider.html5Mode(true).hashPrefix('!'); +}]) + .config(function ($httpProvider) { + $httpProvider.responseInterceptors.push('spinnerInterceptor'); + var spinnerFunction = function (data, headersGetter) { + var scope = angular.injector(['ng']).get('$rootScope'), + headers = headersGetter(), + isResourceRequest = headers['Content-Type'] === "application/json"; - }, function (response) { - $('#spinner').hide(); - return $q.reject(response); - }); - }; + if (isResourceRequest && scope) { + scope.$broadcast('spinnerStart', 'http'); + } + return data; + }; + $httpProvider.defaults.transformRequest.push(spinnerFunction); + }) + .factory('spinnerInterceptor', ['$q', '$rootScope', function ($q, $rootScope) { + return function (promise) { + return promise.then(function (response) { + var headers = response.headers(), + isResourceResponse = headers['content-type'] === "application/json; charset=utf-8"; + if (isResourceResponse) { + $rootScope.$broadcast('spinnerStop', 'http'); + } + return response; + + }, function (response) { + var headers = response.headers(), + isResourceResponse = headers['content-type'] === "application/json; charset=utf-8"; + if (isResourceResponse) { + $rootScope.$broadcast('spinnerStop', 'http'); + } + var status = response.status; + if (status == 401) { + $rootScope.$broadcast('event:loginRequired'); + } + // otherwise + return $q.reject(response); }); + }; +}]); -function BaseCtrl($scope, Auth) { - $scope.auth = Auth.get(function (u, putResponseHeaders) { - $scope.perms = u.perms; +function BaseCtrl($rootScope, $scope, Auth, $location) { + $rootScope.spinner = {http:0, route:false}; + $rootScope.$on('event:loginRequired', function () { + if (!$rootScope.auth.isAuthenticated) { + $location.path('/'); + } else { + $location.path('/login'); + } }); + $scope.$on('spinnerStart', function (event, what) { + console.log(what); + if (what === 'http') { + $rootScope.spinner.http += 1 + } else { + $rootScope.spinner[what] = false; + } + $('#spinner').show(); + }); + + $scope.$on('spinnerStop', function (event, what) { + console.log(what); + if (what === 'http') { + $rootScope.spinner.http -= 1 + } else { + $rootScope.spinner[what] = false; + } + if ($rootScope.spinner.http <= 0 && $rootScope.spinner.route === false) { + $('#spinner').hide(); + } + }); $scope.toasts = []; $scope.clearToast = function (item) { var idx = $scope.toasts.indexOf(item); @@ -119,13 +164,16 @@ function BaseCtrl($scope, Auth) { }; -// $rootScope.$on("$routeChangeStart", function (event, next, current) { -// $scope.toasts.push("Loading..."); -// }); -// $rootScope.$on("$routeChangeSuccess", function (event, current, previous) { -// $scope.toasts.push("Successfully changed routes :)"); -// }); -// $rootScope.$on("$routeChangeError", function (event, current, previous, rejection) { -// $scope.toasts.push("ROUTE CHANGE ERROR: " + rejection); -// }); + $rootScope.$on("$routeChangeStart", function (event, next, current) { + $rootScope.$broadcast('spinnerStart', 'route'); + $rootScope.auth = Auth.get(function (u, putResponseHeaders) { + $rootScope.perms = u.perms; + }); + }); + $rootScope.$on("$routeChangeSuccess", function (event, current, previous) { + $rootScope.$broadcast('spinnerStop', 'route'); + }); + $rootScope.$on("$routeChangeError", function (event, current, previous, rejection) { + $rootScope.$broadcast('spinnerStop', 'route'); + }); } diff --git a/brewman/brewman/static/scripts/payment.js b/brewman/brewman/static/scripts/payment.js index 860bc6fa..619c6acb 100644 --- a/brewman/brewman/static/scripts/payment.js +++ b/brewman/brewman/static/scripts/payment.js @@ -60,7 +60,7 @@ }; $scope.save = function () { - $scope.voucher.$save(function (u, putResponseHeaders) { + $scope.voucher.$save({type:'Payment'}, function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:u.Code}); $location.path('/Payment/' + u.VoucherID) }, function (data, status) { diff --git a/brewman/brewman/static/scripts/purchase.js b/brewman/brewman/static/scripts/purchase.js index cb02dc64..5ddc6225 100644 --- a/brewman/brewman/static/scripts/purchase.js +++ b/brewman/brewman/static/scripts/purchase.js @@ -71,7 +71,7 @@ }; $scope.save = function () { - $scope.voucher.$save(function (u, putResponseHeaders) { + $scope.voucher.$save({type:'Purchase'}, function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:u.Code}); $location.path('/Purchase/' + u.VoucherID) }, function (data, status) { diff --git a/brewman/brewman/static/scripts/receipt.js b/brewman/brewman/static/scripts/receipt.js index 7be50807..3c497119 100644 --- a/brewman/brewman/static/scripts/receipt.js +++ b/brewman/brewman/static/scripts/receipt.js @@ -60,7 +60,7 @@ }; $scope.save = function () { - $scope.voucher.$save(function (u, putResponseHeaders) { + $scope.voucher.$save({type:'Receipt'}, function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:u.Code}); $location.path('/Receipt/' + u.VoucherID) }, function (data, status) { diff --git a/brewman/brewman/views/auth/group.py b/brewman/brewman/views/auth/group.py index 93e892c0..086eeeb8 100644 --- a/brewman/brewman/views/auth/group.py +++ b/brewman/brewman/views/auth/group.py @@ -97,7 +97,6 @@ def group_info(id): group = {'Name': '', 'Permissions': []} for item in Role.list(): group['Permissions'].append({'PermissionID': item.id, 'Name': item.name, 'Enabled': False}) - print(group) else: group_object = Group.get_by_id(id) group = {'GroupID': group_object.id, 'Name': group_object.name, 'Permissions': []} diff --git a/brewman/brewman/views/cost_center.py b/brewman/brewman/views/cost_center.py index 50266440..7030eb5a 100644 --- a/brewman/brewman/views/cost_center.py +++ b/brewman/brewman/views/cost_center.py @@ -8,7 +8,7 @@ from brewman.models.master import CostCenter from brewman.models.validation_exception import ValidationError -@view_config(route_name='cost_center_list', renderer='brewman:templates/angular_base.mako', permission='Cost Centers') +@view_config(route_name='cost_center_list', renderer='brewman:templates/angular_base.mako', permission='Authenticated') @view_config(request_method='GET', route_name='cost_center_id', renderer='brewman:templates/angular_base.mako', xhr=False, permission='Cost Centers') @view_config(request_method='GET', route_name='cost_center', renderer='brewman:templates/angular_base.mako', diff --git a/brewman/brewman/views/employee.py b/brewman/brewman/views/employee.py index 54eadfd8..c7c078e1 100644 --- a/brewman/brewman/views/employee.py +++ b/brewman/brewman/views/employee.py @@ -8,7 +8,7 @@ import transaction from brewman.models.master import CostCenter, Employee from brewman.models.validation_exception import ValidationError -@view_config(route_name='employee_list', renderer='brewman:templates/angular_base.mako', permission='Employees') +@view_config(route_name='employee_list', renderer='brewman:templates/angular_base.mako', permission='Authenticated') @view_config(request_method='GET', route_name='employee_id', renderer='brewman:templates/angular_base.mako', xhr=False, permission='Employees') @view_config(request_method='GET', route_name='employee', renderer='brewman:templates/angular_base.mako', xhr=False, diff --git a/brewman/brewman/views/product.py b/brewman/brewman/views/product.py index 4dca5506..5d01bed7 100644 --- a/brewman/brewman/views/product.py +++ b/brewman/brewman/views/product.py @@ -8,7 +8,7 @@ import transaction from brewman.models.master import Product, CostCenter, LedgerType, Ledger, ProductGroup from brewman.models.validation_exception import ValidationError -@view_config(route_name='product_list', renderer='brewman:templates/angular_base.mako', permission='Products') +@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', xhr=False, permission='Products') @view_config(request_method='GET', route_name='product', renderer='brewman:templates/angular_base.mako', diff --git a/brewman/brewman/views/product_group.py b/brewman/brewman/views/product_group.py index bb32ac98..45b16fc2 100644 --- a/brewman/brewman/views/product_group.py +++ b/brewman/brewman/views/product_group.py @@ -9,7 +9,7 @@ from brewman.models.master import CostCenter, ProductGroup from brewman.models.validation_exception import ValidationError -@view_config(route_name='product_group_list', renderer='brewman:templates/angular_base.mako', permission='Product Groups') +@view_config(route_name='product_group_list', renderer='brewman:templates/angular_base.mako', permission='Authenticated') @view_config(request_method='GET', route_name='product_group_id', renderer='brewman:templates/angular_base.mako', xhr=False, permission='Product Groups') @view_config(request_method='GET', route_name='product_group', renderer='brewman:templates/angular_base.mako', diff --git a/brewman/brewman/views/reports/cash_flow.py b/brewman/brewman/views/reports/cash_flow.py index bc50f5b8..d8c94ac5 100644 --- a/brewman/brewman/views/reports/cash_flow.py +++ b/brewman/brewman/views/reports/cash_flow.py @@ -11,14 +11,14 @@ from brewman.models.voucher import Voucher, Journal from brewman.views.services.session import services_session_period_start, services_session_period_finish @view_config(request_method='GET', route_name='cash_flow', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Cash Flow') @view_config(request_method='GET', route_name='cash_flow_id', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Cash Flow') def get_html(request): return {} -@view_config(request_method='GET', route_name='cash_flow', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='cash_flow', renderer='json', xhr=True, permission='Cash Flow') def get_cash_flow(request): start_date = request.GET.get('StartDate', None) finish_date = request.GET.get('FinishDate', None) @@ -29,7 +29,7 @@ def get_cash_flow(request): 'FinishDate': services_session_period_finish(request), 'Body': [], 'Footer': {}} -@view_config(request_method='GET', route_name='cash_flow_id', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='cash_flow_id', renderer='json', xhr=True, permission='Cash Flow') def get_cash_flow_id(request): id = request.matchdict.get('id', None) start_date = request.GET.get('StartDate', None) diff --git a/brewman/brewman/views/reports/closing_stock.py b/brewman/brewman/views/reports/closing_stock.py index fddb06da..aea702f4 100644 --- a/brewman/brewman/views/reports/closing_stock.py +++ b/brewman/brewman/views/reports/closing_stock.py @@ -10,22 +10,20 @@ from brewman.models.voucher import Voucher, Journal, Inventory from brewman.views.services.session import services_session_period_finish @view_config(request_method='GET', route_name='closing_stock', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Closing Stock') @view_config(request_method='GET', route_name='closing_stock_date', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Closing Stock') def get_html(request): return {} -@view_config(request_method='GET', route_name='closing_stock', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='closing_stock', renderer='json', xhr=True, permission='Closing Stock') def report_blank(request): - print('getting closing stock') return {'Date': services_session_period_finish(request), 'Body': []} -@view_config(request_method='GET', route_name='closing_stock_date', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='closing_stock_date', renderer='json', xhr=True, permission='Closing Stock') def report_data(request): - print('getting closing stock date') date = request.matchdict.get('date', None) return {'Date': date, 'Body': build_report(date)} @@ -46,54 +44,4 @@ def build_report(date): if quantity != 0 and amount != 0: body.append({'Product': product.full_name, 'Group': product.product_group.name, 'Quantity': "{0:,.2f}".format(quantity), 'Amount': "\u20B9 {0:,.2f}".format(amount)}) - return body - - -#def build_report(start_date, finish_date): -# start_date = datetime.datetime.strptime(start_date, '%d-%b-%Y') -# finish_date = datetime.datetime.strptime(finish_date, '%d-%b-%Y') -# opening_query = DBSession.query(Ledger, literal('O', Unicode(1)).label('Type'), func.sum(Journal.amount * Journal.debit).label('Opening'), literal(0, Numeric).label('Closing'))\ -# .join(Journal.voucher).join(Journal.ledger)\ -# .filter(Voucher.date < start_date)\ -# .filter(Voucher.type != VoucherType.by_name('Issue').id)\ -# .group_by(Ledger) -# -# closing_query = DBSession.query(Ledger, literal('C', Unicode(1)).label('Type'), literal(0, Numeric).label('Opening'), func.sum(Journal.amount * Journal.debit).label('Closing'))\ -# .join(Journal.voucher).join(Journal.ledger)\ -# .filter(Voucher.date <= finish_date)\ -# .filter(Voucher.type != VoucherType.by_name('Issue').id)\ -# .group_by(Ledger) -# -# query = opening_query.union(closing_query)\ -# .order_by(Ledger.type)\ -# .order_by(Ledger.name)\ -# .all() -# report = dict() -# body = [] -# for ledger, entry_type, opening, closing in query: -# if ledger.id in report: -# if entry_type == 'O' and opening != 0: -# report[ledger.id]['Opening'] = opening -# elif entry_type == 'C' and closing != 0: -# report[ledger.id]['Closing'] = closing -# else: -# if opening != 0 or closing != 0: -# report[ledger.id] = { 'Ledger': ledger, 'Opening':opening, 'Closing':closing } -# -## report = sorted(list(report.values()), key=lambda sorter: sorter['Ledger'].type) -# for item in report: -# ledger = item['Ledger'] -# ledger_type = LedgerType.by_id(ledger.type) -# if item['Opening'] >= 0: -# opening = "\u20B9 {0:,.2f} Dr".format(item['Opening']) -# else: -# opening = "\u20B9 {0:,.2f} Cr".format(item['Opening'] * -1) -# if item['Closing'] >= 0: -# closing = "\u20B9 {0:,.2f} Dr".format(item['Closing']) -# else: -# closing = "\u20B9 {0:,.2f} Cr".format(item['Closing'] * -1) -# body.append({'Type':ledger_type.name, 'Name':ledger.name, 'Opening':opening, 'Closing': closing}) -# -# return body -# -# + return body \ No newline at end of file diff --git a/brewman/brewman/views/reports/daybook.py b/brewman/brewman/views/reports/daybook.py index 910da588..4dee4c70 100644 --- a/brewman/brewman/views/reports/daybook.py +++ b/brewman/brewman/views/reports/daybook.py @@ -8,12 +8,12 @@ from brewman.views.services.session import services_session_period_finish, servi from brewman.views.transactions import get_edit_url @view_config(request_method='GET', route_name='daybook', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Daybook') def daybook_get(request): return {} -@view_config(request_method='GET', route_name='daybook', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='daybook', renderer='json', xhr=True, permission='Daybook') def daybook_report(request): start_date = request.GET.get('StartDate', None) finish_date = request.GET.get('FinishDate', None) diff --git a/brewman/brewman/views/reports/ledger.py b/brewman/brewman/views/reports/ledger.py index 9efb6c7b..135cb673 100644 --- a/brewman/brewman/views/reports/ledger.py +++ b/brewman/brewman/views/reports/ledger.py @@ -13,29 +13,30 @@ from brewman.views.services.session import services_session_period_start, servic from brewman.views.transactions import get_edit_url @view_config(request_method='GET', route_name='ledger_id', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Ledger') @view_config(request_method='GET', route_name='ledger', renderer='brewman:templates/angular_base.mako', - xhr=False) -def ledger_display_get(request): + xhr=False, permission='Ledger') +def html(request): return {} -@view_config(request_method='GET', route_name='ledger_id', renderer='json', xhr=True) -@view_config(request_method='GET', route_name='ledger', renderer='json', xhr=True) -def ledger_display_post(request): - id = request.matchdict.get('id', None) - if id is None: - return {'StartDate': services_session_period_start(request), - 'FinishDate': services_session_period_finish(request), 'Ledger': {}, 'Body': [], 'Footer': {}} - else: - ledger = LedgerBase.by_id(uuid.UUID(id)) - start_date = request.GET.get('StartDate', services_session_period_start(request)) - finish_date = request.GET.get('FinishDate', services_session_period_finish(request)) - info = {'StartDate': start_date, 'FinishDate': finish_date, - 'Ledger': {'LedgerID': ledger.id, 'Name': ledger.name}, - 'Body': [], 'Footer': {}} - build_report(request, info) - return info +@view_config(request_method='GET', route_name='ledger', renderer='json', xhr=True, permission='Ledger') +def show_blank(request): + return {'StartDate': services_session_period_start(request), + 'FinishDate': services_session_period_finish(request), 'Ledger': {}, 'Body': [], 'Footer': {}} + + +@view_config(request_method='GET', route_name='ledger_id', renderer='json', xhr=True, permission='Ledger') +def show_data(request): + id = request.matchdict['id'] + ledger = LedgerBase.by_id(uuid.UUID(id)) + start_date = request.GET.get('StartDate', services_session_period_start(request)) + finish_date = request.GET.get('FinishDate', services_session_period_finish(request)) + info = {'StartDate': start_date, 'FinishDate': finish_date, + 'Ledger': {'LedgerID': ledger.id, 'Name': ledger.name}, + 'Body': [], 'Footer': {}} + build_report(request, info) + return info def build_report(request, info): diff --git a/brewman/brewman/views/reports/product_ledger.py b/brewman/brewman/views/reports/product_ledger.py index 45277dbe..fadd7431 100644 --- a/brewman/brewman/views/reports/product_ledger.py +++ b/brewman/brewman/views/reports/product_ledger.py @@ -13,29 +13,30 @@ from brewman.views.services.session import services_session_period_start, servic from brewman.views.transactions import get_edit_url @view_config(request_method='GET', route_name='product_ledger_id', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Product Ledger') @view_config(request_method='GET', route_name='product_ledger', renderer='brewman:templates/angular_base.mako', - xhr=False) -def ledger_display_get(request): + xhr=False, permission='Product Ledger') +def html(request): return {} -@view_config(request_method='GET', route_name='product_ledger_id', renderer='json', xhr=True) -@view_config(request_method='GET', route_name='product_ledger', renderer='json', xhr=True) -def ledger_display_post(request): - id = request.matchdict.get('id', None) - if id is None: - return {'StartDate': services_session_period_start(request), - 'FinishDate': services_session_period_finish(request), 'Product': {}, 'Body': [], 'Footer': {}} - else: - product = Product.by_id(uuid.UUID(id)) - start_date = request.GET.get('StartDate', services_session_period_start(request)) - finish_date = request.GET.get('FinishDate', services_session_period_finish(request)) - info = {'StartDate': start_date, 'FinishDate': finish_date, - 'Product': {'ProductID': product.id, 'Name': product.name}, - 'Body': [], 'Footer': {}} - build_report(request, info) - return info +@view_config(request_method='GET', route_name='product_ledger', renderer='json', xhr=True, permission='Product Ledger') +def show_blank(request): + return {'StartDate': services_session_period_start(request), + 'FinishDate': services_session_period_finish(request), 'Product': {}, 'Body': [], 'Footer': {}} + + +@view_config(request_method='GET', route_name='product_ledger_id', renderer='json', xhr=True, permission='Product Ledger') +def show_data(request): + id = request.matchdict['id'] + product = Product.by_id(uuid.UUID(id)) + start_date = request.GET.get('StartDate', services_session_period_start(request)) + finish_date = request.GET.get('FinishDate', services_session_period_finish(request)) + info = {'StartDate': start_date, 'FinishDate': finish_date, + 'Product': {'ProductID': product.id, 'Name': product.name}, + 'Body': [], 'Footer': {}} + build_report(request, info) + return info def build_report(request, info): diff --git a/brewman/brewman/views/reports/profit_loss.py b/brewman/brewman/views/reports/profit_loss.py index 7cc7e505..f11f6382 100644 --- a/brewman/brewman/views/reports/profit_loss.py +++ b/brewman/brewman/views/reports/profit_loss.py @@ -10,13 +10,13 @@ from brewman.models.voucher import Voucher, Journal, VoucherType, Inventory from brewman.views.services.session import services_session_period_start, services_session_period_finish @view_config(request_method='GET', route_name='profit_loss', renderer='brewman:templates/angular_base.mako', - xhr=False) -def get_html(request): + xhr=False, permission='Profit & Loss') +def html(request): return {} -@view_config(request_method='GET', route_name='profit_loss', renderer='json', xhr=True) -def get_profit_loss(request): +@view_config(request_method='GET', route_name='profit_loss', renderer='json', xhr=True, permission='Profit & Loss') +def report(request): start_date = request.GET.get('StartDate', None) finish_date = request.GET.get('FinishDate', None) if start_date and finish_date: diff --git a/brewman/brewman/views/reports/purchase_entries.py b/brewman/brewman/views/reports/purchase_entries.py index 2c3cfef1..8a6aa82f 100644 --- a/brewman/brewman/views/reports/purchase_entries.py +++ b/brewman/brewman/views/reports/purchase_entries.py @@ -11,21 +11,20 @@ from brewman.views.services.session import services_session_period_start, servic from brewman.views.transactions import get_edit_url @view_config(request_method='GET', route_name='purchase_entries', renderer='brewman:templates/angular_base.mako', - xhr=False) -def get_html(request): + xhr=False, permission='Purchase Entries') +def html(request): return {} -@view_config(request_method='GET', route_name='purchase_entries', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='purchase_entries', renderer='json', xhr=True, permission='Purchase Entries') def report_blank(request): return {'StartDate': services_session_period_start(request), 'FinishDate': services_session_period_finish(request), 'Body': [], 'Footer': {}} @view_config(request_method='GET', route_name='purchase_entries', request_param='StartDate', renderer='json', - xhr=True) + xhr=True, permission='Purchase Entries') def report_data(request): - print('get report') start_date = request.GET.get('StartDate', None) finish_date = request.GET.get('FinishDate', None) return build_report(request, start_date, finish_date) diff --git a/brewman/brewman/views/reports/raw_material_cost.py b/brewman/brewman/views/reports/raw_material_cost.py index dd479fe7..a16f01a6 100644 --- a/brewman/brewman/views/reports/raw_material_cost.py +++ b/brewman/brewman/views/reports/raw_material_cost.py @@ -11,20 +11,20 @@ from brewman.models.voucher import Voucher, Journal, Inventory from brewman.views.services.session import services_session_period_start, services_session_period_finish @view_config(request_method='GET', route_name='raw_material_cost', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Raw Material Cost') @view_config(request_method='GET', route_name='raw_material_cost_id', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Raw Material Cost') def get_html(request): return {} -@view_config(request_method='GET', route_name='raw_material_cost', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='raw_material_cost', renderer='json', xhr=True, permission='Raw Material Cost') def report_blank(request): return {'StartDate': services_session_period_start(request), 'FinishDate': services_session_period_finish(request), 'Body': [], 'Footer': {}} -@view_config(request_method='GET', route_name='raw_material_cost', request_param='StartDate', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='raw_material_cost', request_param='StartDate', renderer='json', xhr=True, permission='Raw Material Cost') def report_data(request): start_date = request.GET.get('StartDate', None) finish_date = request.GET.get('FinishDate', None) @@ -32,7 +32,7 @@ def report_data(request): @view_config(request_method='GET', route_name='raw_material_cost_id', request_param='StartDate', renderer='json', - xhr=True) + xhr=True, permission='Raw Material Cost') def report_id(request): id = request.matchdict.get('id', None) start_date = request.GET.get('StartDate', None) diff --git a/brewman/brewman/views/reports/trial_balance.py b/brewman/brewman/views/reports/trial_balance.py index 71a72765..efcecc92 100644 --- a/brewman/brewman/views/reports/trial_balance.py +++ b/brewman/brewman/views/reports/trial_balance.py @@ -10,18 +10,18 @@ from brewman.models.voucher import Voucher, Journal, VoucherType from brewman.views.services.session import services_session_period_finish @view_config(request_method='GET', route_name='trial_balance', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Trial Balance') @view_config(request_method='GET', route_name='trial_balance_date', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Trial Balance') def ledger_display_get(request): return {} -@view_config(request_method='GET', route_name='trial_balance', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='trial_balance', renderer='json', xhr=True, permission='Trial Balance') def report_blank(request): return {'Date': services_session_period_finish(request), 'Body': []} -@view_config(request_method='GET', route_name='trial_balance_date', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='trial_balance_date', renderer='json', xhr=True, permission='Trial Balance') def report_data(request): date = request.matchdict.get('date', None) return {'Date': date, 'Body': build_report(date)} @@ -43,53 +43,3 @@ def build_report(date): val = "\u20B9 {0:,.2f} Dr".format(amount) if amount > 0 else "\u20B9 {0:,.2f} Cr".format(amount * -1) body.append({'Type': ledger.type_object.name, 'Name': ledger.name, tag:val}) return body - - -#def build_report(start_date, finish_date): -# start_date = datetime.datetime.strptime(start_date, '%d-%b-%Y') -# finish_date = datetime.datetime.strptime(finish_date, '%d-%b-%Y') -# opening_query = DBSession.query(Ledger, literal('O', Unicode(1)).label('Type'), func.sum(Journal.amount * Journal.debit).label('Opening'), literal(0, Numeric).label('Closing'))\ -# .join(Journal.voucher).join(Journal.ledger)\ -# .filter(Voucher.date < start_date)\ -# .filter(Voucher.type != VoucherType.by_name('Issue').id)\ -# .group_by(Ledger) -# -# closing_query = DBSession.query(Ledger, literal('C', Unicode(1)).label('Type'), literal(0, Numeric).label('Opening'), func.sum(Journal.amount * Journal.debit).label('Closing'))\ -# .join(Journal.voucher).join(Journal.ledger)\ -# .filter(Voucher.date <= finish_date)\ -# .filter(Voucher.type != VoucherType.by_name('Issue').id)\ -# .group_by(Ledger) -# -# query = opening_query.union(closing_query)\ -# .order_by(Ledger.type)\ -# .order_by(Ledger.name)\ -# .all() -# report = dict() -# body = [] -# for ledger, entry_type, opening, closing in query: -# if ledger.id in report: -# if entry_type == 'O' and opening != 0: -# report[ledger.id]['Opening'] = opening -# elif entry_type == 'C' and closing != 0: -# report[ledger.id]['Closing'] = closing -# else: -# if opening != 0 or closing != 0: -# report[ledger.id] = { 'Ledger': ledger, 'Opening':opening, 'Closing':closing } -# -## report = sorted(list(report.values()), key=lambda sorter: sorter['Ledger'].type) -# for item in report: -# ledger = item['Ledger'] -# ledger_type = LedgerType.by_id(ledger.type) -# if item['Opening'] >= 0: -# opening = "\u20B9 {0:,.2f} Dr".format(item['Opening']) -# else: -# opening = "\u20B9 {0:,.2f} Cr".format(item['Opening'] * -1) -# if item['Closing'] >= 0: -# closing = "\u20B9 {0:,.2f} Dr".format(item['Closing']) -# else: -# closing = "\u20B9 {0:,.2f} Cr".format(item['Closing'] * -1) -# body.append({'Type':ledger_type.name, 'Name':ledger.name, 'Opening':opening, 'Closing': closing}) -# -# return body -# -# diff --git a/brewman/brewman/views/reports/unposted.py b/brewman/brewman/views/reports/unposted.py index ae340e90..8f4406f9 100644 --- a/brewman/brewman/views/reports/unposted.py +++ b/brewman/brewman/views/reports/unposted.py @@ -6,13 +6,13 @@ from brewman.models.voucher import Voucher, Journal, VoucherType from brewman.views.transactions import get_edit_url @view_config(request_method='GET', route_name='unposted', renderer='brewman:templates/angular_base.mako', - xhr=False) -def unposted_get(request): + xhr=False, permission='Post Vouchers') +def html(request): return {} -@view_config(request_method='GET', route_name='unposted', renderer='json', xhr=True) -def unposted_report(request): +@view_config(request_method='GET', route_name='unposted', renderer='json', xhr=True, permission='Post Vouchers') +def report_data(request): return build_report(request) def build_report(request): diff --git a/brewman/brewman/views/services/batch.py b/brewman/brewman/views/services/batch.py index c1424d5d..74a21c54 100644 --- a/brewman/brewman/views/services/batch.py +++ b/brewman/brewman/views/services/batch.py @@ -2,7 +2,7 @@ from pyramid.view import view_config from brewman.models.voucher import Batch -@view_config(request_method='POST', route_name='services_batch_list', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='services_batch_list', renderer='json', xhr=True, permission='Authenticated') def list(request): filter = request.json_body['prefixText'] list = [] diff --git a/brewman/brewman/views/services/cost_center.py b/brewman/brewman/views/services/cost_center.py index dc5711c9..ed142d34 100644 --- a/brewman/brewman/views/services/cost_center.py +++ b/brewman/brewman/views/services/cost_center.py @@ -10,7 +10,7 @@ from brewman.models import DBSession from brewman.models.voucher import Voucher, Journal, VoucherType -@view_config(route_name='issues_grid', renderer='json', xhr=True) +@view_config(route_name='issues_grid', renderer='json', xhr=True, permission='Issue') def grid(request): date = request.matchdict.get('date', None) if date is None: diff --git a/brewman/brewman/views/services/ledger.py b/brewman/brewman/views/services/ledger.py index c020361b..deaf623e 100644 --- a/brewman/brewman/views/services/ledger.py +++ b/brewman/brewman/views/services/ledger.py @@ -1,16 +1,16 @@ from pyramid.view import view_config from brewman.models.master import LedgerBase, Employee, Ledger -@view_config(request_method='POST', route_name='services_account_list', renderer='json', xhr=True) -@view_config(request_method='POST', route_name='services_account_list_type', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='services_account_list', renderer='json', xhr=True, permission='Authenticated') +@view_config(request_method='POST', route_name='services_account_list_type', renderer='json', xhr=True, permission='Authenticated') def ledger_list_view_post(request): type = request.matchdict.get('type', None) filter = request.json_body.get('prefixText', None) return ledger_list(type, filter) -@view_config(request_method='GET', route_name='services_account_list', renderer='json', xhr=True) -@view_config(request_method='GET', route_name='services_account_list_type', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='services_account_list', renderer='json', xhr=True, permission='Authenticated') +@view_config(request_method='GET', route_name='services_account_list_type', renderer='json', xhr=True, permission='Authenticated') def ledger_list_view_get(request): type = request.matchdict.get('type', None) return ledger_list(type, None) @@ -23,12 +23,12 @@ def ledger_list(type=None, filter=None): return list -@view_config(request_method='POST', route_name='services_employee_list', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='services_employee_list', renderer='json', xhr=True, permission='Authenticated') def employee_list_view_post(request): filter = request.json_body.get('prefixText', None) return ledger_list(10, filter) -@view_config(request_method='GET', route_name='services_employee_list', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='services_employee_list', renderer='json', xhr=True, permission='Authenticated') def employee_list_view_get(request): - return employee_list(10, None) + return ledger_list(10, None) diff --git a/brewman/brewman/views/services/product.py b/brewman/brewman/views/services/product.py index 28ac6a27..4668d5dc 100644 --- a/brewman/brewman/views/services/product.py +++ b/brewman/brewman/views/services/product.py @@ -5,7 +5,7 @@ from pyramid.view import view_config from brewman.models.master import Product, ProductGroup -@view_config(request_method='POST', route_name='services_product_list', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='services_product_list', renderer='json', xhr=True, permission='Authenticated') def autocomplete_list(request): filter = request.json_body['prefixText'] list = [] @@ -14,7 +14,7 @@ def autocomplete_list(request): return list -@view_config(request_method='POST', route_name='services_products', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='services_products', renderer='json', xhr=True, permission='Authenticated') def list(request): productGroupID = request.json_body.get('productGroupID', None) page_size = int(request.json_body.get('page_size', 5000)) @@ -30,12 +30,4 @@ def list(request): list = [] for item in products: list.append({'id': str(item.id), 'label': item.name, 'price': str(item.purchase_price)}) - return list - - -@view_config(request_method='POST', route_name='services_product_rate', renderer='json', xhr=True) -def rate(request): - product = Product.by_full_name(request.json_body['productName']) - if product is None: - return None - return "{0:.2f}".format(product.purchase_price) + return list \ No newline at end of file diff --git a/brewman/brewman/views/services/session.py b/brewman/brewman/views/services/session.py index 44687638..4aca86b0 100644 --- a/brewman/brewman/views/services/session.py +++ b/brewman/brewman/views/services/session.py @@ -1,5 +1,4 @@ from datetime import date, timedelta -import json import uuid from pyramid.httpexceptions import HTTPFound from pyramid.response import Response @@ -9,12 +8,12 @@ from pyramid.view import view_config from brewman.models.auth import Role, User from brewman.views.transactions import session_current_date -@view_config(route_name='services_session_current_date', renderer='json', xhr=True) +@view_config(route_name='services_session_current_date', renderer='json', xhr=True, permission='Authenticated') def services_session_current_date(request): return session_current_date(request) -@view_config(route_name='services_session_period_start', renderer='json', xhr=True) +@view_config(route_name='services_session_period_start', renderer='json', xhr=True, permission='Authenticated') def services_session_period_start(request): session = request.session if 'periodStart' not in session: @@ -22,7 +21,7 @@ def services_session_period_start(request): return session['currentDate'] -@view_config(route_name='services_session_period_finish', renderer='json', xhr=True) +@view_config(route_name='services_session_period_finish', renderer='json', xhr=True, permission='Authenticated') def services_session_period_finish(request): session = request.session if 'periodFinish' not in session: @@ -30,26 +29,6 @@ def services_session_period_finish(request): return session['currentDate'] -@view_config(route_name='is_user_in_role', renderer='json', xhr=True) -def is_user_in_role(request): - id = request.matchdict.get('id', None) - session = request.session - perms = session['perms'] - if id in perms: - return True - return False - - -@view_config(route_name='is_user_in_roles', renderer='json', xhr=True) -def is_user_in_roles(request): - roles = [] - jsonRoles = request.json_body['roles'] - perms = request.session['perms'] - for item in jsonRoles: - roles.append({'Role': item, 'Allowed': (True if item in perms else False)}) - return roles - - @view_config(route_name='auth', renderer='json', xhr=True) def user_permission(request): user_id = authenticated_userid(request) diff --git a/brewman/brewman/views/services/voucher/__init__.py b/brewman/brewman/views/services/voucher/__init__.py index 8ac037cf..3fd70f14 100644 --- a/brewman/brewman/views/services/voucher/__init__.py +++ b/brewman/brewman/views/services/voucher/__init__.py @@ -11,12 +11,12 @@ from brewman.models.voucher import Voucher, VoucherType 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' -@view_config(request_method='POST', route_name='voucher', request_param='post', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='voucher', request_param='post', renderer='json', xhr=True, + permission='Post Vouchers') def voucher_post(request): user = User.get_by_id(uuid.UUID(authenticated_userid(request))) try: @@ -32,47 +32,6 @@ def voucher_post(request): return response -@view_config(request_method='POST', route_name='voucher', renderer='json', xhr=True) -def voucher_save(request): - id = request.matchdict.get('id', None) - user = User.get_by_id(uuid.UUID(authenticated_userid(request))) - - try: - """ update voucher """ - id = uuid.UUID(id) - if request.json_body['Type'] in ['Journal', 'Payment', 'Receipt']: - voucher = journal_update_voucher(id, request.json_body, user) - elif request.json_body['Type'] in ['Purchase']: - voucher = purchase_update_voucher(id, request.json_body, user) - elif request.json_body['Type'] in ['Issue']: - voucher = issue_update_voucher(id, request.json_body, user) - transaction.commit() - return voucher_info(Voucher.by_id(voucher.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='POST', route_name='voucher_new', renderer='json', xhr=True) -def voucher_save(request): - user = User.get_by_id(uuid.UUID(authenticated_userid(request))) - try: - """ new voucher """ - if request.json_body['Type'] in ['Journal', 'Payment', 'Receipt']: - voucher = journal_create_voucher(request.json_body, user) - elif request.json_body['Type'] in ['Purchase']: - voucher = purchase_create_voucher(request.json_body, user) - elif request.json_body['Type'] in ['Issue']: - voucher = issue_create_voucher(request.json_body, user) - transaction.commit() - return voucher_info(Voucher.by_id(voucher.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='voucher', renderer='json', xhr=True) def delete(request): id = request.matchdict.get('id', None) @@ -110,12 +69,6 @@ def delete(request): return blank_voucher(additionalInfo=json_voucher) -@view_config(request_method='GET', route_name='voucher_new', request_param='type', renderer='json', xhr=True) -def get_blank(request): - voucher_type = request.GET.get('type', None) - return blank_voucher(type=voucher_type, date=session_current_date(request)) - - @view_config(request_method='GET', route_name='voucher', renderer='json', xhr=True) def get_old(request): id = request.matchdict.get('id', None) diff --git a/brewman/brewman/views/services/voucher/blank_voucher.py b/brewman/brewman/views/services/voucher/blank_voucher.py new file mode 100644 index 00000000..9c0ebb54 --- /dev/null +++ b/brewman/brewman/views/services/voucher/blank_voucher.py @@ -0,0 +1,39 @@ +from pyramid.view import view_config, view_defaults +from brewman.views.services.voucher import blank_voucher +from brewman.views.transactions import session_current_date + +__author__ = 'tanshu' + + +@view_defaults(request_method='GET', route_name='voucher_new', renderer='json', xhr=True) +class blank_voucher_view(object): + def __init__(self, request): + self.request = request + + @view_config(request_param='type=Journal', permission='Journal') + def journal(self): + return self.get_blank() + + + @view_config(request_param='type=Payment', permission='Payment') + def payment(self): + return self.get_blank() + + + @view_config(request_param='type=Receipt', permission='Receipt') + def receipt(self): + return self.get_blank() + + + @view_config(request_param='type=Purchase', permission='Purchase') + def purchase(self): + return self.get_blank() + + + @view_config(request_param='type=Issue', permission='Issue') + def issue(self): + return self.get_blank() + + def get_blank(self): + voucher_type = self.request.GET.get('type', None) + return blank_voucher(type=voucher_type, date=session_current_date(self.request)) diff --git a/brewman/brewman/views/services/voucher/issue.py b/brewman/brewman/views/services/voucher/issue.py index e3d09980..85636e0d 100644 --- a/brewman/brewman/views/services/voucher/issue.py +++ b/brewman/brewman/views/services/voucher/issue.py @@ -67,8 +67,7 @@ def issue_create_journals(inventories, source, destination): cost_center_id=destination)] -def issue_update_voucher(id, json, user): - voucher = Voucher.by_id(id) +def issue_update_voucher(voucher, json, user): voucher.date = datetime.datetime.strptime(json['Date'], '%d-%b-%Y') voucher.narration = json['Narration'] voucher.user_id = user.id diff --git a/brewman/brewman/views/services/voucher/journal.py b/brewman/brewman/views/services/voucher/journal.py index c57aabdf..870478fe 100644 --- a/brewman/brewman/views/services/voucher/journal.py +++ b/brewman/brewman/views/services/voucher/journal.py @@ -22,8 +22,7 @@ def journal_create_voucher(json, user): return voucher -def journal_update_voucher(id, json, user): - voucher = Voucher.by_id(id) +def journal_update_voucher(voucher, json, user): voucher.date = datetime.datetime.strptime(json['Date'], '%d-%b-%Y') voucher.narration = json['Narration'] voucher.user_id = user.id diff --git a/brewman/brewman/views/services/voucher/purchase.py b/brewman/brewman/views/services/voucher/purchase.py index 5b6a1797..050f68ad 100644 --- a/brewman/brewman/views/services/voucher/purchase.py +++ b/brewman/brewman/views/services/voucher/purchase.py @@ -51,8 +51,7 @@ def purchase_create_journals(inventories, ledgerID): return list(journals.values()) -def purchase_update_voucher(id, json, user): - voucher = Voucher.by_id(id) +def purchase_update_voucher(voucher, json, user): voucher.date = datetime.datetime.strptime(json['Date'], '%d-%b-%Y') voucher.narration = json['Narration'] voucher.user_id = user.id @@ -144,7 +143,6 @@ def purchase_update_journals(voucher, journals): DBSession.delete(item) voucher.journals.remove(item) for item in journals: - print(item) DBSession.add(item) voucher.journals.append(item) diff --git a/brewman/brewman/views/services/voucher/save_voucher.py b/brewman/brewman/views/services/voucher/save_voucher.py new file mode 100644 index 00000000..c3353002 --- /dev/null +++ b/brewman/brewman/views/services/voucher/save_voucher.py @@ -0,0 +1,60 @@ +import uuid +from pyramid.response import Response +from pyramid.security import authenticated_userid +from pyramid.view import view_defaults, view_config +import transaction +from brewman.models.auth import User +from brewman.models.validation_exception import ValidationError +from brewman.models.voucher import Voucher +from brewman.views.services.voucher import voucher_info, journal_create_voucher, purchase_create_voucher, issue_create_voucher + +__author__ = 'tanshu' + + +@view_defaults(request_method='POST', route_name='voucher_new', renderer='json', xhr=True) +class save_voucher(object): + def __init__(self, request): + self.request = request + + @view_config(request_param='type=Journal', permission='Journal') + def journal(self): + return self.save() + + + @view_config(request_param='type=Payment', permission='Payment') + def payment(self): + return self.save() + + + @view_config(request_param='type=Receipt', permission='Receipt') + def receipt(self): + return self.save() + + + @view_config(request_param='type=Purchase', permission='Purchase') + def purchase(self): + return self.save() + + + @view_config(request_param='type=Issue', permission='Issue') + def issue(self): + return self.save() + + def save(self): + request = self.request + user = User.get_by_id(uuid.UUID(authenticated_userid(request))) + try: + """ new voucher """ + if request.json_body['Type'] in ['Journal', 'Payment', 'Receipt']: + voucher = journal_create_voucher(request.json_body, user) + elif request.json_body['Type'] in ['Purchase']: + voucher = purchase_create_voucher(request.json_body, user) + elif request.json_body['Type'] in ['Issue']: + voucher = issue_create_voucher(request.json_body, user) + transaction.commit() + return voucher_info(Voucher.by_id(voucher.id)) + except ValidationError as ex: + transaction.abort() + response = Response("Failed validation: {0}".format(ex.message)) + response.status_int = 500 + return response diff --git a/brewman/brewman/views/services/voucher/update_voucher.py b/brewman/brewman/views/services/voucher/update_voucher.py new file mode 100644 index 00000000..ed1b2818 --- /dev/null +++ b/brewman/brewman/views/services/voucher/update_voucher.py @@ -0,0 +1,65 @@ +import uuid +from pyramid.response import Response +from pyramid.security import authenticated_userid, has_permission, Denied +from pyramid.view import view_defaults, view_config +import transaction +from brewman.models.auth import User +from brewman.models.validation_exception import ValidationError +from brewman.models.voucher import Voucher +from brewman.views.services.voucher import voucher_info, issue_update_voucher, purchase_update_voucher, journal_update_voucher + +__author__ = 'tanshu' + + +@view_defaults(request_method='POST', route_name='voucher', renderer='json', xhr=True) +class update_voucher(object): + def __init__(self, request): + self.request = request + self.user = User.get_by_id(uuid.UUID(authenticated_userid(request))) + self.voucher = Voucher.by_id(uuid.UUID(request.matchdict.get('id', None))) + self.json = request.json_body + permission = Denied + + if self.voucher.posted: + permission = has_permisson('EditPosted', None, request) + + + @view_config(request_param='type=Journal', permission='Journal') + def journal(self): + return self.update() + + + @view_config(request_param='type=Payment', permission='Payment') + def payment(self): + return self.update() + + + @view_config(request_param='type=Receipt', permission='Receipt') + def receipt(self): + return self.update() + + + @view_config(request_param='type=Purchase', permission='Purchase') + def purchase(self): + return self.update() + + + @view_config(request_param='type=Issue', permission='Issue') + def issue(self): + return self.update() + + def update(self): + try: + if self.json['Type'] in ['Journal', 'Payment', 'Receipt']: + voucher = journal_update_voucher(self.voucher, self.json, self.user) + elif self.json['Type'] in ['Purchase']: + voucher = purchase_update_voucher(self.voucher, self.json, self.user) + elif self.json['Type'] in ['Issue']: + voucher = issue_update_voucher(self.voucher, self.json, self.user) + transaction.commit() + return voucher_info(Voucher.by_id(voucher.id)) + except ValidationError as ex: + transaction.abort() + response = Response("Failed validation: {0}".format(ex.message)) + response.status_int = 500 + return response diff --git a/brewman/brewman/views/transactions/__init__.py b/brewman/brewman/views/transactions/__init__.py index 420dbdef..a14951db 100644 --- a/brewman/brewman/views/transactions/__init__.py +++ b/brewman/brewman/views/transactions/__init__.py @@ -3,25 +3,25 @@ from pyramid.view import view_config @view_config(request_method='GET', route_name='journal_id', renderer='brewman:templates/angular_base.mako', - permission='Journal Update') + permission='Journal') @view_config(request_method='GET', route_name='journal', renderer='brewman:templates/angular_base.mako', - permission='Journal Create') + permission='Journal') @view_config(request_method='GET', route_name='payment_id', renderer='brewman:templates/angular_base.mako', - permission='Journal Update') + permission='Payment') @view_config(request_method='GET', route_name='payment', renderer='brewman:templates/angular_base.mako', - permission='Journal Create') + permission='Payment') @view_config(request_method='GET', route_name='receipt_id', renderer='brewman:templates/angular_base.mako', - permission='Receipt Update') + permission='Receipt') @view_config(request_method='GET', route_name='receipt', renderer='brewman:templates/angular_base.mako', - permission='Receipt Create') + permission='Receipt') @view_config(request_method='GET', route_name='purchase_id', renderer='brewman:templates/angular_base.mako', - permission='Purchase Update') + permission='Purchase') @view_config(request_method='GET', route_name='purchase', renderer='brewman:templates/angular_base.mako', - permission='Purchase Create') + permission='Purchase') @view_config(request_method='GET', route_name='issue_id', renderer='brewman:templates/angular_base.mako', - permission='Issue Update') + permission='Issue') @view_config(request_method='GET', route_name='issue', renderer='brewman:templates/angular_base.mako', - permission='Issue Create') + permission='Issue') def journal_get(request): return {} @@ -45,7 +45,3 @@ def session_current_date(request): if 'currentDate' not in session: session['currentDate'] = date.today().strftime('%d-%b-%Y') return session['currentDate'] - -def session_current_date_literal(request): - return Literal("$('#txtDate').val('{0}');".format(session_current_date(request))) -