From 27c97cbf88c8bea11a6290a064285c468a5f8a63 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Tue, 23 Oct 2012 17:09:55 +0530 Subject: [PATCH] Auth Group done. Employee done. ACL dynamically done. VoucherFactory to be done. --- Conversion/SqliteDB.txt | 1 + brewman/brewman/__init__.py | 18 +-- brewman/brewman/factories.py | 80 ++----------- brewman/brewman/security.py | 14 +++ .../static/partial/account-detail.html | 2 +- .../brewman/static/partial/account-list.html | 2 +- brewman/brewman/static/partial/cash-flow.html | 2 +- .../brewman/static/partial/closing-stock.html | 2 +- .../static/partial/cost-center-detail.html | 2 +- .../static/partial/cost-center-list.html | 2 +- brewman/brewman/static/partial/daybook.html | 2 +- .../static/partial/employee-detail.html | 2 +- .../brewman/static/partial/group-detail.html | 32 +++++ .../brewman/static/partial/group-list.html | 20 ++++ brewman/brewman/static/partial/issue.html | 2 +- brewman/brewman/static/partial/journal.html | 2 +- brewman/brewman/static/partial/ledger.html | 2 +- brewman/brewman/static/partial/payment.html | 2 +- .../static/partial/product-detail.html | 2 +- .../static/partial/product-group-detail.html | 2 +- .../static/partial/product-group-list.html | 2 +- .../static/partial/product-ledger.html | 2 +- .../brewman/static/partial/product-list.html | 2 +- .../brewman/static/partial/profit-loss.html | 2 +- .../static/partial/purchase-entries.html | 42 +++++++ brewman/brewman/static/partial/purchase.html | 2 +- .../partial/raw-material-cost-detail.html | 2 +- .../static/partial/raw-material-cost.html | 2 +- brewman/brewman/static/partial/receipt.html | 2 +- .../brewman/static/partial/trial-balance.html | 2 +- brewman/brewman/static/partial/unposted.html | 2 +- .../brewman/static/partial/user-detail.html | 2 +- brewman/brewman/static/partial/user-list.html | 2 +- .../static/scripts/angular_directive.js | 41 +++++++ .../brewman/static/scripts/angular_service.js | 13 +++ brewman/brewman/static/scripts/group.js | 27 +++++ brewman/brewman/static/scripts/group_roles.js | 42 ------- brewman/brewman/static/scripts/overlord.js | 7 +- .../static/scripts/purchase-entries.js | 15 +++ brewman/brewman/static/scripts/user_groups.js | 42 ------- brewman/brewman/templates/angular_base.mako | 2 + brewman/brewman/templates/nav_bar/login.pt | 26 +---- brewman/brewman/templates/nav_bar/report.mako | 4 +- brewman/brewman/views/account.py | 20 ++-- brewman/brewman/views/auth/group.py | 109 ++++++++++++++++++ brewman/brewman/views/auth/group_roles.py | 75 ------------ brewman/brewman/views/auth/user.py | 103 ++++++++++------- brewman/brewman/views/cost_center.py | 18 +-- brewman/brewman/views/employee.py | 18 +-- brewman/brewman/views/product.py | 24 ++-- brewman/brewman/views/product_group.py | 20 ++-- .../brewman/views/reports/purchase_entries.py | 57 +++++++++ .../views/services/voucher/__init__.py | 15 --- 53 files changed, 531 insertions(+), 406 deletions(-) create mode 100644 brewman/brewman/static/partial/group-detail.html create mode 100644 brewman/brewman/static/partial/group-list.html create mode 100644 brewman/brewman/static/partial/purchase-entries.html create mode 100644 brewman/brewman/static/scripts/group.js delete mode 100644 brewman/brewman/static/scripts/group_roles.js create mode 100644 brewman/brewman/static/scripts/purchase-entries.js delete mode 100644 brewman/brewman/static/scripts/user_groups.js create mode 100644 brewman/brewman/views/auth/group.py delete mode 100644 brewman/brewman/views/auth/group_roles.py create mode 100644 brewman/brewman/views/reports/purchase_entries.py diff --git a/Conversion/SqliteDB.txt b/Conversion/SqliteDB.txt index e79b7ff8..d0198d9c 100644 --- a/Conversion/SqliteDB.txt +++ b/Conversion/SqliteDB.txt @@ -1,3 +1,4 @@ +UPDATE Auth_Roles Set Name = 'Users' WHERE Name = 'CreateUser' --update entities_ledgers set code = code + 60 where type = 13; -- to prevent duplicate code when converting UPDATE entities_ledgers SET type = 11 WHERE type = 13; DROP TABLE Entities_Taxes; diff --git a/brewman/brewman/__init__.py b/brewman/brewman/__init__.py index a0fd606e..57a5e630 100644 --- a/brewman/brewman/__init__.py +++ b/brewman/brewman/__init__.py @@ -54,10 +54,18 @@ def main(global_config, **settings): config.add_route('account', '/Account') config.add_route('account_list', '/Accounts') + config.add_route('employee_id', '/Employee/{id}') + config.add_route('employee', '/Employee') + config.add_route('employee_list', '/Employees') + config.add_route('user_id', '/User/{id}') config.add_route('user', '/User') config.add_route('user_list', '/Users') + config.add_route('group_id', '/Group/{id}') + config.add_route('group', '/Group') + config.add_route('group_list', '/Groups') + config.add_route('product_id', '/Product/{id}') config.add_route('product', '/Product') config.add_route('product_list', '/Products') @@ -66,16 +74,11 @@ def main(global_config, **settings): config.add_route('product_group', '/ProductGroup') config.add_route('product_group_list', '/ProductGroups') - config.add_route('employee_attendance_save', '/Employee/Attendance/Save') config.add_route('employee_attendance', '/Employee/Attendance') - config.add_route('employee_id', '/Employee/{id}') - config.add_route('employee_attendance_id', '/Employee/{id}/Attendance') - config.add_route('employee', '/Employee') - config.add_route('employee_list', '/Employees') config.add_route('attendance_save', '/Attendance/Save') config.add_route('attendance_date', '/Attendance/{date}') config.add_route('attendance', '/Attendance') @@ -115,10 +118,7 @@ def main(global_config, **settings): config.add_route('daybook', '/Daybook') config.add_route('unposted', '/Unposted') config.add_route('profit_loss', '/ProfitLoss') - - config.add_route('group_roles_id', '/Admin/GroupRoles/{id}') - config.add_route('group_roles', '/Admin/GroupRoles') - config.add_route('save_group_roles', '/Admin/GroupRolesSave') + config.add_route('purchase_entries', '/PurchaseEntries') config.add_route('services_session_current_date', '/Services/CurrentDate') config.add_route('services_session_period_start', '/Services/PeriodStart') diff --git a/brewman/brewman/factories.py b/brewman/brewman/factories.py index a732590c..13bad604 100644 --- a/brewman/brewman/factories.py +++ b/brewman/brewman/factories.py @@ -1,77 +1,17 @@ from pyramid.security import Everyone from pyramid.security import Authenticated from pyramid.security import Allow +from brewman.models.auth import Role class RootFactory(object): - __acl__ = [ - (Allow, Everyone, 'view'), - (Allow, Authenticated, 'post'), - (Allow, 'Attendance', 'Attendance'), - (Allow, 'BalanceSheet', 'BalanceSheet'), - (Allow, 'Cash Flow', 'Cash Flow'), - (Allow, 'CostCenter', 'CostCenter'), - (Allow, 'CostCenterCreate', 'CostCenterCreate'), - (Allow, 'CostCenterDelete', 'CostCenterDelete'), - (Allow, 'CostCenterRetrieve', 'CostCenterRetrieve'), - (Allow, 'CostCenterUpdate', 'CostCenterUpdate'), - (Allow, 'CreateUser', 'CreateUser'), - (Allow, 'DayBook', 'DayBook'), - (Allow, 'EditPosted', 'EditPosted'), - (Allow, 'Employees', 'Employees'), - (Allow, 'EmployeesCreate', 'EmployeesCreate'), - (Allow, 'EmployeesDelete', 'EmployeesDelete'), - (Allow, 'EmployeesRetrieve', 'EmployeesRetrieve'), - (Allow, 'EmployeesUpdate', 'EmployeesUpdate'), - (Allow, 'Finger Prints', 'Finger Prints'), - (Allow, 'Issue', 'Issue'), - (Allow, 'Issue Create', 'Issue Create'), - (Allow, 'Issue Delete', 'Issue Delete'), - (Allow, 'Issue Post', 'Issue Post'), - (Allow, 'Issue Update', 'Issue Update'), - (Allow, 'Journal', 'Journal'), - (Allow, 'Journal Create', 'Journal Create'), - (Allow, 'Journal Delete', 'Journal Delete'), - (Allow, 'Journal Post', 'Journal Post'), - (Allow, 'Journal Update', 'Journal Update'), - (Allow, 'Ledgers', 'Ledgers'), - (Allow, 'LedgersCreate', 'LedgersCreate'), - (Allow, 'LedgersDelete', 'LedgersDelete'), - (Allow, 'LedgersRetrieve', 'LedgersRetrieve'), - (Allow, 'LedgersUpdate', 'LedgersUpdate'), - (Allow, 'ManageRoles', 'ManageRoles'), - (Allow, 'OldTransactions', 'OldTransactions'), - (Allow, 'Payment', 'Payment'), - (Allow, 'Payment Create', 'Payment Create'), - (Allow, 'Payment Delete', 'Payment Delete'), - (Allow, 'Payment Post', 'Payment Post'), - (Allow, 'Payment Update', 'Payment Update'), - (Allow, 'PostTransactions', 'PostTransactions'), - (Allow, 'Products', 'Products'), - (Allow, 'ProductsCreate', 'ProductsCreate'), - (Allow, 'ProductsDelete', 'ProductsDelete'), - (Allow, 'ProductsRetrieve', 'ProductsRetrieve'), - (Allow, 'ProductsUpdate', 'ProductsUpdate'), - (Allow, 'ProfitAndLoss', 'ProfitAndLoss'), - (Allow, 'Purchase', 'Purchase'), - (Allow, 'Purchase Create', 'Purchase Create'), - (Allow, 'Purchase Delete', 'Purchase Delete'), - (Allow, 'Purchase Post', 'Purchase Post'), - (Allow, 'Purchase Update', 'Purchase Update'), - (Allow, 'PurchaseReturn', 'PurchaseReturn'), - (Allow, 'PurchaseReturn Create', 'PurchaseReturn Create'), - (Allow, 'PurchaseReturn Delete', 'PurchaseReturn Delete'), - (Allow, 'PurchaseReturn Post', 'PurchaseReturn Post'), - (Allow, 'PurchaseReturn Update', 'PurchaseReturn Update'), - (Allow, 'Receipt', 'Receipt'), - (Allow, 'Receipt Create', 'Receipt Create'), - (Allow, 'Receipt Delete', 'Receipt Delete'), - (Allow, 'Receipt Post', 'Receipt Post'), - (Allow, 'Receipt Update', 'Receipt Update'), - (Allow, 'Verification', 'Verification'), - (Allow, 'Verification Create', 'Verification Create'), - (Allow, 'Verification Delete', 'Verification Delete'), - (Allow, 'Verification Post', 'Verification Post'), - (Allow, 'Verification Update', 'Verification Update') - ] + @property + def __acl__(self): + acl = [ + (Allow, Everyone, 'view'), + (Allow, Authenticated, 'post')] + for permission in Role.list(): + acl.append((Allow, permission.name, permission.name)) + print(acl) + return acl def __init__(self, request): pass \ No newline at end of file diff --git a/brewman/brewman/security.py b/brewman/brewman/security.py index 4d79c26c..1148c044 100644 --- a/brewman/brewman/security.py +++ b/brewman/brewman/security.py @@ -1,6 +1,19 @@ import uuid +from pyramid.security import Allow, ALL_PERMISSIONS from brewman.models.auth import User +class VoucherFactory(object): + __acl__ = [] + + def __init__(self, request): + self.request = request + + def __getitem__(self, key): + user = USERS[key] + user.__parent__ = self + user.__name__ = key + return user + def groupfinder(user_id, request): perms = [] if 'perms' in request.session: @@ -12,6 +25,7 @@ def groupfinder(user_id, request): perms.append(perm.name) perms = f7(perms) request.session['perms'] = perms + print(perms) return perms diff --git a/brewman/brewman/static/partial/account-detail.html b/brewman/brewman/static/partial/account-detail.html index baf3f151..f4fd02b7 100644 --- a/brewman/brewman/static/partial/account-detail.html +++ b/brewman/brewman/static/partial/account-detail.html @@ -1,4 +1,4 @@ -
+ Account Detail
diff --git a/brewman/brewman/static/partial/account-list.html b/brewman/brewman/static/partial/account-list.html index 9b3b9fdb..d6fde246 100644 --- a/brewman/brewman/static/partial/account-list.html +++ b/brewman/brewman/static/partial/account-list.html @@ -1,5 +1,5 @@ Accounts Add - +
diff --git a/brewman/brewman/static/partial/cash-flow.html b/brewman/brewman/static/partial/cash-flow.html index 99dee542..1f80f12a 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 4316a32a..d56061c9 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/cost-center-detail.html b/brewman/brewman/static/partial/cost-center-detail.html index a416c29a..eb93f822 100644 --- a/brewman/brewman/static/partial/cost-center-detail.html +++ b/brewman/brewman/static/partial/cost-center-detail.html @@ -1,4 +1,4 @@ - + Cost Center Detail
diff --git a/brewman/brewman/static/partial/cost-center-list.html b/brewman/brewman/static/partial/cost-center-list.html index c15220ef..af78549d 100644 --- a/brewman/brewman/static/partial/cost-center-list.html +++ b/brewman/brewman/static/partial/cost-center-list.html @@ -1,5 +1,5 @@ Cost Centers Add -
Name
+
diff --git a/brewman/brewman/static/partial/daybook.html b/brewman/brewman/static/partial/daybook.html index 595934f7..a75ce83d 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-detail.html b/brewman/brewman/static/partial/employee-detail.html index df819f6e..8dbf9995 100644 --- a/brewman/brewman/static/partial/employee-detail.html +++ b/brewman/brewman/static/partial/employee-detail.html @@ -1,4 +1,4 @@ - + Employee Detail
diff --git a/brewman/brewman/static/partial/group-detail.html b/brewman/brewman/static/partial/group-detail.html new file mode 100644 index 00000000..9bcb07c9 --- /dev/null +++ b/brewman/brewman/static/partial/group-detail.html @@ -0,0 +1,32 @@ + + Group Detail +
+ + +
+ +
+
+ +
+ + +
+
    +
  • + +
  • + +
