Converted most routes to use resolve.
Issue fixed (hopefully) :). Error in payment / receipt resolved fixed.
This commit is contained in:
@ -16,7 +16,7 @@
|
|||||||
<td>{{item.Code}}</td>
|
<td>{{item.Code}}</td>
|
||||||
<td>{{item.Amount}}</td>
|
<td>{{item.Amount}}</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn" ng-click="get(item.VoucherID)">Load</button>
|
<a class="btn" href="/Issue/{{item.VoucherID}}">Load</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
var overlord_service = angular.module('overlord.service', ['ngResource']);
|
var overlord_service = angular.module('overlord.service', ['ngResource']);
|
||||||
|
|
||||||
// TODO: Replace hardcoded url with route_url
|
// TODO: Replace hardcoded url with route_url
|
||||||
overlord_service.factory('issue_grid', ['$resource', function ($resource) {
|
overlord_service.factory('IssueGrid', ['$resource', function ($resource) {
|
||||||
return $resource('/Issues/Services/:date');
|
return $resource('/Issues/Services/:date');
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
function IssueCtrl($scope, $routeParams, $location, Voucher, CostCenter, issue_grid) {
|
function IssueCtrl($scope, $routeParams, $location, voucher, cost_centers, issue_grid, IssueGrid, Voucher) {
|
||||||
if (typeof $routeParams.id === 'undefined') {
|
$scope.voucher = voucher;
|
||||||
// $scope.voucher = Voucher.get({type:'Issue', date:$routeParams.Date, source:$routeParams.Source, destination:$routeParams.Destination});
|
$scope.cost_centers = cost_centers;
|
||||||
$scope.voucher = Voucher.get({type:'Issue'});
|
$scope.smallGrid = issue_grid;
|
||||||
} else {
|
|
||||||
$scope.voucher = Voucher.get({id:$routeParams.id});
|
if (typeof $routeParams.Source === 'undefined' && typeof $routeParams.Destination === 'undefined' && typeof $routeParams.id === 'undefined') {
|
||||||
|
console.log('Changing route on load');
|
||||||
|
var date = $scope.voucher.Date;
|
||||||
|
var source = getDebitCredit($scope.voucher.Journals, -1);
|
||||||
|
var destination = getDebitCredit($scope.voucher.Journals, 1);
|
||||||
|
$location.path('/Issue/' + date).search({Source:source, Destination:destination});
|
||||||
}
|
}
|
||||||
$scope.cost_centers = CostCenter.query();
|
|
||||||
|
|
||||||
$scope.addInventory = function () {
|
$scope.addInventory = function () {
|
||||||
for (var i = 0, l = this.voucher.Inventories.length; i < l; i++) {
|
for (var i = 0, l = this.voucher.Inventories.length; i < l; i++) {
|
||||||
@ -37,59 +41,40 @@
|
|||||||
this.voucher.Inventories.splice(index, 1);
|
this.voucher.Inventories.splice(index, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.updateGrid = function () {
|
|
||||||
var voucher = $scope.voucher;
|
|
||||||
for (var i = 0, l = voucher.Journals.length; i < l; i++) {
|
|
||||||
if (voucher.Journals[i].Debit === -1) {
|
|
||||||
var creditJournal = voucher.Journals[i].CostCenter.CostCenterID;
|
|
||||||
} else {
|
|
||||||
var debitJournal = voucher.Journals[i].CostCenter.CostCenterID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$scope.smallGrid = issue_grid.query({date:voucher.Date, source:creditJournal, destination:debitJournal });
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.$watch('voucher.Date', function (newDate, oldDate) {
|
$scope.$watch('voucher.Date', function (newDate, oldDate) {
|
||||||
if (newDate !== oldDate && typeof newDate !== 'undefined') {
|
if (newDate !== oldDate && typeof newDate !== 'undefined') {
|
||||||
$scope.updateGrid();
|
if (typeof $routeParams.Source !== 'undefined' && typeof $routeParams.Destination !== 'undefined' && typeof $routeParams.id !== 'undefined') {
|
||||||
|
$location.path('/Issue/' + newDate).search({Source:$routeParams.Source, Destination:$routeParams.Destination});
|
||||||
|
} else {
|
||||||
|
$scope.smallGrid = IssueGrid.query({date:newDate, Source:$routeParams.Source, Destination:$routeParams.Destination});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
function getDebitCredit(journals, type) {
|
||||||
|
for (var i = 0, l = journals.length; i < l; i++) {
|
||||||
|
if (journals[i].Debit === type) {
|
||||||
|
return journals[i].CostCenter.CostCenterID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$scope.$watch('voucher.Journals', function (newJournals, oldJournals) {
|
$scope.$watch('voucher.Journals', function (newJournals, oldJournals) {
|
||||||
if (typeof newJournals === 'undefined') {
|
if (typeof newJournals === 'undefined' || angular.equals(newJournals, oldJournals)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var doUpdate = false;
|
if (typeof oldJournals !== 'undefined') {
|
||||||
|
if (getDebitCredit(oldJournals, -1) === getDebitCredit(newJournals, -1) && getDebitCredit(oldJournals, 1) === getDebitCredit(newJournals, 1)) {
|
||||||
if (typeof oldJournals !== 'undefined' && typeof $scope.source === 'undefined') {
|
return;
|
||||||
for (var i = 0, l = oldJournals.length; i < l; i++) {
|
|
||||||
if (oldJournals[i].Debit === -1) {
|
|
||||||
$scope.source = oldJournals[i].CostCenter.CostCenterID;
|
|
||||||
} else {
|
|
||||||
$scope.destination = oldJournals[i].CostCenter.CostCenterID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!doUpdate) {
|
|
||||||
for (var i = 0, l = newJournals.length; i < l; i++) {
|
|
||||||
if (newJournals[i].Debit === -1) {
|
|
||||||
if (newJournals[i].CostCenter.CostCenterID != $scope.source) {
|
|
||||||
$scope.source = newJournals[i].CostCenter.CostCenterID;
|
|
||||||
doUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (newJournals[i].CostCenter.CostCenterID != $scope.destination) {
|
|
||||||
$scope.destination = newJournals[i].CostCenter.CostCenterID;
|
|
||||||
doUpdate = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (doUpdate) {
|
|
||||||
$scope.updateGrid();
|
if (typeof $routeParams.Source !== 'undefined' && typeof $routeParams.Destination !== 'undefined' && typeof $routeParams.id !== 'undefined') {
|
||||||
|
console.log('journal watch location');
|
||||||
|
$location.path('/Issue/' + $scope.voucher.Date).search({Source:getDebitCredit(newJournals, -1), Destination:getDebitCredit(newJournals, 1)});
|
||||||
|
} else {
|
||||||
|
console.log('journal watch grid');
|
||||||
|
$scope.smallGrid = IssueGrid.query({date:$scope.voucher.Date, Source:getDebitCredit(newJournals, -1), Destination:getDebitCredit(newJournals, 1)});
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
@ -107,12 +92,10 @@
|
|||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
$scope.resetVoucher = function (voucherid) {
|
$scope.resetVoucher = function (voucherid) {
|
||||||
// $location.path('/Issue').search({Date:voucher.Date, Source:'', Destination:''});
|
var date = $scope.voucher.Date;
|
||||||
$scope.voucher = Voucher.get({id:voucherid, type:'Issue'}, function (u, putResponseHeaders) {
|
var source = getDebitCredit($scope.voucher.Journals, -1);
|
||||||
$location.path('/Issue');
|
var destination = getDebitCredit($scope.voucher.Journals, 1);
|
||||||
}, function (data, status) {
|
$location.path('/Issue/' + date).search({Source:source, Destination:destination});
|
||||||
$scope.toasts.push({Type:'Error', Message:data.data});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.preventAlteration = function (voucher) {
|
$scope.preventAlteration = function (voucher) {
|
||||||
@ -137,9 +120,8 @@
|
|||||||
|
|
||||||
$scope.save = function () {
|
$scope.save = function () {
|
||||||
$scope.voucher.$save({type:'Issue'}, function (u, putResponseHeaders) {
|
$scope.voucher.$save({type:'Issue'}, function (u, putResponseHeaders) {
|
||||||
$location.path('/Issue/' + u.VoucherID);
|
|
||||||
$scope.toasts.push({Type:'Success', Message:u.Code});
|
$scope.toasts.push({Type:'Success', Message:u.Code});
|
||||||
$scope.updateGrid();
|
$scope.redirectOnSave(u);
|
||||||
}, function (data, status) {
|
}, function (data, status) {
|
||||||
$scope.toasts.push({Type:'Error', Message:data.data});
|
$scope.toasts.push({Type:'Error', Message:data.data});
|
||||||
});
|
});
|
||||||
@ -147,11 +129,78 @@
|
|||||||
|
|
||||||
$scope.delete = function () {
|
$scope.delete = function () {
|
||||||
$scope.voucher.$delete(function (u, putResponseHeaders) {
|
$scope.voucher.$delete(function (u, putResponseHeaders) {
|
||||||
$location.path('/Issue').replace();
|
|
||||||
$scope.toasts.push({Type:'Success', Message:''});
|
$scope.toasts.push({Type:'Success', Message:''});
|
||||||
$scope.updateGrid();
|
var date = u.Date;
|
||||||
|
var source = getDebitCredit(u.Journals, -1);
|
||||||
|
var destination = getDebitCredit(u.Journals, 1);
|
||||||
|
$location.path('/Issue/' + date).search({Source:source, Destination:destination}).replace();
|
||||||
}, function (data, status) {
|
}, function (data, status) {
|
||||||
$scope.toasts.push({Type:'Error', Message:data.data});
|
$scope.toasts.push({Type:'Error', Message:data.data});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
$scope.redirectOnSave = function (voucher) {
|
||||||
|
if (typeof $routeParams.Source !== 'undefined' && typeof $routeParams.Destination !== 'undefined' && typeof $routeParams.id !== 'undefined') {
|
||||||
|
Voucher.get({type:'Issue', Date:$routeParams.id, Source:$routeParams.Source, Destination:$routeParams.Destination}, function (u, putResponseHeaders) {
|
||||||
|
$scope.voucher = u;
|
||||||
|
});
|
||||||
|
$scope.smallGrid = IssueGrid.query({date:$routeParams.id, Source:$routeParams.Source, Destination:$routeParams.Destination});
|
||||||
|
} else {
|
||||||
|
var date = voucher.Date;
|
||||||
|
var source = getDebitCredit(voucher.Journals, -1);
|
||||||
|
var destination = getDebitCredit(voucher.Journals, 1);
|
||||||
|
$location.path('/Issue/' + date).search({Source:source, Destination:destination});
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IssueCtrl.resolve = {
|
||||||
|
voucher:function ($q, $route, Voucher) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var id = $route.current.params.id;
|
||||||
|
var source = $route.current.params.Source;
|
||||||
|
var destination = $route.current.params.Destination;
|
||||||
|
|
||||||
|
var successCb = function (result) {
|
||||||
|
deferred.resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof source !== 'undefined' && typeof destination !== 'undefined' && typeof id !== 'undefined') {
|
||||||
|
Voucher.get({type:'Issue', Date:id, Source:source, Destination:destination}, successCb);
|
||||||
|
} else if (typeof source === 'undefined' && typeof destination === 'undefined' && typeof id !== 'undefined') {
|
||||||
|
Voucher.get({id:id}, successCb);
|
||||||
|
} else {
|
||||||
|
Voucher.get({type:'Issue'}, successCb);
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
issue_grid:function ($q, $route, IssueGrid) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var id = $route.current.params.id;
|
||||||
|
var source = $route.current.params.Source;
|
||||||
|
var destination = $route.current.params.Destination;
|
||||||
|
|
||||||
|
var successCb = function (result) {
|
||||||
|
deferred.resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof source !== 'undefined' && typeof destination !== 'undefined' && typeof id !== 'undefined') {
|
||||||
|
IssueGrid.query({date:id, Source:source, Destination:destination}, successCb);
|
||||||
|
} else if (typeof source === 'undefined' && typeof destination === 'undefined' && typeof id !== 'undefined') {
|
||||||
|
IssueGrid.query({date:id}, successCb);
|
||||||
|
} else {
|
||||||
|
deferred.resolve([]);
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
cost_centers:function ($q, CostCenter) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var successCb = function (result) {
|
||||||
|
deferred.resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
CostCenter.query({}, successCb);
|
||||||
|
return deferred.promise;
|
||||||
|
}}
|
||||||
@ -10,17 +10,17 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte
|
|||||||
when('/Journal', {templateUrl:'/partial/journal.html', controller:JournalCtrl, resolve:JournalCtrl.resolve}).
|
when('/Journal', {templateUrl:'/partial/journal.html', controller:JournalCtrl, resolve:JournalCtrl.resolve}).
|
||||||
when('/Journal/:id', {templateUrl:'/partial/journal.html', controller:JournalCtrl, resolve:JournalCtrl.resolve}).
|
when('/Journal/:id', {templateUrl:'/partial/journal.html', controller:JournalCtrl, resolve:JournalCtrl.resolve}).
|
||||||
|
|
||||||
when('/Payment', {templateUrl:'/partial/payment.html', controller:PaymentCtrl}).
|
when('/Payment', {templateUrl:'/partial/payment.html', controller:PaymentCtrl, resolve:PaymentCtrl.resolve}).
|
||||||
when('/Payment/:id', {templateUrl:'/partial/payment.html', controller:PaymentCtrl}).
|
when('/Payment/:id', {templateUrl:'/partial/payment.html', controller:PaymentCtrl, resolve:PaymentCtrl.resolve}).
|
||||||
|
|
||||||
when('/Receipt', {templateUrl:'/partial/receipt.html', controller:ReceiptCtrl}).
|
when('/Receipt', {templateUrl:'/partial/receipt.html', controller:ReceiptCtrl, resolve:ReceiptCtrl.resolve}).
|
||||||
when('/Receipt/:id', {templateUrl:'/partial/receipt.html', controller:ReceiptCtrl}).
|
when('/Receipt/:id', {templateUrl:'/partial/receipt.html', controller:ReceiptCtrl, resolve:ReceiptCtrl.resolve}).
|
||||||
|
|
||||||
when('/Purchase', {templateUrl:'/partial/purchase.html', controller:PurchaseCtrl}).
|
when('/Purchase', {templateUrl:'/partial/purchase.html', controller:PurchaseCtrl, resolve:PurchaseCtrl.resolve}).
|
||||||
when('/Purchase/:id', {templateUrl:'/partial/purchase.html', controller:PurchaseCtrl}).
|
when('/Purchase/:id', {templateUrl:'/partial/purchase.html', controller:PurchaseCtrl, resolve:PurchaseCtrl.resolve}).
|
||||||
|
|
||||||
when('/Issue', {templateUrl:'/partial/issue.html', controller:IssueCtrl}).
|
when('/Issue', {templateUrl:'/partial/issue.html', controller:IssueCtrl, resolve:IssueCtrl.resolve}).
|
||||||
when('/Issue/:id', {templateUrl:'/partial/issue.html', controller:IssueCtrl}).
|
when('/Issue/:id', {templateUrl:'/partial/issue.html', controller:IssueCtrl, resolve:IssueCtrl.resolve}).
|
||||||
|
|
||||||
when('/Ledger', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl, resolve:LedgerCtrl.resolve}).
|
when('/Ledger', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl, resolve:LedgerCtrl.resolve}).
|
||||||
when('/Ledger/:id', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl, resolve:LedgerCtrl.resolve}).
|
when('/Ledger/:id', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl, resolve:LedgerCtrl.resolve}).
|
||||||
|
|||||||
@ -1,11 +1,6 @@
|
|||||||
function PaymentCtrl($scope, $routeParams, $location, Voucher, LedgerService) {
|
function PaymentCtrl($scope, $location, voucher, ledgers) {
|
||||||
if (typeof $routeParams.id === 'undefined') {
|
$scop.voucher = voucher
|
||||||
$scope.voucher = Voucher.get({type:'Payment'});
|
$scope.ledgers = ledgers;
|
||||||
} else {
|
|
||||||
$scope.voucher = Voucher.get({id:$routeParams.id});
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.ledgers = LedgerService.query({type:1});
|
|
||||||
|
|
||||||
$scope.addJournal = function () {
|
$scope.addJournal = function () {
|
||||||
for (var i = 0, l = this.voucher.Journals.length; i < l; i++) {
|
for (var i = 0, l = this.voucher.Journals.length; i < l; i++) {
|
||||||
@ -97,3 +92,32 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PaymentCtrl.resolve = {
|
||||||
|
voucher:function ($q, $route, Voucher) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var id = $route.current.params.id;
|
||||||
|
|
||||||
|
var successCb = function (result) {
|
||||||
|
deferred.resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof id === 'undefined') {
|
||||||
|
Voucher.get({type:'Payment'}, successCb);
|
||||||
|
} else {
|
||||||
|
Voucher.get({id:id}, successCb);
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
ledgers:function ($q, LedgerService) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var successCb = function (result) {
|
||||||
|
deferred.resolve(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
LedgerService.query({type:1}, successCb);
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,5 @@
|
|||||||
function PurchaseCtrl($scope, $routeParams, $location, Voucher) {
|
function PurchaseCtrl($scope, $routeParams, $location, voucher) {
|
||||||
if (typeof $routeParams.id === 'undefined') {
|
$scop.voucher = voucher
|
||||||
$scope.voucher = Voucher.get({type:'Purchase'});
|
|
||||||
} else {
|
|
||||||
$scope.voucher = Voucher.get({id:$routeParams.id});
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.rate = 0;
|
$scope.rate = 0;
|
||||||
$scope.addInventory = function () {
|
$scope.addInventory = function () {
|
||||||
@ -108,3 +104,22 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PurchaseCtrl.resolve = {
|
||||||
|
voucher:function ($q, $route, Voucher) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var id = $route.current.params.id;
|
||||||
|
|
||||||
|
var successCb = function (result) {
|
||||||
|
deferred.resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof id === 'undefined') {
|
||||||
|
Voucher.get({type:'Purchase'}, successCb);
|
||||||
|
} else {
|
||||||
|
Voucher.get({id:id}, successCb);
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,11 +1,6 @@
|
|||||||
function ReceiptCtrl($scope, $routeParams, $location, Voucher, LedgerService) {
|
function ReceiptCtrl($scope, $routeParams, $location, voucher, ledgers) {
|
||||||
if (typeof $routeParams.id === 'undefined') {
|
$scop.voucher = voucher
|
||||||
$scope.voucher = Voucher.get({type:'Receipt'});
|
$scope.ledgers = ledgers;
|
||||||
} else {
|
|
||||||
$scope.voucher = Voucher.get({id:$routeParams.id});
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.ledgers = LedgerService.query({type:1});
|
|
||||||
|
|
||||||
$scope.addJournal = function () {
|
$scope.addJournal = function () {
|
||||||
for (var i = 0, l = this.voucher.Journals.length; i < l; i++) {
|
for (var i = 0, l = this.voucher.Journals.length; i < l; i++) {
|
||||||
@ -97,3 +92,32 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReceiptCtrl.resolve = {
|
||||||
|
voucher:function ($q, $route, Voucher) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var id = $route.current.params.id;
|
||||||
|
|
||||||
|
var successCb = function (result) {
|
||||||
|
deferred.resolve(result);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof id === 'undefined') {
|
||||||
|
Voucher.get({type:'Receipt'}, successCb);
|
||||||
|
} else {
|
||||||
|
Voucher.get({id:id}, successCb);
|
||||||
|
}
|
||||||
|
return deferred.promise;
|
||||||
|
},
|
||||||
|
ledgers:function ($q, LedgerService) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
var successCb = function (result) {
|
||||||
|
deferred.resolve(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
LedgerService.query({type:1}, successCb);
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,30 +10,40 @@ from brewman.models import DBSession
|
|||||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(route_name='issues_grid', request_param='Source', renderer='json', xhr=True, permission='Issue')
|
||||||
|
def grid_date(request):
|
||||||
|
date = datetime.datetime.strptime(request.matchdict['date'], '%d-%b-%Y')
|
||||||
|
return get_grid(date, uuid.UUID(request.GET['Source']), uuid.UUID(request.GET['Destination']))
|
||||||
|
|
||||||
|
|
||||||
@view_config(route_name='issues_grid', renderer='json', xhr=True, permission='Issue')
|
@view_config(route_name='issues_grid', renderer='json', xhr=True, permission='Issue')
|
||||||
def grid(request):
|
def grid_voucher(request):
|
||||||
date = request.matchdict.get('date', None)
|
id = uuid.UUID(request.matchdict['date'])
|
||||||
if date is None:
|
voucher = Voucher.by_id(id)
|
||||||
return {}
|
source = [j.cost_center_id for j in voucher.journals if j.debit == -1]
|
||||||
date = datetime.datetime.strptime(date, '%d-%b-%Y')
|
source = source[0]
|
||||||
|
destination = [j.cost_center_id for j in voucher.journals if j.debit == 1]
|
||||||
|
destination = destination[0]
|
||||||
|
return get_grid(voucher.date, source, destination)
|
||||||
|
|
||||||
|
|
||||||
|
def get_grid(date, source, destination):
|
||||||
list = []
|
list = []
|
||||||
source = uuid.UUID(request.GET['source'])
|
|
||||||
destination = uuid.UUID(request.GET['destination'])
|
|
||||||
|
|
||||||
source_journal = aliased(Journal)
|
source_journal = aliased(Journal)
|
||||||
destination_journal = aliased(Journal)
|
destination_journal = aliased(Journal)
|
||||||
source_or = (and_(source_journal.cost_center_id == source, source_journal.debit == -1))
|
source_or = (and_(source_journal.cost_center_id == source, source_journal.debit == -1))
|
||||||
destination_or = (and_(destination_journal.cost_center_id == destination, destination_journal.debit == 1))
|
destination_or = (and_(destination_journal.cost_center_id == destination, destination_journal.debit == 1))
|
||||||
query = DBSession.query(Voucher, source_journal.amount)\
|
query = DBSession.query(Voucher, source_journal.amount)\
|
||||||
.join(source_journal, Voucher.journals)\
|
.join(source_journal, Voucher.journals)\
|
||||||
.join(destination_journal, Voucher.journals)\
|
.join(destination_journal, Voucher.journals)\
|
||||||
.filter(Voucher.date == date)\
|
.filter(Voucher.date == date)\
|
||||||
.filter(Voucher.type == VoucherType.by_name('Issue').id)\
|
.filter(Voucher.type == VoucherType.by_name('Issue').id)\
|
||||||
.filter(and_(source_or, destination_or))\
|
.filter(and_(source_or, destination_or))\
|
||||||
.order_by(Voucher.creation_date)\
|
.order_by(Voucher.creation_date)\
|
||||||
.all()
|
.all()
|
||||||
|
|
||||||
for voucher, amount in query:
|
for voucher, amount in query:
|
||||||
list.append(
|
list.append(
|
||||||
{'VoucherID': str(voucher.id), 'Code': str(voucher.code), 'Amount': "\u20B9 {0:.2f}".format(amount)})
|
{'VoucherID': str(voucher.id), 'Code': str(voucher.code), 'Amount': "\u20B9 {0:.2f}".format(amount)})
|
||||||
return list
|
return list
|
||||||
|
|||||||
@ -126,7 +126,7 @@ def blank_voucher(type=None, date=None, additionalInfo=None):
|
|||||||
raise ValidationError('Voucher Type is null and no information is provided in additional information')
|
raise ValidationError('Voucher Type is null and no information is provided in additional information')
|
||||||
elif type is None:
|
elif type is None:
|
||||||
type = additionalInfo['Type']
|
type = additionalInfo['Type']
|
||||||
if date is None and additionalInfo is None:
|
if date is None and 'Date' not in additionalInfo:
|
||||||
raise ValidationError('Both Date and Additional Information cannot be null')
|
raise ValidationError('Both Date and Additional Information cannot be null')
|
||||||
elif date is None:
|
elif date is None:
|
||||||
date = additionalInfo['Date']
|
date = additionalInfo['Date']
|
||||||
@ -150,6 +150,15 @@ def blank_voucher(type=None, date=None, additionalInfo=None):
|
|||||||
'Amount': 0,
|
'Amount': 0,
|
||||||
'Debit': 1,
|
'Debit': 1,
|
||||||
'CostCenter': {'CostCenterID': CostCenter.cost_center_kitchen()}})
|
'CostCenter': {'CostCenterID': CostCenter.cost_center_kitchen()}})
|
||||||
|
elif 'Source' in additionalInfo and 'Destination' in additionalInfo:
|
||||||
|
json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()},
|
||||||
|
'Amount': 0,
|
||||||
|
'Debit': -1,
|
||||||
|
'CostCenter': {'CostCenterID': additionalInfo['Source']}})
|
||||||
|
json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()},
|
||||||
|
'Amount': 0,
|
||||||
|
'Debit': 1,
|
||||||
|
'CostCenter': {'CostCenterID': additionalInfo['Destination']}})
|
||||||
else:
|
else:
|
||||||
json_voucher['Date'] = additionalInfo['Date']
|
json_voucher['Date'] = additionalInfo['Date']
|
||||||
for item in additionalInfo['Journals']:
|
for item in additionalInfo['Journals']:
|
||||||
|
|||||||
@ -9,7 +9,7 @@ __author__ = 'tanshu'
|
|||||||
class blank_voucher_view(object):
|
class blank_voucher_view(object):
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
@view_config(request_param='type=Journal', permission='Journal')
|
@view_config(request_param='type=Journal', permission='Journal')
|
||||||
def journal(self):
|
def journal(self):
|
||||||
return self.get_blank()
|
return self.get_blank()
|
||||||
@ -32,7 +32,15 @@ class blank_voucher_view(object):
|
|||||||
|
|
||||||
@view_config(request_param='type=Issue', permission='Issue')
|
@view_config(request_param='type=Issue', permission='Issue')
|
||||||
def issue(self):
|
def issue(self):
|
||||||
return self.get_blank()
|
voucher_type = self.request.GET.get('type', None)
|
||||||
|
date = self.request.GET.get('Date', None)
|
||||||
|
source = self.request.GET.get('Source', None)
|
||||||
|
destination = self.request.GET.get('Destination', None)
|
||||||
|
if date is not None and source is not None and destination is not None:
|
||||||
|
return blank_voucher(type=voucher_type, date=None,
|
||||||
|
additionalInfo={'Date': date, 'Source': source, 'Destination': destination})
|
||||||
|
else:
|
||||||
|
return self.get_blank()
|
||||||
|
|
||||||
def get_blank(self):
|
def get_blank(self):
|
||||||
voucher_type = self.request.GET.get('type', None)
|
voucher_type = self.request.GET.get('type', None)
|
||||||
|
|||||||
@ -41,7 +41,7 @@ def issue_create_inventory(voucher, item, batch_consumed):
|
|||||||
if quantity <= 0:
|
if quantity <= 0:
|
||||||
raise ValidationError("Quantity of {0} cannot be zero".format(item.product.name))
|
raise ValidationError("Quantity of {0} cannot be zero".format(item.product.name))
|
||||||
if batch_consumed == True and quantity > batch.quantity_remaining:
|
if batch_consumed == True and quantity > batch.quantity_remaining:
|
||||||
raise ValidationError("Quantity available is {0} only".format(item.batch.quantity_remaining))
|
raise ValidationError("Quantity available is {0} only".format(batch.quantity_remaining))
|
||||||
|
|
||||||
if batch_consumed is None:
|
if batch_consumed is None:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user