Cost Center Done
This commit is contained in:
parent
0be9ce91d9
commit
a71999e3c8
@ -119,7 +119,7 @@ class CostCenter(Base):
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
return DBSession.query(cls).all()
|
||||
return DBSession.query(cls).order_by(cls.name).all()
|
||||
|
||||
def create(self):
|
||||
code = DBSession.query(func.max(CostCenter.code)).one()[0]
|
||||
|
@ -1,5 +1,5 @@
|
||||
<form method="post" class="form-horizontal" ng-controller="AccountCtrl">
|
||||
<legend>Account Edit / New</legend>
|
||||
<legend>Account Detail</legend>
|
||||
<div class="control-group">
|
||||
<label for="txtCode" class="control-label">Code</label>
|
||||
|
||||
|
16
brewman/brewman/static/partial/cost-center-detail.html
Normal file
16
brewman/brewman/static/partial/cost-center-detail.html
Normal 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>
|
13
brewman/brewman/static/partial/cost-center-list.html
Normal file
13
brewman/brewman/static/partial/cost-center-list.html
Normal 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>
|
@ -100,7 +100,10 @@ overlord_service.factory('Permission', ['$resource', function ($resource) {
|
||||
|
||||
// TODO: Replace hardcoded url with route_url
|
||||
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
|
||||
|
@ -7,6 +7,9 @@
|
||||
when('/Accounts', {templateUrl: '/partial/account-list.html', controller: AccountListCtrl}).
|
||||
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('/User/:id', {templateUrl: '/partial/user-detail.html', controller: UserCtrl});
|
||||
// .otherwise({redirectTo: '/phones'});
|
||||
|
27
brewman/brewman/static/scripts/cost-center.js
Normal file
27
brewman/brewman/static/scripts/cost-center.js
Normal 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();
|
||||
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
function JournalCtrl($scope, $routeParams, $location, Voucher) {
|
||||
console.log('loading')
|
||||
|
||||
if (typeof $routeParams.id === 'undefined'){
|
||||
$scope.voucher = Voucher.get({type:'Journal'});
|
||||
} else {
|
||||
|
@ -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>
|
@ -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>
|
@ -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>
|
@ -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>
|
@ -41,6 +41,7 @@
|
||||
|
||||
${h.ScriptLink(request, 'account.js')}
|
||||
${h.ScriptLink(request, 'user.js')}
|
||||
${h.ScriptLink(request, 'cost-center.js')}
|
||||
|
||||
<!-- Le fav and touch icons -->
|
||||
<link rel="shortcut icon" href="${request.static_url('brewman:static/img/favicon.ico')}">
|
||||
|
@ -1,14 +1,11 @@
|
||||
import json
|
||||
import uuid
|
||||
from pyramid.response import Response
|
||||
|
||||
from pyramid.view import view_config
|
||||
import transaction
|
||||
from brewman.helpers import Literal
|
||||
|
||||
from brewman.models.master import CostCenter, Ledger, LedgerType
|
||||
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(request_method='GET', route_name='account_id', renderer='brewman:templates/angular_base.mako',
|
||||
|
@ -1,65 +1,77 @@
|
||||
import uuid
|
||||
from pyramid.response import Response
|
||||
|
||||
from pyramid.httpexceptions import HTTPFound
|
||||
from pyramid.view import view_config
|
||||
import transaction
|
||||
|
||||
from brewman.models import DBSession
|
||||
from brewman.models.master import CostCenter
|
||||
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(request_method='GET', route_name='cost_center', renderer='brewman:templates/ledgers/cost_center_edit.mako')
|
||||
def cost_center_edit(request):
|
||||
id = request.matchdict.get('id', None)
|
||||
if id is None:
|
||||
item = CostCenter('(Auto)','')
|
||||
else:
|
||||
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(route_name='cost_center_list', renderer='brewman:templates/angular_base.mako')
|
||||
@view_config(request_method='GET', route_name='cost_center_id', renderer='brewman:templates/angular_base.mako',
|
||||
xhr=False)
|
||||
@view_config(request_method='GET', route_name='cost_center', renderer='brewman:templates/angular_base.mako',
|
||||
xhr=False)
|
||||
def html(request):
|
||||
return {}
|
||||
|
||||
@view_config(request_method='POST', route_name='cost_center_id')
|
||||
@view_config(request_method='POST', route_name='cost_center')
|
||||
def cost_center_submit(request):
|
||||
|
||||
@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)
|
||||
def save_update(request):
|
||||
try:
|
||||
|
||||
id = request.matchdict.get('id', None)
|
||||
if id is None:
|
||||
item = CostCenter(0,request.POST['name']).create()
|
||||
CostCenter(0, request.json_body['Name']).create()
|
||||
else:
|
||||
item = CostCenter.by_id(uuid.UUID(id))
|
||||
item.name = request.POST['name']
|
||||
item.name = request.json_body['Name']
|
||||
transaction.commit()
|
||||
url = request.route_url('cost_center_list')
|
||||
return HTTPFound(location=url)
|
||||
return cost_center_info(item.id)
|
||||
# url = request.route_url('account_list')
|
||||
# return HTTPFound(location=url)
|
||||
except ValidationError as ex:
|
||||
# request.session.flash(ex)
|
||||
transaction.abort()
|
||||
# request.session.flash(ex.message)
|
||||
return request
|
||||
|
||||
@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}
|
||||
response = Response("Failed validation: {0}".format(ex.message))
|
||||
response.status_int = 500
|
||||
return response
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='cost_center_list', renderer='json', xhr=True)
|
||||
def get(request):
|
||||
cost_centers = []
|
||||
for item in CostCenter.list():
|
||||
cost_centers.append({'CostCenterID': item.id, 'Name': item.name})
|
||||
return cost_centers
|
||||
@view_config(request_method='DELETE', route_name='cost_center_id', renderer='json', xhr=True)
|
||||
def delete(request):
|
||||
id = request.matchdict.get('id', None)
|
||||
if id is None:
|
||||
response = Response("Cost Center is Null")
|
||||
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}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user