+ +
+
+
+ +
+ +
+
+ diff --git a/brewman/brewman/static/partial/group-list.html b/brewman/brewman/static/partial/group-list.html new file mode 100644 index 00000000..92cb4008 --- /dev/null +++ b/brewman/brewman/static/partial/group-list.html @@ -0,0 +1,20 @@ +Users Add +
Name
+ + + + + + + + + + + + +
NameGroups
{{item.Name}} +
    +
  • {{permission}}
  • +
+
+ diff --git a/brewman/brewman/static/partial/issue.html b/brewman/brewman/static/partial/issue.html index 4fbddf73..8d09c002 100644 --- a/brewman/brewman/static/partial/issue.html +++ b/brewman/brewman/static/partial/issue.html @@ -1,5 +1,5 @@

Issue Edit / New

-
+
diff --git a/brewman/brewman/static/partial/journal.html b/brewman/brewman/static/partial/journal.html index ba5c1967..aa4bc03d 100644 --- a/brewman/brewman/static/partial/journal.html +++ b/brewman/brewman/static/partial/journal.html @@ -1,4 +1,4 @@ - +
diff --git a/brewman/brewman/static/partial/ledger.html b/brewman/brewman/static/partial/ledger.html index 5637b076..8eb6575b 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/payment.html b/brewman/brewman/static/partial/payment.html index 806cb23d..7e32ad73 100644 --- a/brewman/brewman/static/partial/payment.html +++ b/brewman/brewman/static/partial/payment.html @@ -1,4 +1,4 @@ - +
diff --git a/brewman/brewman/static/partial/product-detail.html b/brewman/brewman/static/partial/product-detail.html index 29615839..ca86b74b 100644 --- a/brewman/brewman/static/partial/product-detail.html +++ b/brewman/brewman/static/partial/product-detail.html @@ -1,4 +1,4 @@ - + Product Detail
diff --git a/brewman/brewman/static/partial/product-group-detail.html b/brewman/brewman/static/partial/product-group-detail.html index 7621ab73..83b021f5 100644 --- a/brewman/brewman/static/partial/product-group-detail.html +++ b/brewman/brewman/static/partial/product-group-detail.html @@ -1,4 +1,4 @@ - + Product Group Detail
diff --git a/brewman/brewman/static/partial/product-group-list.html b/brewman/brewman/static/partial/product-group-list.html index 247f4835..38cf4445 100644 --- a/brewman/brewman/static/partial/product-group-list.html +++ b/brewman/brewman/static/partial/product-group-list.html @@ -1,5 +1,5 @@ Product Groups Add - +
diff --git a/brewman/brewman/static/partial/product-ledger.html b/brewman/brewman/static/partial/product-ledger.html index e2df291b..c97cb38f 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/product-list.html b/brewman/brewman/static/partial/product-list.html index 59c300d8..5d673c0a 100644 --- a/brewman/brewman/static/partial/product-list.html +++ b/brewman/brewman/static/partial/product-list.html @@ -1,5 +1,5 @@ Products Add -
Name
+
diff --git a/brewman/brewman/static/partial/profit-loss.html b/brewman/brewman/static/partial/profit-loss.html index d67a7299..53fac021 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 new file mode 100644 index 00000000..b9c93826 --- /dev/null +++ b/brewman/brewman/static/partial/purchase-entries.html @@ -0,0 +1,42 @@ + + Purchase Entries +
+ + +
+ + + +
+
+
+ + +
+
Code
+ + + + + + + + + + + + + + + + + + + + + + +
DateSupplierProductQuantityRateTaxAmount
{{items.Date}}{{items.Supplier}}{{item.Product}}{{item.Quantity}}{{item.Rate}}{{item.Tax}}{{item.Amount}}
+
+
+ diff --git a/brewman/brewman/static/partial/purchase.html b/brewman/brewman/static/partial/purchase.html index 7188afdb..e84cda03 100644 --- a/brewman/brewman/static/partial/purchase.html +++ b/brewman/brewman/static/partial/purchase.html @@ -1,5 +1,5 @@

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 1f0e71aa..c0a957ed 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 39c12143..1fe784e6 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/receipt.html b/brewman/brewman/static/partial/receipt.html index be356da2..de0dd15f 100644 --- a/brewman/brewman/static/partial/receipt.html +++ b/brewman/brewman/static/partial/receipt.html @@ -1,4 +1,4 @@ - +
diff --git a/brewman/brewman/static/partial/trial-balance.html b/brewman/brewman/static/partial/trial-balance.html index 431d8f8d..839b2267 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 a0d95bda..9fcf37bb 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/partial/user-detail.html b/brewman/brewman/static/partial/user-detail.html index bb239c5e..630038b5 100644 --- a/brewman/brewman/static/partial/user-detail.html +++ b/brewman/brewman/static/partial/user-detail.html @@ -1,4 +1,4 @@ - + User Detail
diff --git a/brewman/brewman/static/partial/user-list.html b/brewman/brewman/static/partial/user-list.html index 35e96635..7b616a21 100644 --- a/brewman/brewman/static/partial/user-list.html +++ b/brewman/brewman/static/partial/user-list.html @@ -1,5 +1,5 @@ Users Add - +
diff --git a/brewman/brewman/static/scripts/angular_directive.js b/brewman/brewman/static/scripts/angular_directive.js index f5015920..4781accf 100644 --- a/brewman/brewman/static/scripts/angular_directive.js +++ b/brewman/brewman/static/scripts/angular_directive.js @@ -126,3 +126,44 @@ overlord_directive.directive('fadey', function () { }; return directiveDefinitionObject; }); + + +(function (angular) { + /* + * Defines the ng:if tag. This is useful if jquery mobile does not allow + * an ng-switch element in the dom, e.g. between ul and li. + */ + var ngIfDirective = { + transclude:'element', + priority:1000, + terminal:true, + compile:function (element, attr, linker) { + return function (scope, iterStartElement, attr) { + iterStartElement[0].doNotMove = true; + var expression = attr.ngmIf; + var lastElement; + var lastScope; + scope.$watch(expression, function (newValue) { + if (lastElement) { + lastElement.remove(); + lastElement = null; + } + lastScope && lastScope.$destroy(); + if (newValue) { + lastScope = scope.$new(); + linker(lastScope, function (clone) { + lastElement = clone; + iterStartElement.after(clone); + }); + } + // Note: need to be parent() as jquery cannot trigger events on comments + // (angular creates a comment node when using transclusion, as ng-repeat does). + iterStartElement.parent().trigger("$childrenChanged"); + }); + }; + } + }; + overlord_directive.directive('ngmIf', function () { + return ngIfDirective; + }); +})(angular); \ No newline at end of file diff --git a/brewman/brewman/static/scripts/angular_service.js b/brewman/brewman/static/scripts/angular_service.js index 55e5f6d4..611fdf9c 100644 --- a/brewman/brewman/static/scripts/angular_service.js +++ b/brewman/brewman/static/scripts/angular_service.js @@ -65,6 +65,14 @@ overlord_service.factory('User', ['$resource', function ($resource) { }); }]); +// TODO: Replace hardcoded url with route_url +overlord_service.factory('Group', ['$resource', function ($resource) { + return $resource('/Group/:id', + {id:'@GroupID'}, { + query:{method:'GET', params:{list:true}, isArray:true} + }); +}]); + // TODO: Replace hardcoded url with route_url overlord_service.factory('Product', ['$resource', function ($resource) { return $resource('/Product/:id', @@ -120,6 +128,11 @@ overlord_service.factory('ProfitLoss', ['$resource', function ($resource) { return $resource('/ProfitLoss'); }]); +// TODO: Replace hardcoded url with route_url +overlord_service.factory('PurchaseEntries', ['$resource', function ($resource) { + return $resource('/PurchaseEntries'); +}]); + // TODO: Replace hardcoded url with route_url overlord_service.factory('RawMaterialCost', ['$resource', function ($resource) { return $resource('/RawMaterialCost/:id'); diff --git a/brewman/brewman/static/scripts/group.js b/brewman/brewman/static/scripts/group.js new file mode 100644 index 00000000..9de9c6fa --- /dev/null +++ b/brewman/brewman/static/scripts/group.js @@ -0,0 +1,27 @@ +function GroupListCtrl($scope, Group) { + $scope.info = Group.query(); +} + +function GroupCtrl($scope, $routeParams, $location, Group) { + $scope.group = Group.get({id: $routeParams.id}); + + $scope.save = function () { + $scope.group.$save(function (u, putResponseHeaders) { + $scope.toasts.push({Type:'Success', Message:u.Code}); + $location.path('/Groups') + }, function (data, status) { + $scope.toasts.push({Type:'Error', Message:data.data}); + }); + }; + + $scope.delete = function () { + $scope.group.$delete(function (u, putResponseHeaders) { + $scope.toasts.push({Type:'Success', Message:''}); + $location.path('/Groups') + }, function (data, status) { + $scope.toasts.push({Type:'Error', Message:data.data}); + }); + }; + $('#txtName').focus(); + +} diff --git a/brewman/brewman/static/scripts/group_roles.js b/brewman/brewman/static/scripts/group_roles.js deleted file mode 100644 index b0f4f44e..00000000 --- a/brewman/brewman/static/scripts/group_roles.js +++ /dev/null @@ -1,42 +0,0 @@ -function Populate(response) { - if (response != null) { - var stateObj = { 'group_id':response.group_id }; - history.pushState(stateObj, 'Display', response.url); - $('#ddlGroup').val(response.group_id); - $('#tbodyMain').html(response.body); - } -} - -function Show(group_id) { - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - data:JSON.stringify({ group_id:group_id }), - dataType:"json", - success:function (response) { - Populate(response); - }, - error:function (jqXHR, textStatus) { - $("#ctl00_statusDiv").removeClass().addClass("error"); - var msg = $.parseJSON(jqXHR.responseText).Message; - $("#ctl00_statusDiv").html(msg); - } - }); - return false; -} - -function GetFormData() { - var selected_roles = new Array(); - var group_id = $("#ddlGroup").val(); - $("tr.Entry").each(function () { - $this = $(this); - var role_id = $this.find("td.RoleID").html(); - var checkbox = $this.find("input[type=checkbox]").attr('checked'); - checkbox = (typeof checkbox == 'undefined') ? false : true; - selected_roles.push({ 'role_id':role_id, 'selected':checkbox }); - }); - return JSON.stringify({group_id:group_id, selected_roles:selected_roles}); -} - -function ResetForm() {} - diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index a0738587..b34fe2b6 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -38,6 +38,7 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte 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('/TrialBalance', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}). when('/TrialBalance/:date', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}). @@ -67,7 +68,11 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte 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('/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}); // .otherwise({redirectTo: '/phones'}); $locationProvider.html5Mode(true); }]) diff --git a/brewman/brewman/static/scripts/purchase-entries.js b/brewman/brewman/static/scripts/purchase-entries.js new file mode 100644 index 00000000..f115e08c --- /dev/null +++ b/brewman/brewman/static/scripts/purchase-entries.js @@ -0,0 +1,15 @@ +function PurchaseEntriesCtrl($scope, $routeParams, $location, PurchaseEntries) { + if (typeof $routeParams.StartDate === 'undefined') { + $scope.info = PurchaseEntries.get({}); + } else { + $scope.info = PurchaseEntries.get({StartDate:$routeParams.StartDate, FinishDate:$routeParams.FinishDate}); + } + $scope.show = function () { + $scope.info = PurchaseEntries.get({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate}, function (u, putResponseHeaders) { + $location.path('/PurchaseEntries').search({StartDate:u.StartDate, FinishDate:u.FinishDate}); + }, function (data, status) { + $scope.toasts.push({Type:'Error', Message:data.data}); + }); + }; + $('#txtStartDate').focus(); +} diff --git a/brewman/brewman/static/scripts/user_groups.js b/brewman/brewman/static/scripts/user_groups.js deleted file mode 100644 index 064e8280..00000000 --- a/brewman/brewman/static/scripts/user_groups.js +++ /dev/null @@ -1,42 +0,0 @@ -function Populate(response) { - if (response != null) { - var stateObj = { 'user_id':response.user_id }; - history.pushState(stateObj, 'Display', response.url); - $('#ddlUser').val(response.user_id); - $('#tbodyMain').html(response.body); - } -} - -function Show(user_id) { - $.ajax({ - type:"POST", - contentType:"application/json; charset=utf-8", - data:JSON.stringify({ user_id:user_id }), - dataType:"json", - success:function (response) { - Populate(response); - }, - error:function (jqXHR, textStatus) { - $("#ctl00_statusDiv").removeClass().addClass("error"); - var msg = $.parseJSON(jqXHR.responseText).Message; - $("#ctl00_statusDiv").html(msg); - } - }); - return false; -} - -function GetFormData() { - var selected_groups = new Array(); - var user_id = $("#ddlUser").val(); - $("tr.Entry").each(function () { - $this = $(this); - var group_id = $this.find("td.GroupID").html(); - var checkbox = $this.find("input[type=checkbox]").attr('checked'); - checkbox = (typeof checkbox == 'undefined') ? false : true; - selected_groups.push({ 'group_id':group_id, 'selected':checkbox }); - }); - return JSON.stringify({user_id:user_id, selected_groups:selected_groups}); -} - -function ResetForm() {} - diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index 37fca3c5..0f1c7c25 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -45,6 +45,7 @@ ${h.ScriptLink(request, 'trial-balance.js')} ${h.ScriptLink(request, 'closing-stock.js')} ${h.ScriptLink(request, 'profit-loss.js')} + ${h.ScriptLink(request, 'purchase-entries.js')} ${h.ScriptLink(request, 'cash-flow.js')} ${h.ScriptLink(request, 'raw-material-cost.js')} ${h.ScriptLink(request, 'daybook.js')} @@ -53,6 +54,7 @@ ${h.ScriptLink(request, 'account.js')} ${h.ScriptLink(request, 'employee.js')} ${h.ScriptLink(request, 'user.js')} + ${h.ScriptLink(request, 'group.js')} ${h.ScriptLink(request, 'cost-center.js')} ${h.ScriptLink(request, 'product.js')} ${h.ScriptLink(request, 'product-group.js')} diff --git a/brewman/brewman/templates/nav_bar/login.pt b/brewman/brewman/templates/nav_bar/login.pt index bbbf29c7..370ba061 100644 --- a/brewman/brewman/templates/nav_bar/login.pt +++ b/brewman/brewman/templates/nav_bar/login.pt @@ -3,8 +3,8 @@ @@ -13,30 +13,8 @@ - - -
  • ${user.name} - -
  • - - -
  • Home - -
  • -
    \ No newline at end of file diff --git a/brewman/brewman/templates/nav_bar/report.mako b/brewman/brewman/templates/nav_bar/report.mako index d2057c7d..d6d35bf8 100644 --- a/brewman/brewman/templates/nav_bar/report.mako +++ b/brewman/brewman/templates/nav_bar/report.mako @@ -8,18 +8,16 @@
  • Purchases
  • Final Reports
  • diff --git a/brewman/brewman/views/account.py b/brewman/brewman/views/account.py index aa9189c9..279e4b17 100644 --- a/brewman/brewman/views/account.py +++ b/brewman/brewman/views/account.py @@ -7,17 +7,17 @@ import transaction from brewman.models.master import CostCenter, Ledger, LedgerType from brewman.models.validation_exception import ValidationError -@view_config(route_name='account_list', renderer='brewman:templates/angular_base.mako') +@view_config(route_name='account_list', renderer='brewman:templates/angular_base.mako', permission='Accounts') @view_config(request_method='GET', route_name='account_id', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Accounts') @view_config(request_method='GET', route_name='account', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Accounts') def html(request): return {} -@view_config(request_method='POST', route_name='account_id', renderer='json', xhr=True) -@view_config(request_method='POST', route_name='account', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='account_id', renderer='json', xhr=True, permission='Accounts') +@view_config(request_method='POST', route_name='account', renderer='json', xhr=True, permission='Accounts') def save_update(request): try: id = request.matchdict.get('id', None) @@ -42,7 +42,7 @@ def save_update(request): return response -@view_config(request_method='DELETE', route_name='account_id', renderer='json', xhr=True) +@view_config(request_method='DELETE', route_name='account_id', renderer='json', xhr=True, permission='Accounts') def delete(request): id = request.matchdict.get('id', None) if id is None: @@ -55,17 +55,17 @@ def delete(request): return response -@view_config(request_method='GET', route_name='account_id', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='account_id', renderer='json', xhr=True, permission='Accounts') def show_id(request): return account_info(uuid.UUID(request.matchdict.get('id', None))) -@view_config(request_method='GET', route_name='account', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='account', renderer='json', xhr=True, permission='Accounts') def show_blank(request): return account_info(None) -@view_config(request_method='GET', route_name='account', renderer='json', request_param='list', xhr=True) +@view_config(request_method='GET', route_name='account', renderer='json', request_param='list', xhr=True, permission='Accounts') def show_list(request): list = Ledger.list() ledgers = [] @@ -75,7 +75,7 @@ def show_list(request): return ledgers -@view_config(request_method='GET', route_name='account_type_list', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='account_type_list', renderer='json', xhr=True, permission='Accounts') def account_type_list(request): account_types = [] for item in LedgerType.list(): diff --git a/brewman/brewman/views/auth/group.py b/brewman/brewman/views/auth/group.py new file mode 100644 index 00000000..93e892c0 --- /dev/null +++ b/brewman/brewman/views/auth/group.py @@ -0,0 +1,109 @@ +import uuid + +from pyramid.view import view_config +import transaction +from brewman.models import DBSession +from brewman.models.auth import Group, Role +from brewman.models.validation_exception import ValidationError + +@view_config(route_name='group_list', renderer='brewman:templates/angular_base.mako', permission='Users') +@view_config(request_method='GET', route_name='group_id', renderer='brewman:templates/angular_base.mako', + xhr=False, permission='Users') +@view_config(request_method='GET', route_name='group', renderer='brewman:templates/angular_base.mako', + xhr=False, permission='Users') +def html(request): + return {} + + +@view_config(request_method='POST', route_name='group', renderer='json', xhr=True, permission='Users') +def save(request): + try: + group = Group(request.json_body['Name']) + DBSession.add(group) + add_permissions(group, request.json_body['Permissions']) + transaction.commit() + return group_info(group.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='group_id', renderer='json', xhr=True, permission='Users') +def update(request): + try: + id = request.matchdict.get('id', None) + group = Group.get_by_id(uuid.UUID(id)) + group.name = request.json_body['Name'] + add_permissions(group, request.json_body['Permissions']) + transaction.commit() + return group_info(group.id) + except ValidationError as ex: + transaction.abort() + response = Response("Failed validation: {0}".format(ex.message)) + response.status_int = 500 + return response + + +def add_permissions(group, permissions): + for permission in permissions: + id = uuid.UUID(permission['PermissionID']) + gp = [p for p in group.roles if p.id == id] + gp = None if len(gp) == 0 else gp[0] + if permission['Enabled'] and gp is None: + group.roles.append(Role.get_by_id(id)) + elif not permission['Enabled'] and gp: + group.roles.remove(gp) + + +@view_config(request_method='DELETE', route_name='group_id', renderer='json', xhr=True, permission='Users') +def delete(request): + id = request.matchdict.get('id', None) + if id is None: + response = Response("Group is Null") + response.status_int = 500 + return response + else: + response = Response("Group deletion not implemented") + response.status_int = 500 + return response + + +@view_config(request_method='GET', route_name='group_id', renderer='json', xhr=True, permission='Users') +def show_id(request): + return group_info(uuid.UUID(request.matchdict.get('id', None))) + + +@view_config(request_method='GET', route_name='group', renderer='json', xhr=True, permission='Users') +def show_blank(request): + return group_info(None) + + +@view_config(request_method='GET', route_name='group', renderer='json', request_param='list', xhr=True, permission='Users') +def show_list(request): + list = Group.list() + groups = [] + for item in list: + group = {'Name': item.name, 'Permissions': [], 'Url': request.route_url('group_id', id=item.id)} + for permission in item.roles: + group['Permissions'].append(permission.name) + groups.append(group) + return groups + + +def group_info(id): + if id is None: + 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': []} + for item in Role.list(): + group['Permissions'].append( + {'PermissionID': item.id, 'Name': item.name, 'Enabled': True if item in group_object.roles else False}) + return group + + diff --git a/brewman/brewman/views/auth/group_roles.py b/brewman/brewman/views/auth/group_roles.py deleted file mode 100644 index 7bcc8de5..00000000 --- a/brewman/brewman/views/auth/group_roles.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, Role - -@view_config(request_method='GET', route_name='group_roles', permission='ManageRoles', - renderer='brewman:templates/auth/group_roles.pt') -@view_config(request_method='GET', route_name='group_roles_id', permission='ManageRoles', - renderer='brewman:templates/auth/group_roles.pt') -def group_roles_get(request): - id = request.matchdict.get('id', None) - id = None if id is None else uuid.UUID(id) - group = SelectInput('ddlGroup', list=Group.list(), displayField='name', valueField='id', defaultValue=id) - body, footer = build_report(request, id) - body = Literal(body) - footer = Literal(footer) - - return {'title': 'Group Roles', - 'pageclass': "page-blogpost page-sidebar-right", - 'pagecontentclass': "page-content grid_12", - 'page_header': '', - 'group': group, - 'body': body, - 'footer': footer} - - -@view_config(request_method='POST', route_name='group_roles', permission='ManageRoles', renderer='json', xhr=True) -@view_config(request_method='POST', route_name='group_roles_id', permission='ManageRoles', renderer='json', xhr=True) -def group_roles_post(request): - id = request.json_body['group_id'] - body, footer = build_report(request, uuid.UUID(id)) - url = request.route_url('group_roles_id', id=id) - return {'group_id': id, - 'url': url, - 'body': body} - - -@view_config(request_method='POST', route_name='save_group_roles', permission='ManageRoles', renderer='json', xhr=True) -def group_roles_save(request): - id = request.json_body['group_id'] - group = Group.get_by_id(uuid.UUID(id)) - for item in request.json_body['selected_roles']: - role = Role.get_by_id(uuid.UUID(item['role_id'])) - selected = item['selected'] - if selected and role not in group.roles: - group.roles.append(role) - elif not selected and role in group.roles: - group.roles.remove(role) - transaction.commit() - return 'Roles Updated' - - -def build_report(request, id): - body = '' - if id is None: - for item in Role.list(): - body += ''\ - .format(str(item.id), item.name) - else: - group = Group.get_by_id(id) - for item in Role.list(): - if item in group.roles: - checked = ' checked="checked"' - else: - checked = '' - body += ''\ - .format(str(item.id), item.name, checked) - footer = '' - return body, footer - - diff --git a/brewman/brewman/views/auth/user.py b/brewman/brewman/views/auth/user.py index 148af4ff..19f94f35 100644 --- a/brewman/brewman/views/auth/user.py +++ b/brewman/brewman/views/auth/user.py @@ -8,38 +8,21 @@ 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(route_name='user_list', renderer='brewman:templates/angular_base.mako', permission='Users') @view_config(request_method='GET', route_name='user_id', renderer='brewman:templates/angular_base.mako', - xhr=False, permission='ManageRoles') + xhr=False, permission='Users') @view_config(request_method='GET', route_name='user', renderer='brewman:templates/angular_base.mako', - xhr=False, permission='ManageRoles') + xhr=False, permission='Users') 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): +@view_config(request_method='POST', route_name='user', renderer='json', xhr=True, permission='Users') +def save(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) + user = User(request.json_body['Name'], request.json_body['Password'], request.json_body['LockedOut']) + DBSession.add(user) + add_groups(user, request.json_body['Groups']) transaction.commit() return user_info(user.id) except ValidationError as ex: @@ -49,7 +32,37 @@ def save_update(request): return response -@view_config(request_method='DELETE', route_name='user_id', renderer='json', xhr=True, permission='CreateUser') +@view_config(request_method='POST', route_name='user_id', renderer='json', xhr=True, permission='Users') +def update(request): + try: + id = request.matchdict.get('id', None) + 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'] + add_groups(user, request.json_body['Groups']) + 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 + + +def add_groups(user, groups): + for group in groups: + 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) + + +@view_config(request_method='DELETE', route_name='user_id', renderer='json', xhr=True, permission='Users') def delete(request): id = request.matchdict.get('id', None) if id is None: @@ -62,25 +75,27 @@ def delete(request): 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) +@view_config(request_method='GET', route_name='user_id', renderer='json', xhr=True, permission='Users') +def show_id(request): + return user_info(uuid.UUID(request.matchdict.get('id', 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) + +@view_config(request_method='GET', route_name='user', renderer='json', xhr=True, permission='Users') +def show_blank(request): + return user_info(None) + + +@view_config(request_method='GET', route_name='user', renderer='json', request_param='list', xhr=True, permission='Users') +def show_list(request): + 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 def user_info(id): diff --git a/brewman/brewman/views/cost_center.py b/brewman/brewman/views/cost_center.py index 411a2e65..6e5e30e1 100644 --- a/brewman/brewman/views/cost_center.py +++ b/brewman/brewman/views/cost_center.py @@ -8,17 +8,17 @@ 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') +@view_config(route_name='cost_center_list', renderer='brewman:templates/angular_base.mako', permission='Cost Centers') @view_config(request_method='GET', route_name='cost_center_id', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Cost Centers') @view_config(request_method='GET', route_name='cost_center', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Cost Centers') def html(request): return {} -@view_config(request_method='POST', route_name='cost_center_id', renderer='json', xhr=True) -@view_config(request_method='POST', route_name='cost_center', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='cost_center_id', renderer='json', xhr=True, permission='Cost Centers') +@view_config(request_method='POST', route_name='cost_center', renderer='json', xhr=True, permission='Cost Centers') def save_update(request): try: id = request.matchdict.get('id', None) @@ -36,7 +36,7 @@ def save_update(request): return response -@view_config(request_method='DELETE', route_name='cost_center_id', renderer='json', xhr=True) +@view_config(request_method='DELETE', route_name='cost_center_id', renderer='json', xhr=True, permission='Cost Centers') def delete(request): id = request.matchdict.get('id', None) if id is None: @@ -48,17 +48,17 @@ def delete(request): response.status_int = 500 return response -@view_config(request_method='GET', route_name='cost_center_id', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='cost_center_id', renderer='json', xhr=True, permission='Cost Centers') def show_id(request): return cost_center_info(uuid.UUID(request.matchdict.get('id', None))) -@view_config(request_method='GET', route_name='cost_center', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='cost_center', renderer='json', xhr=True, permission='Cost Centers') def show_blank(request): return cost_center_info(None) -@view_config(request_method='GET', route_name='cost_center', request_param='list', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='cost_center', request_param='list', renderer='json', xhr=True, permission='Cost Centers') def show_list(request): list = CostCenter.list() cost_centers = [] diff --git a/brewman/brewman/views/employee.py b/brewman/brewman/views/employee.py index bbc1c35e..e1a6b99e 100644 --- a/brewman/brewman/views/employee.py +++ b/brewman/brewman/views/employee.py @@ -13,17 +13,17 @@ from brewman.models.master import CostCenter, Employee, AttendanceType from brewman.models.validation_exception import ValidationError from brewman.models.voucher import Attendance -@view_config(route_name='employee_list', renderer='brewman:templates/angular_base.mako') +@view_config(route_name='employee_list', renderer='brewman:templates/angular_base.mako', permission='Employees') @view_config(request_method='GET', route_name='employee_id', renderer='brewman:templates/angular_base.mako', xhr=False, - permission='EmployeesUpdate') + permission='Employees') @view_config(request_method='GET', route_name='employee', renderer='brewman:templates/angular_base.mako', xhr=False, - permission='EmployeesUpdate') + permission='Employees') def html(request): return {} -@view_config(request_method='POST', route_name='employee_id', renderer='json', xhr=True, permission='EmployeesUpdate') -@view_config(request_method='POST', route_name='employee', renderer='json', xhr=True, permission='EmployeesUpdate') +@view_config(request_method='POST', route_name='employee_id', renderer='json', xhr=True, permission='Employees') +@view_config(request_method='POST', route_name='employee', renderer='json', xhr=True, permission='Employees') def save_update(request): try: id = request.matchdict.get('id', None) @@ -56,7 +56,7 @@ def save_update(request): return response -@view_config(request_method='DELETE', route_name='employee_id', renderer='json', xhr=True) +@view_config(request_method='DELETE', route_name='employee_id', renderer='json', xhr=True, permission='Employees') def delete(request): id = request.matchdict.get('id', None) if id is None: @@ -69,17 +69,17 @@ def delete(request): return response -@view_config(request_method='GET', route_name='employee_id', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='employee_id', renderer='json', xhr=True, permission='Employees') def show_id(request): return employee_info(uuid.UUID(request.matchdict.get('id', None))) -@view_config(request_method='GET', route_name='employee', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='employee', renderer='json', xhr=True, permission='Employees') def show_blank(request): return employee_info(None) -@view_config(request_method='GET', route_name='employee', request_param='list', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='employee', request_param='list', renderer='json', xhr=True, permission='Employees') def show_list(request): list = Employee.list() ledgers = [] diff --git a/brewman/brewman/views/product.py b/brewman/brewman/views/product.py index 2eeb6680..969fca33 100644 --- a/brewman/brewman/views/product.py +++ b/brewman/brewman/views/product.py @@ -9,15 +9,15 @@ from brewman.models.validation_exception import ValidationError @view_config(route_name='product_list', renderer='brewman:templates/angular_base.mako', permission='Products') @view_config(request_method='GET', route_name='product_id', renderer='brewman:templates/angular_base.mako', - xhr=False, permission='ProductsUpdate') + xhr=False, permission='Products') @view_config(request_method='GET', route_name='product', renderer='brewman:templates/angular_base.mako', - xhr=False, permission='ProductsUpdate') + xhr=False, permission='Products') def html(request): return {} -@view_config(request_method='POST', route_name='product_id', renderer='json', xhr=True) -@view_config(request_method='POST', route_name='product', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='product_id', renderer='json', xhr=True, permission='Products') +@view_config(request_method='POST', route_name='product', renderer='json', xhr=True, permission='Products') def save_update(request): try: id = request.matchdict.get('id', None) @@ -48,7 +48,7 @@ def save_update(request): return response -@view_config(request_method='DELETE', route_name='product_id', renderer='json', xhr=True) +@view_config(request_method='DELETE', route_name='product_id', renderer='json', xhr=True, permission='Products') def delete(request): id = request.matchdict.get('id', None) if id is None: @@ -61,17 +61,17 @@ def delete(request): return response -@view_config(request_method='GET', route_name='product_id', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='product_id', renderer='json', xhr=True, permission='Products') def show_id(request): return product_info(uuid.UUID(request.matchdict.get('id', None))) -@view_config(request_method='GET', route_name='product', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='product', renderer='json', xhr=True, permission='Products') def show_blank(request): return product_info(None) -@view_config(request_method='GET', route_name='product', request_param='list', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='product', request_param='list', renderer='json', xhr=True, permission='Products') def show_list(request): list = Product.query().order_by(Product.discontinued).order_by(Product.product_group_id).order_by( Product.name).all() @@ -83,14 +83,6 @@ def show_list(request): return products -@view_config(request_method='GET', route_name='product_group_list', renderer='json', xhr=True) -def product_group_list(request): - product_groups = [] - for item in ProductGroup.list(): - product_groups.append({'ProductGroupID': item.id, 'Name': item.name}) - return product_groups - - def product_info(id): if id is None: product = {'Code': '(Auto)', 'Type': LedgerType.by_name('Creditors').id, 'IsActive': True, diff --git a/brewman/brewman/views/product_group.py b/brewman/brewman/views/product_group.py index a2711c42..06f843a4 100644 --- a/brewman/brewman/views/product_group.py +++ b/brewman/brewman/views/product_group.py @@ -9,17 +9,17 @@ 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') +@view_config(route_name='product_group_list', renderer='brewman:templates/angular_base.mako', permission='Product Groups') @view_config(request_method='GET', route_name='product_group_id', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Product Groups') @view_config(request_method='GET', route_name='product_group', renderer='brewman:templates/angular_base.mako', - xhr=False) + xhr=False, permission='Product Groups') def html(request): return {} -@view_config(request_method='POST', route_name='product_group_id', renderer='json', xhr=True) -@view_config(request_method='POST', route_name='product_group', renderer='json', xhr=True) +@view_config(request_method='POST', route_name='product_group_id', renderer='json', xhr=True, permission='Product Groups') +@view_config(request_method='POST', route_name='product_group', renderer='json', xhr=True, permission='Product Groups') def save_update(request): try: id = request.matchdict.get('id', None) @@ -38,7 +38,7 @@ def save_update(request): return response -@view_config(request_method='DELETE', route_name='product_group_id', renderer='json', xhr=True) +@view_config(request_method='DELETE', route_name='product_group_id', renderer='json', xhr=True, permission='Product Groups') def delete(request): id = request.matchdict.get('id', None) if id is None: @@ -50,17 +50,17 @@ def delete(request): response.status_int = 500 return response -@view_config(request_method='GET', route_name='product_group_id', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='product_group_id', renderer='json', xhr=True, permission='Product Groups') def show_id(request): return product_group_info(uuid.UUID(request.matchdict.get('id', None))) -@view_config(request_method='GET', route_name='product_group', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='product_group', renderer='json', xhr=True, permission='Product Groups') def show_blank(request): return product_group_info(None) -@view_config(request_method='GET', route_name='product_group', request_param='list', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='product_group', request_param='list', renderer='json', xhr=True, permission='Product Groups') def show_list(request): list = ProductGroup.list() product_groups = [] @@ -73,8 +73,6 @@ def product_group_info(id): if id is None: return {} else: - product_group = ProductGroup.by_id(id) - product_group = ProductGroup.by_id(id) product_group = ProductGroup.by_id(id) return {'ProductGroupID': product_group.id, 'Name': product_group.name} diff --git a/brewman/brewman/views/reports/purchase_entries.py b/brewman/brewman/views/reports/purchase_entries.py new file mode 100644 index 00000000..2c3cfef1 --- /dev/null +++ b/brewman/brewman/views/reports/purchase_entries.py @@ -0,0 +1,57 @@ +import datetime +from sqlalchemy.sql.expression import func, desc + +from pyramid.view import view_config + +from brewman.models import DBSession +from brewman.models.master import CostCenter, LedgerType, LedgerBase + +from brewman.models.voucher import Voucher, Journal, VoucherType, Inventory +from brewman.views.services.session import services_session_period_start, services_session_period_finish +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): + return {} + + +@view_config(request_method='GET', route_name='purchase_entries', renderer='json', xhr=True) +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) +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) + + +def build_report(request, start_date, finish_date): + report = {'StartDate': start_date, 'FinishDate': finish_date, 'Body': []} + start_date = datetime.datetime.strptime(start_date, '%d-%b-%Y') + finish_date = datetime.datetime.strptime(finish_date, '%d-%b-%Y') + + query = DBSession.query(Voucher)\ + .filter(Voucher.date >= start_date)\ + .filter(Voucher.date <= finish_date)\ + .filter(Voucher.type == VoucherType.by_name('Purchase').id)\ + .order_by(Voucher.date).all() + + for voucher in query: + journal = [j for j in voucher.journals if j.debit == -1] + journal = journal[0] + row = {'Date': voucher.date.strftime('%d-%b-%Y'), 'Supplier': journal.ledger.name, + 'Url': get_edit_url(request, voucher), 'Products': []} + for item in voucher.inventories: + row['Products'].append( + {'Product': item.product.full_name, 'Quantity': item.quantity, 'Rate': item.rate, 'Tax': item.tax, + 'Amount': item.amount}) + report['Body'].append(row) + return report + + diff --git a/brewman/brewman/views/services/voucher/__init__.py b/brewman/brewman/views/services/voucher/__init__.py index b1dc6e99..8ac037cf 100644 --- a/brewman/brewman/views/services/voucher/__init__.py +++ b/brewman/brewman/views/services/voucher/__init__.py @@ -122,21 +122,6 @@ def get_old(request): return voucher_info(Voucher.by_id(uuid.UUID(id))) -#@view_config(request_method='GET', route_name='voucher_new', renderer='json', xhr=True) -#@view_config(request_method='GET', route_name='voucher', renderer='json', xhr=True) -#def get_old(request): -# id = request.matchdict.get('id', None) -# voucher_type = request.GET.get('type', None) -# 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 - - def voucher_info(voucher): json_voucher = {'VoucherID': voucher.id, 'Date': voucher.date.strftime('%d-%b-%Y'),
    Name
    {0}'\ - '
    {0}'\ - '