Cost Center Done

This commit is contained in:
Tanshu 2012-10-12 00:29:11 +05:30
parent 0be9ce91d9
commit a71999e3c8
15 changed files with 121 additions and 198 deletions

View File

@ -119,7 +119,7 @@ class CostCenter(Base):
@classmethod @classmethod
def list(cls): def list(cls):
return DBSession.query(cls).all() return DBSession.query(cls).order_by(cls.name).all()
def create(self): def create(self):
code = DBSession.query(func.max(CostCenter.code)).one()[0] code = DBSession.query(func.max(CostCenter.code)).one()[0]

View File

@ -1,5 +1,5 @@
<form method="post" class="form-horizontal" ng-controller="AccountCtrl"> <form method="post" class="form-horizontal" ng-controller="AccountCtrl">
<legend>Account Edit / New</legend> <legend>Account Detail</legend>
<div class="control-group"> <div class="control-group">
<label for="txtCode" class="control-label">Code</label> <label for="txtCode" class="control-label">Code</label>

View File

@ -0,0 +1,16 @@
<form method="post" class="form-horizontal" ng-controller="CostCenterCtrl">
<legend>Cost Center Detail</legend>
<div class="control-group">
<label for="txtName" class="control-label">Name</label>
<div class="controls">
<input type="text" id="txtName" ng-model="cost_center.Name"/>
</div>
</div>
<div class=" control-group">
<div class="controls">
<button ng-click="save()">Save</button>
</div>
</div>
</form>

View File

@ -0,0 +1,13 @@
<legend>Cost Centers</legend>
<table class="clean-table" ng-controller="CostCenterListCtrl">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in info">
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
</tr>
</tbody>
</table>

View File

