From eb8568b47117bc1789effda9f40dec2271c0e80f Mon Sep 17 00:00:00 2001 From: Tanshu Date: Fri, 12 Oct 2012 02:30:36 +0530 Subject: [PATCH] Dropped many columns for Prodct Table. Merged product and account menu on page top. Product working now. --- Conversion/SqliteDB.txt | 24 +++ brewman/brewman/__init__.py | 1 + brewman/brewman/helpers.py | 2 +- brewman/brewman/models/master.py | 28 ++-- .../static/partial/account-detail.html | 2 +- .../brewman/static/partial/account-list.html | 2 +- .../static/partial/cost-center-list.html | 2 +- .../static/partial/product-detail.html | 88 +++++++++++ .../brewman/static/partial/product-list.html | 21 +++ .../brewman/static/partial/user-detail.html | 2 +- brewman/brewman/static/partial/user-list.html | 3 +- brewman/brewman/static/scripts/account.js | 6 +- .../brewman/static/scripts/angular_service.js | 13 ++ .../brewman/static/scripts/autocomplete.js | 7 + brewman/brewman/static/scripts/cost-center.js | 2 +- brewman/brewman/static/scripts/journal.js | 1 - brewman/brewman/static/scripts/product.js | 91 +++-------- brewman/brewman/static/scripts/user.js | 4 +- brewman/brewman/templates/angular_base.mako | 4 +- brewman/brewman/templates/base.mako | 8 +- .../brewman/templates/nav_bar/account.mako | 10 -- brewman/brewman/templates/nav_bar/master.mako | 9 ++ brewman/brewman/templates/nav_bar/product.pt | 9 -- brewman/brewman/templates/product/list.pt | 38 ----- brewman/brewman/views/account.py | 4 +- brewman/brewman/views/auth/user.py | 6 +- brewman/brewman/views/cost_center.py | 4 +- brewman/brewman/views/nav_bar.py | 7 +- brewman/brewman/views/product.py | 149 ++++++++++-------- 29 files changed, 312 insertions(+), 235 deletions(-) create mode 100644 brewman/brewman/static/partial/product-detail.html create mode 100644 brewman/brewman/static/partial/product-list.html delete mode 100644 brewman/brewman/templates/nav_bar/account.mako create mode 100644 brewman/brewman/templates/nav_bar/master.mako delete mode 100644 brewman/brewman/templates/nav_bar/product.pt delete mode 100644 brewman/brewman/templates/product/list.pt diff --git a/Conversion/SqliteDB.txt b/Conversion/SqliteDB.txt index 4ac792ab..f135a9fa 100644 --- a/Conversion/SqliteDB.txt +++ b/Conversion/SqliteDB.txt @@ -16,3 +16,27 @@ CREATE TABLE "Entities_Ledgers" ("LedgerID" guid NOT NULL, "Code" integer NOT NU INSERT INTO "Entities_Ledgers" SELECT "LedgerID", "Code", "Name", "Type", '', "IsActive", "CostCenterID" FROM "Entities_Ledgers_old"; UPDATE "Entities_Ledgers" SET ledger_type = 'employees' where type = 10; DROP TABLE "Entities_Ledgers_old"; + +ALTER TABLE "Entities_Products" RENAME TO "Entities_Products_old"; +CREATE TABLE [Entities_Products] ( + "ProductID" guid NOT NULL, + "Code" integer NOT NULL, + "Name" nvarchar(150) NOT NULL COLLATE NOCASE, + "Units" nvarchar(50) NOT NULL COLLATE NOCASE, + "Fraction" numeric NOT NULL, + "FractionUnits" nvarchar(255) NOT NULL COLLATE NOCASE, + "Yeild" numeric NOT NULL, + "ShowForPurchase" bit NOT NULL, + "Price" numeric, + "Discontinued" bit NOT NULL, + "ProductGroupID" guid, + "LedgerID" guid, + PRIMARY KEY ([ProductID]) +, + FOREIGN KEY ([LedgerID]) + REFERENCES [Entities_Ledgers]([LedgerID]), + FOREIGN KEY ([ProductGroupID]) + REFERENCES [Entities_ProductGroups]([ProductGroupID]) +); +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"; diff --git a/brewman/brewman/__init__.py b/brewman/brewman/__init__.py index 8911c3a1..ac50dbb5 100644 --- a/brewman/brewman/__init__.py +++ b/brewman/brewman/__init__.py @@ -135,6 +135,7 @@ def main(global_config, **settings): config.add_route('user_permissions', '/Permissions') config.add_route('account_type_list', '/AccountTypes') + config.add_route('product_group_list', '/ProductGroups') config.add_route('services_batch_list', '/Services/Batches') config.add_route('services_batch_add_inventory', '/Services/AddBatch') diff --git a/brewman/brewman/helpers.py b/brewman/brewman/helpers.py index 2cc48566..dc2f5170 100644 --- a/brewman/brewman/helpers.py +++ b/brewman/brewman/helpers.py @@ -1,6 +1,6 @@ import string -from brewman.views.nav_bar import login_menu, report_menu, voucher_menu, entry_menu, employee_menu, account_menu, product_menu +from brewman.views.nav_bar import login_menu, report_menu, voucher_menu, entry_menu, employee_menu, master_menu class Form(object): """Make absolute URL from the relative one. diff --git a/brewman/brewman/models/master.py b/brewman/brewman/models/master.py index 927fae67..e60f6c5d 100644 --- a/brewman/brewman/models/master.py +++ b/brewman/brewman/models/master.py @@ -19,26 +19,18 @@ class Product(Base): yeild = Column('Yeild', Numeric) show_for_purchase = Column('ShowForPurchase', Boolean) product_group_id = Column('ProductGroupID', GUID(), ForeignKey('entities_productgroups.ProductGroupID')) - sale_ledger_id = Column('SaleLedgerID', GUID(), ForeignKey('entities_ledgers.LedgerID')) - sale_tax_id = Column('SaleTaxID', GUID(), ForeignKey('entities_taxes.TaxID')) - sale_price = Column('SalePrice', Numeric) - purchase_ledger_id = Column('PurchaseLedgerID', GUID(), ForeignKey('entities_ledgers.LedgerID')) - purchase_tax_id = Column('PurchaseTaxID', GUID(), ForeignKey('entities_taxes.TaxID')) - purchase_price = Column('PurchasePrice', Numeric) + ledger_id = Column('LedgerID', GUID(), ForeignKey('entities_ledgers.LedgerID')) + price = Column('Price', Numeric) discontinued = Column('Discontinued', Boolean) batches = relationship('Batch', backref='product') inventories = relationship('Inventory', backref='product') - sale_ledger = relationship('Ledger', primaryjoin="Ledger.id==Product.sale_ledger_id") - sale_tax = relationship('Tax', primaryjoin="Tax.id==Product.sale_tax_id") - purchase_ledger = relationship('Ledger', primaryjoin="Ledger.id==Product.purchase_ledger_id") - purchase_tax = relationship('Tax', primaryjoin="Tax.id==Product.purchase_tax_id") + ledger = relationship('Ledger', primaryjoin="Ledger.id==Product.ledger_id") def __init__(self, code=None, name=None, units=None, fraction=None, fraction_units=None, yeild=None, - show_for_purchase=None, product_group_id=None, sale_ledger_id=None, sale_tax_id=None, sale_price=None, - purchase_ledger_id=None, purchase_tax_id=None, purchase_price=None, discontinued=None): + show_for_purchase=None, product_group_id=None, ledger_id=None, price=None, discontinued=None): self.code = code self.name = name self.units = units @@ -47,12 +39,8 @@ class Product(Base): self.yeild = yeild self.show_for_purchase = show_for_purchase self.product_group_id = product_group_id - self.sale_ledger_id = sale_ledger_id - self.sale_tax_id = sale_tax_id - self.sale_price = sale_price - self.purchase_ledger_id = purchase_ledger_id - self.purchase_tax_id = purchase_tax_id - self.purchase_price = purchase_price + self.ledger_id = ledger_id + self.price = price self.discontinued = discontinued @property @@ -94,6 +82,10 @@ class ProductGroup(Base): def __init__(self, name=None): self.name = name + @classmethod + def list(cls): + return DBSession.query(cls).order_by(cls.name) + class CostCenter(Base): __tablename__ = 'entities_costcenters' diff --git a/brewman/brewman/static/partial/account-detail.html b/brewman/brewman/static/partial/account-detail.html index 4bfaec5b..599794bd 100644 --- a/brewman/brewman/static/partial/account-detail.html +++ b/brewman/brewman/static/partial/account-detail.html @@ -28,7 +28,7 @@
diff --git a/brewman/brewman/static/partial/account-list.html b/brewman/brewman/static/partial/account-list.html index 60dd286f..9b3b9fdb 100644 --- a/brewman/brewman/static/partial/account-list.html +++ b/brewman/brewman/static/partial/account-list.html @@ -1,4 +1,4 @@ -Accounts +Accounts Add diff --git a/brewman/brewman/static/partial/cost-center-list.html b/brewman/brewman/static/partial/cost-center-list.html index cd7d96d4..c15220ef 100644 --- a/brewman/brewman/static/partial/cost-center-list.html +++ b/brewman/brewman/static/partial/cost-center-list.html @@ -1,4 +1,4 @@ -Cost Centers +Cost Centers Add
diff --git a/brewman/brewman/static/partial/product-detail.html b/brewman/brewman/static/partial/product-detail.html new file mode 100644 index 00000000..29615839 --- /dev/null +++ b/brewman/brewman/static/partial/product-detail.html @@ -0,0 +1,88 @@ + + Product Detail +
+ + +
+ +
+
+
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+ + +
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+
+ + +
+ + +
+
+ +
+ +
+ +
+
+ diff --git a/brewman/brewman/static/partial/product-list.html b/brewman/brewman/static/partial/product-list.html new file mode 100644 index 00000000..59c300d8 --- /dev/null +++ b/brewman/brewman/static/partial/product-list.html @@ -0,0 +1,21 @@ +Products Add +
+ + + + + + + + + + + + + + + + + + +
CodeNamePriceTypeDiscontinued
{{item.Code}}{{item.Name}} ({{item.Units}})₹ {{item.Price}}{{item.ProductGroup}}{{item.Discontinued}}
diff --git a/brewman/brewman/static/partial/user-detail.html b/brewman/brewman/static/partial/user-detail.html index 2fd06dce..bb239c5e 100644 --- a/brewman/brewman/static/partial/user-detail.html +++ b/brewman/brewman/static/partial/user-detail.html @@ -20,7 +20,7 @@
diff --git a/brewman/brewman/static/partial/user-list.html b/brewman/brewman/static/partial/user-list.html index 955e8ba2..35e96635 100644 --- a/brewman/brewman/static/partial/user-list.html +++ b/brewman/brewman/static/partial/user-list.html @@ -1,4 +1,4 @@ -Accounts +Users Add @@ -19,3 +19,4 @@
+ diff --git a/brewman/brewman/static/scripts/account.js b/brewman/brewman/static/scripts/account.js index d6008b3c..5a4ae1ba 100644 --- a/brewman/brewman/static/scripts/account.js +++ b/brewman/brewman/static/scripts/account.js @@ -2,7 +2,7 @@ $scope.info = Account.query(); } -function AccountCtrl($scope, $routeParams, Account, AccountType, CostCenter) { +function AccountCtrl($scope, $routeParams, $location, Account, AccountType, CostCenter) { $scope.account = Account.get({id: $routeParams.id}); $scope.account_types = AccountType.query(); @@ -11,6 +11,7 @@ function AccountCtrl($scope, $routeParams, Account, AccountType, CostCenter) { $scope.save = function () { $scope.account.$save(function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:u.Code}); + $location.path('/Accounts') }, function (data, status) { $scope.toasts.push({Type:'Error', Message:data.data}); }); @@ -19,10 +20,11 @@ function AccountCtrl($scope, $routeParams, Account, AccountType, CostCenter) { $scope.delete = function () { $scope.account.$delete(function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:''}); + $location.path('/Accounts') }, function (data, status) { $scope.toasts.push({Type:'Error', Message:data.data}); }); }; - $('#txtLedger').focus(); + $('#txtName').focus(); } diff --git a/brewman/brewman/static/scripts/angular_service.js b/brewman/brewman/static/scripts/angular_service.js index 2371b571..c727badf 100644 --- a/brewman/brewman/static/scripts/angular_service.js +++ b/brewman/brewman/static/scripts/angular_service.js @@ -119,3 +119,16 @@ overlord_service.factory('User', ['$resource', function ($resource) { }); }]); +// TODO: Replace hardcoded url with route_url +overlord_service.factory('Product', ['$resource', function ($resource) { + return $resource('/Product/:id', + {id:'@ProductID'}, { + query:{method:'GET', params:{list:true}, isArray:true} + }); +}]); + +// TODO: Replace hardcoded url with route_url +overlord_service.factory('ProductGroup', ['$resource', function ($resource) { + return $resource('/ProductGroups'); +}]); + diff --git a/brewman/brewman/static/scripts/autocomplete.js b/brewman/brewman/static/scripts/autocomplete.js index 53fa8412..8a7c8275 100644 --- a/brewman/brewman/static/scripts/autocomplete.js +++ b/brewman/brewman/static/scripts/autocomplete.js @@ -5,12 +5,19 @@ when('/Journal/:id', {templateUrl: '/partial/journal.html', controller: JournalCtrl}). 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('/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('/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}); // .otherwise({redirectTo: '/phones'}); $locationProvider.html5Mode(true); diff --git a/brewman/brewman/static/scripts/cost-center.js b/brewman/brewman/static/scripts/cost-center.js index ea3748f8..f369e403 100644 --- a/brewman/brewman/static/scripts/cost-center.js +++ b/brewman/brewman/static/scripts/cost-center.js @@ -22,6 +22,6 @@ function CostCenterCtrl($scope, $routeParams, $location, CostCenter) { $scope.toasts.push({Type:'Error', Message:data.data}); }); }; - $('#txtLedger').focus(); + $('#txtName').focus(); } diff --git a/brewman/brewman/static/scripts/journal.js b/brewman/brewman/static/scripts/journal.js index 5a3020bf..985c133c 100644 --- a/brewman/brewman/static/scripts/journal.js +++ b/brewman/brewman/static/scripts/journal.js @@ -2,7 +2,6 @@ if (typeof $routeParams.id === 'undefined'){ $scope.voucher = Voucher.get({type:'Journal'}); } else { - console.log('getting voucher' + $routeParams.id) $scope.voucher = Voucher.get({id:$routeParams.id}); } diff --git a/brewman/brewman/static/scripts/product.js b/brewman/brewman/static/scripts/product.js index a81d79ef..771aebde 100644 --- a/brewman/brewman/static/scripts/product.js +++ b/brewman/brewman/static/scripts/product.js @@ -1,73 +1,28 @@ -function GetProducts(productGroupID, page) { - if (productGroupID == -1) { - productGroupID = product_group_id; - } - product_group_id = productGroupID; - if (page == 0) { - page = 1; - } - else { - page = product_page + page; - if (page < 1){ - page = 1 - } - } - product_page = page; - $.ajax({ - type:"POST", - url:products_route, - contentType:"application/json; charset=utf-8", - data:JSON.stringify({ productGroupID:productGroupID, page_size:product_page_size, page:page }), - dataType:"json", - success:function (response) { - var rows = ""; - $.each(response, function (index, row) { - rows += "
  • "; - }) - - $("#products").html(rows); - }, - error:ShowError - }); - return false; +function ProductListCtrl($scope, Product) { + $scope.info = Product.query(); } +function ProductCtrl($scope, $routeParams, $location, Product, ProductGroup) { + $scope.product = Product.get({id:$routeParams.id}); + $scope.product_groups = ProductGroup.query(); -function GetProductGroups(page) { - if (page == 0) { - page = 1; - } - else { - page = product_group_page + page; - if (page < 1){ - page = 1 - } - } - product_group_page = page; - $.ajax({ - type:"POST", - url:product_groups_route, - contentType:"application/json; charset=utf-8", - data:JSON.stringify({ page_size:product_group_page_size, page:page }), - dataType:"json", - success:function (response) { - var rows = ""; - $.each(response, function (index, row) { - rows += "
  • "; - }) + $scope.save = function () { + $scope.product.$save(function (u, putResponseHeaders) { + $scope.toasts.push({Type:'Success', Message:u.Code}); + $location.path('/Products') + }, function (data, status) { + $scope.toasts.push({Type:'Error', Message:data.data}); + }); + }; + + $scope.delete = function () { + $scope.product.$delete(function (u, putResponseHeaders) { + $scope.toasts.push({Type:'Success', Message:''}); + $location.path('/Products') + }, function (data, status) { + $scope.toasts.push({Type:'Error', Message:data.data}); + }); + }; + $('#txtName').focus(); - $("#product_groups").html(rows); - }, - error:function (jqXHR, textStatus) { - var msg = jqXHR.responseText; - $("#status").append('
    Error! ' + msg + '
    '); - } - }); - return false; } - -function ShowError(jqXHR, textStatus) { - var msg = jqXHR.responseText; - $("#status").append('
    Error! ' + msg + '
    '); - -} \ No newline at end of file diff --git a/brewman/brewman/static/scripts/user.js b/brewman/brewman/static/scripts/user.js index 6a531152..b0e513ae 100644 --- a/brewman/brewman/static/scripts/user.js +++ b/brewman/brewman/static/scripts/user.js @@ -2,12 +2,13 @@ $scope.info = User.query(); } -function UserCtrl($scope, $routeParams, User) { +function UserCtrl($scope, $routeParams, $location, User) { $scope.user = User.get({id: $routeParams.id}); $scope.save = function () { $scope.user.$save(function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:u.Code}); + $location.path('/Users') }, function (data, status) { $scope.toasts.push({Type:'Error', Message:data.data}); }); @@ -16,6 +17,7 @@ function UserCtrl($scope, $routeParams, User) { $scope.delete = function () { $scope.user.$delete(function (u, putResponseHeaders) { $scope.toasts.push({Type:'Success', Message:''}); + $location.path('/Users') }, function (data, status) { $scope.toasts.push({Type:'Error', Message:data.data}); }); diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index 509341ea..1a614926 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -42,6 +42,7 @@ ${h.ScriptLink(request, 'account.js')} ${h.ScriptLink(request, 'user.js')} ${h.ScriptLink(request, 'cost-center.js')} + ${h.ScriptLink(request, 'product.js')} @@ -75,8 +76,7 @@ ${h.report_menu(request) | n } ${h.entry_menu(request) | n } ${h.employee_menu(request) | n } - ${h.account_menu(request) | n } - ${h.product_menu(request) | n } + ${h.master_menu(request) | n } ${h.login_menu(request) | n } diff --git a/brewman/brewman/templates/base.mako b/brewman/brewman/templates/base.mako index c1563aa9..4d2ad08d 100644 --- a/brewman/brewman/templates/base.mako +++ b/brewman/brewman/templates/base.mako @@ -35,8 +35,13 @@ ${h.ScriptLink(request, 'angular_filter.js')} ${h.ScriptLink(request, 'angular_service.js')} ${h.ScriptLink(request, 'session.js')} + + ${h.ScriptLink(request, 'journal.js')} + ${h.ScriptLink(request, 'account.js')} ${h.ScriptLink(request, 'user.js')} + ${h.ScriptLink(request, 'cost-center.js')} + ${h.ScriptLink(request, 'product.js')} <%block name="header" /> @@ -72,8 +77,7 @@ ${h.report_menu(request) | n } ${h.entry_menu(request) | n } ${h.employee_menu(request) | n } - ${h.account_menu(request) | n } - ${h.product_menu(request) | n } + ${h.master_menu(request) | n } ${h.login_menu(request) | n } diff --git a/brewman/brewman/templates/nav_bar/account.mako b/brewman/brewman/templates/nav_bar/account.mako deleted file mode 100644 index b6e7ac03..00000000 --- a/brewman/brewman/templates/nav_bar/account.mako +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/brewman/brewman/templates/nav_bar/master.mako b/brewman/brewman/templates/nav_bar/master.mako new file mode 100644 index 00000000..88969496 --- /dev/null +++ b/brewman/brewman/templates/nav_bar/master.mako @@ -0,0 +1,9 @@ + diff --git a/brewman/brewman/templates/nav_bar/product.pt b/brewman/brewman/templates/nav_bar/product.pt deleted file mode 100644 index 409ed5e2..00000000 --- a/brewman/brewman/templates/nav_bar/product.pt +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/brewman/brewman/templates/product/list.pt b/brewman/brewman/templates/product/list.pt deleted file mode 100644 index d4cadfc9..00000000 --- a/brewman/brewman/templates/product/list.pt +++ /dev/null @@ -1,38 +0,0 @@ - - -
    -
    -

    Products

    - - - - - - - - - - - - - - - - - - - - - - - -
    Product IDCodeNameUnitsGroupDiscontinued?
    ${item.id}${item.code}${item.name}${item.units}${item.product_group.name}${item.discontinued}
    - -
    -
    - -
    - \ No newline at end of file diff --git a/brewman/brewman/views/account.py b/brewman/brewman/views/account.py index ac998e14..639834f8 100644 --- a/brewman/brewman/views/account.py +++ b/brewman/brewman/views/account.py @@ -22,7 +22,7 @@ def save_update(request): try: id = request.matchdict.get('id', None) if id is None: - Ledger(0, request.json_body['Name'], int(request.json_body['Type']), request.json_body['IsActive'], + item = Ledger(0, request.json_body['Name'], int(request.json_body['Type']), request.json_body['IsActive'], uuid.UUID(request.json_body['CostCenter']['CostCenterID'])).create() else: new_type = int(request.json_body['Type']) @@ -35,8 +35,6 @@ def save_update(request): item.costcenter_id = uuid.UUID(request.json_body['CostCenter']['CostCenterID']) transaction.commit() return account_info(item.id) - # url = request.route_url('account_list') - # return HTTPFound(location=url) except ValidationError as ex: transaction.abort() response = Response("Failed validation: {0}".format(ex.message)) diff --git a/brewman/brewman/views/auth/user.py b/brewman/brewman/views/auth/user.py index e6750c3e..148af4ff 100644 --- a/brewman/brewman/views/auth/user.py +++ b/brewman/brewman/views/auth/user.py @@ -85,13 +85,15 @@ def show(request): def user_info(id): if id is None: - return {'Name': '', 'LockedOut': False, 'Groups': []} + account = {'Name': '', 'LockedOut': False, 'Groups': []} + for item in Group.list(): + account['Groups'].append({'GroupID': item.id, 'Name': item.name, 'Enabled': False}) else: user = User.get_by_id(id) account = {'UserID': user.id, 'Name': user.name, 'Password': '', 'LockedOut': user.locked_out, 'Groups': []} for item in Group.list(): account['Groups'].append( {'GroupID': item.id, 'Name': item.name, 'Enabled': True if item in user.groups else False}) - return account + return account diff --git a/brewman/brewman/views/cost_center.py b/brewman/brewman/views/cost_center.py index 5aa8e6e5..d0d2348b 100644 --- a/brewman/brewman/views/cost_center.py +++ b/brewman/brewman/views/cost_center.py @@ -23,14 +23,12 @@ def save_update(request): try: id = request.matchdict.get('id', None) if id is None: - CostCenter(0, request.json_body['Name']).create() + item = CostCenter(0, request.json_body['Name']).create() else: item = CostCenter.by_id(uuid.UUID(id)) item.name = request.json_body['Name'] transaction.commit() return cost_center_info(item.id) - # url = request.route_url('account_list') - # return HTTPFound(location=url) except ValidationError as ex: transaction.abort() response = Response("Failed validation: {0}".format(ex.message)) diff --git a/brewman/brewman/views/nav_bar.py b/brewman/brewman/views/nav_bar.py index e8c8b8fe..5e792cea 100644 --- a/brewman/brewman/views/nav_bar.py +++ b/brewman/brewman/views/nav_bar.py @@ -18,11 +18,8 @@ def entry_menu(request): def employee_menu(request): return render('brewman:templates/nav_bar/employee.pt', {'request': request}) -def account_menu(request): - return render('brewman:templates/nav_bar/account.mako', {'request': request}) - -def product_menu(request): - return render('brewman:templates/nav_bar/product.pt', {'request': request}) +def master_menu(request): + return render('brewman:templates/nav_bar/master.mako', {'request': request}) def login_menu(request): user_id = authenticated_userid(request) diff --git a/brewman/brewman/views/product.py b/brewman/brewman/views/product.py index ab06f9df..7baeb98b 100644 --- a/brewman/brewman/views/product.py +++ b/brewman/brewman/views/product.py @@ -1,83 +1,104 @@ -import datetime +from decimal import Decimal import uuid -from pyramid.httpexceptions import HTTPFound -from pyramid.renderers import render -from pyramid.security import authenticated_userid from pyramid.view import view_config -from sqlalchemy.sql.expression import or_ import transaction -from brewman.helpers import Literal -from brewman.models import DBSession -from brewman.models.master import Product, CostCenter, Employee, AttendanceType, LedgerType +from brewman.models.master import Product, CostCenter, LedgerType, Ledger, ProductGroup from brewman.models.validation_exception import ValidationError -from brewman.models.voucher import Attendance -@view_config(request_method='GET', route_name='product_id', renderer='brewman:templates/product/edit.pt', - permission='ProductsUpdate') -@view_config(request_method='GET', route_name='product', renderer='brewman:templates/product/edit.pt', - permission='ProductsCreate') -def product_edit(request): - id = request.matchdict.get('id', None) - if id is None: - item = Employee('(Auto)', '') - else: - item = Product.by_id(uuid.UUID(id)) - print(item.code) - return {'title': 'Edit / Add Product', - 'pageclass': "page-blogpost page-sidebar-right", - 'pagecontentclass': "page-content grid_12", - 'page_header': '', - 'item': item, - 'types': LedgerType.list(), - 'cost_centers': CostCenter.list()} +@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') +@view_config(request_method='GET', route_name='product', renderer='brewman:templates/angular_base.mako', + xhr=False, permission='ProductsUpdate') +def html(request): + return {} -@view_config(request_method='POST', route_name='product_id', permission='ProductsUpdate') -@view_config(request_method='POST', route_name='product', permission='ProductsCreate') -def employee_submit(request): +@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) +def save_update(request): try: id = request.matchdict.get('id', None) if id is None: - is_active = True if request.POST.has_key('is_active') else False - joining_date = datetime.datetime.strptime(request.POST['joining_date'], '%d-%b-%Y') - leaving_date = None if is_active else datetime.datetime.strptime(request.POST['leaving_date'], '%d-%b-%Y') - Employee(0, request.POST['name'], 10, None, is_active, uuid.UUID(request.POST['cost_center_id']), - request.POST['designation'], int(request.POST['salary']), int(request.POST['service_points']), - joining_date, leaving_date).create() - request.session.flash('Employee created') + item = Product(0, request.json_body['Name'], request.json_body['Units'], + Decimal(request.json_body['Fraction']), request.json_body['FractionUnits'], + Decimal(request.json_body['Yeild']), request.json_body['ShowForPurchase'], + uuid.UUID(request.json_body['ProductGroup']['ProductGroupID']), Ledger.all_purchases(), + Decimal(request.json_body['Price']), request.json_body['Discontinued']).create() else: - item = Employee.by_id(uuid.UUID(id)) - item.name = request.POST['name'] - item.is_active = True if request.POST.has_key('is_active') else False - item.costcenter_id = uuid.UUID(request.POST['cost_center_id']) - item.designation = request.POST['designation'] - item.salary = int(request.POST['salary']) - item.service_points = int(request.POST['service_points']) - item.joining_date = datetime.datetime.strptime(request.POST['joining_date'], '%d-%b-%Y') - item.leaving_date = None if item.is_active else datetime.datetime.strptime(request.POST['leaving_date'], - '%d-%b-%Y') - request.session.flash('Employee Updated') + item = Product.by_id(uuid.UUID(id)) + item.name = request.json_body['Name'] + item.units = request.json_body['Units'] + item.fraction = Decimal(request.json_body['Fraction']) + item.fraction_units = request.json_body['FractionUnits'] + item.yeild = Decimal(request.json_body['Yeild']) + item.show_for_purchase = request.json_body['ShowForPurchase'] + item.product_group_id = uuid.UUID(request.json_body['ProductGroup']['ProductGroupID']) + item.ledger_id = Ledger.all_purchases() + item.price = Decimal(request.json_body['Price']) + item.discontinued = request.json_body['Discontinued'] + transaction.commit() - url = request.route_url('employee_list') - return HTTPFound(location=url) + return product_info(item.id) except ValidationError as ex: - request.session.flash(ex) transaction.abort() - request.session.flash(ex.message) - return request + response = Response("Failed validation: {0}".format(ex.message)) + response.status_int = 500 + return response -@view_config(route_name='product_list', renderer='brewman:templates/product/list.pt', permission='Products') -def employee_list(request): - dbsession = DBSession() - list = dbsession.query(Product)\ - .order_by(Product.discontinued)\ - .all() +@view_config(request_method='DELETE', route_name='product_id', renderer='json', xhr=True) +def delete(request): + id = request.matchdict.get('id', None) + if id is None: + response = Response("Product is Null") + response.status_int = 500 + return response + else: + response = Response("Product deletion not implemented") + response.status_int = 500 + return response - return {'title': 'Products', - 'pageclass': "page-blogpost page-sidebar-right", - 'pagecontentclass': "page-content grid_12", - 'page_header': '', - 'list': list} + +@view_config(request_method='GET', route_name='product_id', renderer='json', xhr=True) +@view_config(request_method='GET', route_name='product', renderer='json', xhr=True) +def show(request): + list = request.GET.get('list', None) + + if list: + list = Product.query().order_by(Product.discontinued).order_by(Product.product_group_id).order_by( + Product.name).all() + products = [] + for item in list: + products.append({'Code': item.code, 'Name': item.name, 'Units': item.units, 'Price': item.price, + 'ProductGroup': item.product_group.name, 'Discontinued': item.discontinued, + 'Url': request.route_url('product_id', id=item.id)}) + return products + else: + id = request.matchdict.get('id', None) + id = None if id is None else uuid.UUID(id) + return product_info(id) + + +@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, + 'CostCenter': CostCenter.overall()} + else: + product = Product.by_id(id) + product = {'ProductID': product.id, 'Code': product.code, 'Name': product.name, 'Units': product.units, + 'Fraction': product.fraction, 'FractionUnits': product.fraction_units, 'Yeild': product.yeild, + 'ShowForPurchase': product.show_for_purchase, 'Discontinued': product.discontinued, + 'ProductGroup': {'ProductGroupID': product.product_group_id}, + 'Ledger': {'LedgerID': product.ledger_id}, 'Price': product.price} + return product