@ -100,7 +100,10 @@ overlord_service.factory('Permission', ['$resource', function ($resource) {
// TODO: Replace hardcoded url with route_url // TODO: Replace hardcoded url with route_url
overlord_service.factory('CostCenter', ['$resource', function ($resource) { overlord_service.factory('CostCenter', ['$resource', function ($resource) {
return $resource('/CostCenters'); return $resource('/CostCenter/:id',
{id:'@CostCenterID'}, {
query:{method:'GET', params:{list:true}, isArray:true}
});
}]); }]);
// TODO: Replace hardcoded url with route_url // TODO: Replace hardcoded url with route_url

View File

@ -7,6 +7,9 @@
when('/Accounts', {templateUrl: '/partial/account-list.html', controller: AccountListCtrl}). when('/Accounts', {templateUrl: '/partial/account-list.html', controller: AccountListCtrl}).
when('/Account/:id', {templateUrl: '/partial/account-detail.html', controller: AccountCtrl}). when('/Account/:id', {templateUrl: '/partial/account-detail.html', controller: AccountCtrl}).
when('/CostCenters', {templateUrl: '/partial/cost-center-list.html', controller: CostCenterListCtrl}).
when('/CostCenter/:id', {templateUrl: '/partial/cost-center-detail.html', controller: CostCenterCtrl}).
when('/Users', {templateUrl: '/partial/user-list.html', controller: UserListCtrl}). when('/Users', {templateUrl: '/partial/user-list.html', controller: UserListCtrl}).
when('/User/:id', {templateUrl: '/partial/user-detail.html', controller: UserCtrl}); when('/User/:id', {templateUrl: '/partial/user-detail.html', controller: UserCtrl});
// .otherwise({redirectTo: '/phones'}); // .otherwise({redirectTo: '/phones'});

View File

@ -0,0 +1,27 @@
function CostCenterListCtrl($scope, CostCenter) {
$scope.info = CostCenter.query();
}
function CostCenterCtrl($scope, $routeParams, $location, CostCenter) {
$scope.cost_center = CostCenter.get({id: $routeParams.id});
$scope.save = function () {
$scope.cost_center.$save(function (u, putResponseHeaders) {
$scope.toasts.push({Type:'Success', Message:u.Code});
$location.path('/CostCenters')
}, function (data, status) {
$scope.toasts.push({Type:'Error', Message:data.data});
});
};
$scope.delete = function () {
$scope.cost_center.$delete(function (u, putResponseHeaders) {
$scope.toasts.push({Type:'Success', Message:''});
$location.path('/CostCenters')
}, function (data, status) {
$scope.toasts.push({Type:'Error', Message:data.data});
});
};
$('#txtLedger').focus();
}

View File

@ -1,6 +1,4 @@
function JournalCtrl($scope, $routeParams, $location, Voucher) { function JournalCtrl($scope, $routeParams, $location, Voucher) {
console.log('loading')
if (typeof $routeParams.id === 'undefined'){ if (typeof $routeParams.id === 'undefined'){
$scope.voucher = Voucher.get({type:'Journal'}); $scope.voucher = Voucher.get({type:'Journal'});
} else { } else {

View File

@ -1,71 +0,0 @@
# -*- coding: utf-8 -*-
<%inherit file="../base.mako"/>
<%block name="header">
<script type="text/javascript">
const perms = ${perms};
const account = ${account};
const account_types = ${account_types};
const cost_centers = ${cost_centers};
</script>
${h.ScriptLink(request, 'account.js')}
<script type="text/javascript">
$(document).ready(function () {
$('#txtLedger').focus();
});
</script>
</%block>
<%block name="content">
<form method="post" class="form-horizontal" ng-controller="AccountCtrl">
<legend>Ledger Edit / New</legend>
${h.CsrfToken(request.session)}
<div class="control-group">
<label for="txtCode" class="control-label">Code</label>
<div class="controls">
<input type="text" id="txtCode" class="non-search-box" disabled="disabled" ng-model="account.Code"/>
</div>
</div>
<div class="control-group">
<label for="txtName" class="control-label">Name</label>
<div class="controls">
<input type="text" id="txtName" ng-model="account.Name"/>
</div>
</div>
<div class="control-group">
<label for="ddlType" class="control-label">Type</label>
<div class="controls">
<select id="ddlType" class="select-box" ng-model="account.Type"
ng-options="l.AccountTypeID as l.Name for l in account_types"> </select>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" ng-checked="account.IsActive"> Is Active
</label>
</div>
</div>
<div class="control-group">
<label for="ddlCostCenter" class="control-label">Cost Center</label>
<div class="controls">
<select id="ddlCostCenter" class="select-box" ng-model="account.CostCenter.CostCenterID"
ng-options="l.CostCenterID as l.Name for l in cost_centers"> </select>
</div>
</div>
<div class=" control-group" id="add">
<div class="controls">
<button ng-click="save()">Save</button>
</div>
</div>
</form>
</%block>

View File

@ -1,30 +0,0 @@
# -*- coding: utf-8 -*-
<%inherit file="../base.mako"/>
<%block name="header">
<script type="text/javascript">
const perms = ${perms};
const info = ${info};
</script>
${h.ScriptLink(request, 'account.js')}
</%block>
<%block name="content">
<h2 class="ribbon-header">Ledgers</h2>
<table class="clean-table" ng-controller="AccountListCtrl">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Is Active?</th>
<th>Cost Center</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in info">
<td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td>{{item.Type}}</td>
<td>{{item.IsActive}}</td>
<td>{{item.CostCenter}}</td>
</tr>
</tbody>
</table>
</%block>

View File

@ -1,21 +0,0 @@
# -*- coding: utf-8 -*-
<%inherit file="../base.mako"/>
<%block name="content">
<h2 class="ribbon-header">Cost Center Edit / New</h2>
<form method="post" autocomplete="off">
${h.CsrfToken(request.session)}
<p>
${h.Label('Code: ' + str(h.Span('(Required *)', 'required')), 'code')}
${h.TextInput('code', value = item.code, css_class = 'required', required = 'required')}
</p>
<p>
${h.Label('Name: ' + str(h.Span('(Required *)', 'required')), 'name')}
${h.TextInput('name', value = item.name, css_class = 'required', required = 'required')}
</p>
<p>
${h.SubmitButton('submit', 'Submit')}
</p>
</form>
</%block>

View File

@ -1,25 +0,0 @@
# -*- coding: utf-8 -*-
<%inherit file="../base.mako"/>
<%block name="content">
<h2 class="ribbon-header">Cost Centers</h2>
<table id="gvGrid" class="clean-table">
<thead>
<tr>
<th class="CostCenterID hide">Cost CenterID</th>
<th class="Code hide">Code</th>
<th class="Name">Name</th>
</tr>
</thead>
<tbody id="tbodyMain">
% for item in list:
<tr>
<td class="CostCenterID hide">${item.id}</td>
<td class="Code hide">${item.code}</td>
<td class="Name"><a href="${request.route_url('cost_center_id', id=item.id)}">${item.name}</a></td>
</tr>
% endfor
</tbody>
<tfoot id="tfootMain">
</tfoot>
</table>
</%block>

View File

@ -41,6 +41,7 @@
${h.ScriptLink(request, 'account.js')} ${h.ScriptLink(request, 'account.js')}
${h.ScriptLink(request, 'user.js')} ${h.ScriptLink(request, 'user.js')}
${h.ScriptLink(request, 'cost-center.js')}
<!-- Le fav and touch icons --> <!-- Le fav and touch icons -->
<link rel="shortcut icon" href="${request.static_url('brewman:static/img/favicon.ico')}"> <link rel="shortcut icon" href="${request.static_url('brewman:static/img/favicon.ico')}">

View File

@ -1,14 +1,11 @@
import json
import uuid import uuid
from pyramid.response import Response from pyramid.response import Response
from pyramid.view import view_config from pyramid.view import view_config
import transaction import transaction
from brewman.helpers import Literal
from brewman.models.master import CostCenter, Ledger, LedgerType from brewman.models.master import CostCenter, Ledger, LedgerType
from brewman.models.validation_exception import ValidationError from brewman.models.validation_exception import ValidationError
from brewman.views import DecimalEncoder
@view_config(route_name='account_list', renderer='brewman:templates/angular_base.mako') @view_config(route_name='account_list', renderer='brewman:templates/angular_base.mako')
@view_config(request_method='GET', route_name='account_id', renderer='brewman:templates/angular_base.mako', @view_config(request_method='GET', route_name='account_id', renderer='brewman:templates/angular_base.mako',

View File

@ -1,65 +1,77 @@
import uuid import uuid
from pyramid.response import Response
from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_config from pyramid.view import view_config
import transaction import transaction
from brewman.models import DBSession
from brewman.models.master import CostCenter from brewman.models.master import CostCenter
from brewman.models.validation_exception import ValidationError from brewman.models.validation_exception import ValidationError
@view_config(request_method='GET', route_name='cost_center_id', renderer='brewman:templates/ledgers/cost_center_edit.mako') @view_config(route_name='cost_center_list', renderer='brewman:templates/angular_base.mako')
@view_config(request_method='GET', route_name='cost_center', renderer='brewman:templates/ledgers/cost_center_edit.mako') @view_config(request_method='GET', route_name='cost_center_id', renderer='brewman:templates/angular_base.mako',
def cost_center_edit(request): xhr=False)
id = request.matchdict.get('id', None) @view_config(request_method='GET', route_name='cost_center', renderer='brewman:templates/angular_base.mako',
if id is None: xhr=False)
item = CostCenter('(Auto)','') def html(request):
else: return {}
item = CostCenter.by_id(uuid.UUID(id))
return {'title':'Hops n Grains - Blog',
'pageclass': "page-blogpost page-sidebar-right",
'pagecontentclass': "page-content grid_12",
'page_header': '',
'item': item}
@view_config(request_method='POST', route_name='cost_center_id')
@view_config(request_method='POST', route_name='cost_center') @view_config(request_method='POST', route_name='cost_center_id', renderer='json', xhr=True)
def cost_center_submit(request): @view_config(request_method='POST', route_name='cost_center', renderer='json', xhr=True)
def save_update(request):
try: try:
id = request.matchdict.get('id', None) id = request.matchdict.get('id', None)
if id is None: if id is None:
item = CostCenter(0,request.POST['name']).create() CostCenter(0, request.json_body['Name']).create()
else: else:
item = CostCenter.by_id(uuid.UUID(id)) item = CostCenter.by_id(uuid.UUID(id))
item.name = request.POST['name'] item.name = request.json_body['Name']
transaction.commit() transaction.commit()
url = request.route_url('cost_center_list') return cost_center_info(item.id)
return HTTPFound(location=url) # url = request.route_url('account_list')
# return HTTPFound(location=url)
except ValidationError as ex: except ValidationError as ex:
# request.session.flash(ex)
transaction.abort() transaction.abort()
# request.session.flash(ex.message) response = Response("Failed validation: {0}".format(ex.message))
return request response.status_int = 500
return response
@view_config(route_name='cost_center_list', renderer='brewman:templates/ledgers/cost_center_list.mako', xhr=False)
def cost_center_list(request):
dbsession = DBSession()
cost_centers = dbsession.query(CostCenter).all()
return {'title':'Hops n Grains - Blog',
'pageclass': "page-blogpost page-sidebar-right",
'pagecontentclass': "page-content grid_12",
'page_header': '',
'list': cost_centers}
@view_config(request_method='GET', route_name='cost_center_list', renderer='json', xhr=True) @view_config(request_method='DELETE', route_name='cost_center_id', renderer='json', xhr=True)
def get(request): def delete(request):
cost_centers = [] id = request.matchdict.get('id', None)
for item in CostCenter.list(): if id is None:
cost_centers.append({'CostCenterID': item.id, 'Name': item.name}) response = Response("Cost Center is Null")
return cost_centers response.status_int = 500
return response
else:
response = Response("Cost Center deletion not implemented")
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', renderer='json', xhr=True)
def show(request):
list = request.GET.get('list', None)
if list:
list = CostCenter.list()
cost_centers = []
for item in list:
cost_centers.append({'CostCenterID': item.id, 'Name': item.name, 'Url': request.route_url('cost_center_id', id=item.id)})
return cost_centers
else:
id = request.matchdict.get('id', None)
id = None if id is None else uuid.UUID(id)
return cost_center_info(id)
def cost_center_info(id):
if id is None:
return {}
else:
cost_center = CostCenter.by_id(id)
return {'CostCenterID': cost_center.id, 'Name': cost_center.name}