diff --git a/brewman/brewman/models/master.py b/brewman/brewman/models/master.py index 5cef21ce..0fc4819e 100644 --- a/brewman/brewman/models/master.py +++ b/brewman/brewman/models/master.py @@ -188,6 +188,8 @@ class LedgerBase(Base): @classmethod def by_id(cls, id): + if not isinstance(id, uuid.UUID): + id = uuid.UUID(id) return DBSession.query(cls).filter(cls.id == id).first() @classmethod diff --git a/brewman/brewman/static/js/lodash.min-2.2.1.js b/brewman/brewman/static/js/lodash.min-2.2.1.js new file mode 100644 index 00000000..0fd9246e --- /dev/null +++ b/brewman/brewman/static/js/lodash.min-2.2.1.js @@ -0,0 +1,54 @@ +/** + * @license + * Lo-Dash 2.2.1 (Custom Build) lodash.com/license | Underscore.js 1.5.2 underscorejs.org/LICENSE + * Build: `lodash modern -o ./dist/lodash.js` + */ +;(function(){function n(n,t,e){e=(e||0)-1;for(var r=n?n.length:0;++er||typeof e=="undefined")return 1;if(ee?0:e);++r=b&&f===n,h=u||v?i():s;if(v){var g=o(h);g?(f=t,h=g):(v=!1,h=u?h:(c(h),s))}for(;++af(h,y))&&((u||v)&&h.push(y),s.push(g))}return v?(c(h.k),p(h)):u&&c(h),s}function it(n){return function(t,e,r){var u={};e=Y.createCallback(e,r,3),r=-1;var o=t?t.length:0;if(typeof o=="number")for(;++re?Re(0,o+e):e)||0,Pe(n)?a=-1o&&(o=i)}}else t=!t&&wt(n)?r:Y.createCallback(t,e,3),It(n,function(n,e,r){e=t(n,e,r),e>u&&(u=e,o=n)});return o}function Rt(n,t){var e=-1,r=n?n.length:0;if(typeof r=="number")for(var u=Xt(r);++earguments.length;t=et(t,r,4);var o=-1,a=n.length;if(typeof a=="number")for(u&&(e=n[++o]);++oarguments.length;return t=et(t,r,4),Nt(n,function(n,r,o){e=u?(u=!1,n):t(e,n,r,o)}),e}function Bt(n){var t=-1,e=n?n.length:0,r=Xt(typeof e=="number"?e:0);return It(n,function(n){var e=Jt(++t);r[t]=r[e],r[e]=n}),r}function $t(n,t,e){var r;t=Y.createCallback(t,e,3),e=-1; +var u=n?n.length:0;if(typeof u=="number")for(;++e=b&&u===n;if(l){var c=o(i);c?(u=t,i=c):l=!1}for(;++ru(i,c)&&f.push(c);return l&&p(i),f}function Tt(n,t,e){var r=0,u=n?n.length:0;if(typeof t!="number"&&null!=t){var o=-1;for(t=Y.createCallback(t,e,3);++or?Re(0,u+r):r||0}else if(r)return r=zt(t,e),t[r]===e?r:-1;return n(t,e,r)}function qt(n,t,e){if(typeof t!="number"&&null!=t){var r=0,u=-1,o=n?n.length:0;for(t=Y.createCallback(t,e,3);++u>>1,e(n[r])e?0:e);++t/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:N,variable:"",imports:{_:Y}},Oe||(lt=function(n){if(bt(n)){l.prototype=n;var t=new l;l.prototype=null}return t||{}});var ze=xe?function(n,t){U.value=t,xe(n,"__bindData__",U)}:l,Pe=Ie||function(n){return n&&typeof n=="object"&&typeof n.length=="number"&&je.call(n)==$||!1},Ke=Se?function(n){return bt(n)?Se(n):[] +}:Q,Le={"&":"&","<":"<",">":">",'"':""","'":"'"},Me=mt(Le),Ue=ue("("+Ke(Me).join("|")+")","g"),Ve=ue("["+Ke(Le).join("")+"]","g"),Ge=it(function(n,t,e){ye.call(n,e)?n[e]++:n[e]=1}),He=it(function(n,t,e){(ye.call(n,e)?n[e]:n[e]=[]).push(t)}),Je=it(function(n,t,e){n[e]=t});Te&&X&&typeof be=="function"&&(Vt=function(n){if(!_t(n))throw new ae;return be.apply(e,arguments)});var Qe=8==De(w+"08")?De:function(n,t){return De(wt(n)?n.replace(E,""):n,t||0)};return Y.after=function(n,t){if(!_t(t))throw new ae; +return function(){return 1>--n?t.apply(this,arguments):void 0}},Y.assign=J,Y.at=function(n){for(var t=arguments,e=-1,r=rt(t,!0,!1,1),t=t[2]&&t[2][t[1]]===n?1:r.length,u=Xt(t);++e=b&&o(a?r[a]:g) +}n:for(;++l(m?t(m,y):s(g,y))){for(a=u,(m||g).push(y);--a;)if(m=f[a],0>(m?t(m,y):s(r[a],y)))continue n;h.push(y)}}for(;u--;)(m=f[u])&&p(m);return c(f),c(g),h},Y.invert=mt,Y.invoke=function(n,t){var e=$e.call(arguments,2),r=-1,u=typeof t=="function",o=n?n.length:0,a=Xt(typeof o=="number"?o:0);return It(n,function(n){a[++r]=(u?t:n[t]).apply(n,e)}),a},Y.keys=Ke,Y.map=Et,Y.max=St,Y.memoize=function(n,t){function e(){var r=e.cache,u=t?t.apply(this,arguments):_+arguments[0];return ye.call(r,u)?r[u]:r[u]=n.apply(this,arguments) +}if(!_t(n))throw new ae;return e.cache={},e},Y.merge=function(n){var t=arguments,e=2;if(!bt(n))return n;if("number"!=typeof t[2]&&(e=t.length),3r(a,e))&&(o[e]=n)}),o},Y.once=function(n){var t,e;if(!_t(n))throw new ae;return function(){return t?e:(t=!0,e=n.apply(this,arguments),n=null,e)}},Y.pairs=function(n){for(var t=-1,e=Ke(n),r=e.length,u=Xt(r);++te?Re(0,r+e):Ae(e,r-1))+1);r--;)if(n[r]===t)return r;return-1},Y.mixin=Ht,Y.noConflict=function(){return e._=le,this},Y.parseInt=Qe,Y.random=Jt,Y.reduce=At,Y.reduceRight=Dt,Y.result=function(n,t){if(n){var e=n[t];return _t(e)?n[t]():e}},Y.runInContext=v,Y.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Ke(n).length},Y.some=$t,Y.sortedIndex=zt,Y.template=function(n,t,e){var r=Y.templateSettings; +n||(n=""),e=G({},e,r);var u,o=G({},e.imports,r.imports),r=Ke(o),o=jt(o),i=0,f=e.interpolate||S,l="__p+='",f=ue((e.escape||S).source+"|"+f.source+"|"+(f===N?C:S).source+"|"+(e.evaluate||S).source+"|$","g");n.replace(f,function(t,e,r,o,f,c){return r||(r=o),l+=n.slice(i,c).replace(A,a),e&&(l+="'+__e("+e+")+'"),f&&(u=!0,l+="';"+f+";__p+='"),r&&(l+="'+((__t=("+r+"))==null?'':__t)+'"),i=c+t.length,t}),l+="';\n",f=e=e.variable,f||(e="obj",l="with("+e+"){"+l+"}"),l=(u?l.replace(j,""):l).replace(k,"$1").replace(x,"$1;"),l="function("+e+"){"+(f?"":e+"||("+e+"={});")+"var __t,__p='',__e=_.escape"+(u?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}"; +try{var c=ne(r,"return "+l).apply(h,o)}catch(p){throw p.source=l,p}return t?c(t):(c.source=l,c)},Y.unescape=function(n){return null==n?"":oe(n).replace(Ue,vt)},Y.uniqueId=function(n){var t=++m;return oe(null==n?"":n)+t},Y.all=xt,Y.any=$t,Y.detect=Ot,Y.findWhere=Ot,Y.foldl=At,Y.foldr=Dt,Y.include=kt,Y.inject=At,y(Y,function(n,t){Y.prototype[t]||(Y.prototype[t]=function(){var t=[this.__wrapped__],e=this.__chain__;return _e.apply(t,arguments),t=n.apply(Y,t),e?new nt(t,e):t})}),Y.first=Tt,Y.last=function(n,t,e){var r=0,u=n?n.length:0; +if(typeof t!="number"&&null!=t){var o=u;for(t=Y.createCallback(t,e,3);o--&&t(n[o],o,n);)r++}else if(r=t,null==r||e)return n?n[u-1]:h;return s(n,Re(0,u-r))},Y.sample=function(n,t,e){var r=n?n.length:0;return typeof r!="number"&&(n=jt(n)),null==t||e?n?n[Jt(r-1)]:h:(n=Bt(n),n.length=Ae(Re(0,t),n.length),n)},Y.take=Tt,Y.head=Tt,y(Y,function(n,t){var e="sample"!==t;Y.prototype[t]||(Y.prototype[t]=function(t,r){var u=this.__chain__,o=n(this.__wrapped__,t,r);return u||null!=t&&(!r||e&&typeof t=="function")?new nt(o,u):o +})}),Y.VERSION="2.2.1",Y.prototype.chain=function(){return this.__chain__=!0,this},Y.prototype.toString=function(){return oe(this.__wrapped__)},Y.prototype.value=Qt,Y.prototype.valueOf=Qt,It(["join","pop","shift"],function(n){var t=ie[n];Y.prototype[n]=function(){var n=this.__chain__,e=t.apply(this.__wrapped__,arguments);return n?new nt(e,n):e}}),It(["push","reverse","sort","unshift"],function(n){var t=ie[n];Y.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),It(["concat","slice","splice"],function(n){var t=ie[n]; +Y.prototype[n]=function(){return new nt(t.apply(this.__wrapped__,arguments),this.__chain__)}}),Y}var h,g=[],y=[],m=0,_=+new Date+"",b=75,d=40,w=" \t\x0B\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",j=/\b__p\+='';/g,k=/\b(__p\+=)''\+/g,x=/(__e\(.*?\)|\b__t\))\+'';/g,C=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,O=/\w*$/,I=/^function[ \n\r\t]+\w/,N=/<%=([\s\S]+?)%>/g,E=RegExp("^["+w+"]*0+(?=.$)"),S=/($^)/,R=/\bthis\b/,A=/['\n\r\t\u2028\u2029\\]/g,D="Array Boolean Date Function Math Number Object RegExp String _ attachEvent clearTimeout isFinite isNaN parseInt setImmediate setTimeout".split(" "),B="[object Arguments]",$="[object Array]",F="[object Boolean]",T="[object Date]",W="[object Function]",q="[object Number]",z="[object Object]",P="[object RegExp]",K="[object String]",L={}; +L[W]=!1,L[B]=L[$]=L[F]=L[T]=L[q]=L[z]=L[P]=L[K]=!0;var M={leading:!1,maxWait:0,trailing:!1},U={configurable:!1,enumerable:!1,value:null,writable:!1},V={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1},G={"\\":"\\","'":"'","\n":"n","\r":"r","\t":"t","\u2028":"u2028","\u2029":"u2029"},H=V[typeof window]&&window||this,J=V[typeof exports]&&exports&&!exports.nodeType&&exports,Q=V[typeof module]&&module&&!module.nodeType&&module,X=Q&&Q.exports===J&&J,Y=V[typeof global]&&global;!Y||Y.global!==Y&&Y.window!==Y||(H=Y); +var Z=v();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(H._=Z, define(function(){return Z})):J&&Q?X?(Q.exports=Z)._=Z:J._=Z:H._=Z}).call(this); \ No newline at end of file diff --git a/brewman/brewman/static/partial/payment.html b/brewman/brewman/static/partial/payment.html index b49f7a6e..78c3ab50 100644 --- a/brewman/brewman/static/partial/payment.html +++ b/brewman/brewman/static/partial/payment.html @@ -19,7 +19,7 @@ + value="{{journal.Amount | number:2}}"/> diff --git a/brewman/brewman/static/partial/receipt.html b/brewman/brewman/static/partial/receipt.html index 43cb1935..446c3149 100644 --- a/brewman/brewman/static/partial/receipt.html +++ b/brewman/brewman/static/partial/receipt.html @@ -19,7 +19,7 @@ + value="{{journal.Amount | number:2}}"/> diff --git a/brewman/brewman/static/scripts/journal.js b/brewman/brewman/static/scripts/journal.js index b516fc34..82d5cca3 100644 --- a/brewman/brewman/static/scripts/journal.js +++ b/brewman/brewman/static/scripts/journal.js @@ -1,21 +1,21 @@ 'use strict'; var JournalCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher', 'Account', function ($scope, $location, $q, dateFilter, $modal, voucher, Account) { + $('#txtAccount').focus(); + $scope.voucher = voucher; $scope.debit = 1; - function getOldJournal(ledgerID, journals) { - for (var i = 0, l = journals.length; i < l; i++) { - if (journals[i].Ledger.LedgerID === ledgerID) { - return journals[i]; - } - } + function getOld(ledgerID, journals) { + return _.find(journals, function (journal) { + return journal.Ledger.LedgerID === ledgerID; + }); } $scope.add = function () { if (!$scope.account || !$scope.account.LedgerID || !$scope.amount || Number(!$scope.amount)) { return; } - var oldJournal = getOldJournal($scope.account.LedgerID, this.voucher.Journals); + var oldJournal = getOld($scope.account.LedgerID, this.voucher.Journals); if (typeof oldJournal !== 'undefined') { var amount = (oldJournal.Debit * oldJournal.Amount) + (parseInt($scope.debit) * Number($scope.amount)); if (amount < 0) { @@ -113,7 +113,7 @@ var JournalCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher }); modalInstance.result.then(function (updated) { if (updated.Ledger.LedgerID !== $scope.selectedJournal.Ledger.LedgerID) { - var oldJournal = getOldJournal(updated.Ledger.LedgerID, $scope.voucher.Journals); + var oldJournal = getOld(updated.Ledger.LedgerID, $scope.voucher.Journals); if (typeof oldJournal !== 'undefined') { delete $scope.selectedJournal; return false; @@ -152,7 +152,7 @@ var JournalCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher $scope.accounts = function ($viewValue) { var deferred = $q.defer(); - Account.autocomplete({term: $viewValue, count: 20, a:true}, function (result) { + Account.autocomplete({term: $viewValue, count: 20, a: true}, function (result) { deferred.resolve(result); }); return deferred.promise; diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index 94fa4113..4d0f9157 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -10,10 +10,10 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte when('/Journal', {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, resolve: PaymentCtrl.resolve}). + when('/Payment', {templateUrl: '/partial/payment.html', controller: PaymentCtrl, resolve: PaymentCtrl.resolve, reloadOnSearch:false}). when('/Payment/:id', {templateUrl: '/partial/payment.html', controller: PaymentCtrl, resolve: PaymentCtrl.resolve}). - when('/Receipt', {templateUrl: '/partial/receipt.html', controller: ReceiptCtrl, resolve: ReceiptCtrl.resolve}). + when('/Receipt', {templateUrl: '/partial/receipt.html', controller: ReceiptCtrl, resolve: ReceiptCtrl.resolve, reloadOnSearch:false}). when('/Receipt/:id', {templateUrl: '/partial/receipt.html', controller: ReceiptCtrl, resolve: ReceiptCtrl.resolve}). when('/Purchase', {templateUrl: '/partial/purchase.html', controller: PurchaseCtrl, resolve: PurchaseCtrl.resolve}). diff --git a/brewman/brewman/static/scripts/payment.js b/brewman/brewman/static/scripts/payment.js index e1af7564..8ec88d2a 100644 --- a/brewman/brewman/static/scripts/payment.js +++ b/brewman/brewman/static/scripts/payment.js @@ -1,21 +1,21 @@ 'use strict'; var PaymentCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher', 'ledgers', 'Account', function ($scope, $location, $q, dateFilter, $modal, voucher, ledgers, Account) { + $('#txtAccount').focus(); + $scope.voucher = voucher; $scope.ledgers = ledgers; - function getOldJournal(ledgerID, journals) { - for (var i = 0, l = journals.length; i < l; i++) { - if (journals[i].Ledger.LedgerID === ledgerID) { - return journals[i]; - } - } + function getOld(ledgerID, journals) { + return _.find(journals, function (journal) { + return journal.Ledger.LedgerID === ledgerID; + }); } $scope.add = function () { if (!$scope.account || !$scope.account.LedgerID || !$scope.amount || Number(!$scope.amount)) { return; } - var oldJournal = getOldJournal($scope.account.LedgerID, this.voucher.Journals); + var oldJournal = getOld($scope.account.LedgerID, this.voucher.Journals); if (typeof oldJournal === 'undefined') { this.voucher.Journals.push({Debit: 1, Amount: Number($scope.amount), Ledger: $scope.account}); } else { @@ -27,7 +27,7 @@ var PaymentCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher } delete $scope.account; delete $scope.amount; - $('#txtLedger').focus(); + $('#txtAccount').focus(); }; $scope.removeJournal = function (journal) { @@ -36,18 +36,16 @@ var PaymentCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher }; $scope.$watch('voucher.Journals', function (journals, oldValue) { - var amount = 0; - if (typeof journals !== 'undefined') { - for (var i = 0, l = journals.length; i < l; i++) { - if (journals[i].Debit === -1) { - var creditJournal = journals[i]; - } else { - amount += Number(journals[i].Amount); - } - } - if (creditJournal.Amount !== amount) { - creditJournal.Amount = amount; - } + var amount = _.chain(journals) + .where({'Debit': 1}) + .reduce(function (sum, item) { + return item.Amount + sum; + }, 0).value(); + + var j = _.find(journals,{'Debit': -1}); + j.Amount = amount; + if (_.find(oldValue, {'Debit': -1}).Ledger.LedgerID !== j.Ledger.LedgerID) { + $location.path('/Payment').search({a: j.Ledger.LedgerID}).replace(); } }, true); @@ -116,7 +114,7 @@ var PaymentCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher }); modalInstance.result.then(function (updated) { if (updated.Ledger.LedgerID !== $scope.selectedJournal.Ledger.LedgerID) { - var oldJournal = getOldJournal(updated.Ledger.LedgerID, $scope.voucher.Journals); + var oldJournal = getOld(updated.Ledger.LedgerID, $scope.voucher.Journals); if (typeof oldJournal !== 'undefined') { delete $scope.selectedJournal; return false; @@ -152,7 +150,7 @@ var PaymentCtrl = ['$scope', '$location', '$q', 'dateFilter', '$modal', 'voucher $scope.accounts = function ($viewValue) { var deferred = $q.defer(); - Account.autocomplete({term: $viewValue, count: 20, a:true}, function (result) { + Account.autocomplete({term: $viewValue, count: 20, a: true}, function (result) { deferred.resolve(result); }); return deferred.promise; @@ -164,13 +162,18 @@ PaymentCtrl.resolve = { var deferred = $q.defer(); var id = $route.current.params.id; + var account = $route.current.params.a; var successCb = function (result) { deferred.resolve(result); }; if (typeof id === 'undefined') { - Voucher.get({type: 'Payment'}, successCb); + var options = {type: 'Payment'}; + if (!angular.isUndefined(account)) { + options.a = account; + } + Voucher.get(options, successCb); } else { Voucher.get({id: id}, successCb); } diff --git a/brewman/brewman/static/scripts/receipt.js b/brewman/brewman/static/scripts/receipt.js index b6bb2730..1f8b1406 100644 --- a/brewman/brewman/static/scripts/receipt.js +++ b/brewman/brewman/static/scripts/receipt.js @@ -1,21 +1,21 @@ 'use strict'; var ReceiptCtrl = ['$scope', '$routeParams', '$location', '$q', 'dateFilter', '$modal', 'voucher', 'ledgers', 'Voucher', 'Account', function ($scope, $routeParams, $location, $q, dateFilter, $modal, voucher, ledgers, Voucher, Account) { + $('#txtAccount').focus(); + $scope.voucher = voucher; $scope.ledgers = ledgers; - function getOldJournal(ledgerID, journals) { - for (var i = 0, l = journals.length; i < l; i++) { - if (journals[i].Ledger.LedgerID === ledgerID) { - return journals[i]; - } - } + function getOld(ledgerID, journals) { + return _.find(journals, function (journal) { + return journal.Ledger.LedgerID === ledgerID; + }); } $scope.add = function () { if (!$scope.account || !$scope.account.LedgerID || !$scope.amount || Number(!$scope.amount)) { return; } - var oldJournal = getOldJournal($scope.account.LedgerID, this.voucher.Journals); + var oldJournal = getOld($scope.account.LedgerID, this.voucher.Journals); if (typeof oldJournal === 'undefined') { this.voucher.Journals.push({Debit: -1, Amount: Number($scope.amount), Ledger: $scope.account}); } else { @@ -27,7 +27,7 @@ var ReceiptCtrl = ['$scope', '$routeParams', '$location', '$q', 'dateFilter', '$ } delete $scope.account; delete $scope.amount; - $('#txtLedger').focus(); + $('#txtAccount').focus(); }; $scope.removeJournal = function (journal) { @@ -36,18 +36,16 @@ var ReceiptCtrl = ['$scope', '$routeParams', '$location', '$q', 'dateFilter', '$ }; $scope.$watch('voucher.Journals', function (journals, oldValue) { - var amount = 0; - if (typeof journals !== 'undefined') { - for (var i = 0, l = journals.length; i < l; i++) { - if (journals[i].Debit === 1) { - var debitJournal = journals[i]; - } else { - amount += Number(journals[i].Amount); - } - } - if (debitJournal.Amount !== amount) { - debitJournal.Amount = amount; - } + var amount = _.chain(journals) + .where({'Debit': -1}) + .reduce(function (sum, item) { + return item.Amount + sum; + }, 0).value(); + + var j = _.find(journals, {'Debit': 1}); + j.Amount = amount; + if (_.find(oldValue, {'Debit': 1}).Ledger.LedgerID !== j.Ledger.LedgerID) { + $location.path('/Receipt').search({a: j.Ledger.LedgerID}).replace(); } }, true); @@ -116,7 +114,7 @@ var ReceiptCtrl = ['$scope', '$routeParams', '$location', '$q', 'dateFilter', '$ }); modalInstance.result.then(function (updated) { if (updated.Ledger.LedgerID !== $scope.selectedJournal.Ledger.LedgerID) { - var oldJournal = getOldJournal(updated.Ledger.LedgerID, $scope.voucher.Journals); + var oldJournal = getOld(updated.Ledger.LedgerID, $scope.voucher.Journals); if (typeof oldJournal !== 'undefined') { delete $scope.selectedJournal; return false; @@ -152,7 +150,7 @@ var ReceiptCtrl = ['$scope', '$routeParams', '$location', '$q', 'dateFilter', '$ $scope.accounts = function ($viewValue) { var deferred = $q.defer(); - Account.autocomplete({term: $viewValue, count: 20, 'a':true}, function (result) { + Account.autocomplete({term: $viewValue, count: 20, 'a': true}, function (result) { deferred.resolve(result); }); return deferred.promise; @@ -164,13 +162,18 @@ ReceiptCtrl.resolve = { var deferred = $q.defer(); var id = $route.current.params.id; + var account = $route.current.params.a; var successCb = function (result) { deferred.resolve(result); }; if (typeof id === 'undefined') { - Voucher.get({type: 'Receipt'}, successCb); + var options = {type: 'Receipt'}; + if (!angular.isUndefined(account)) { + options.a = account; + } + Voucher.get(options, successCb); } else { Voucher.get({id: id}, successCb); } diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index c1107fe2..83b7e89c 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -27,6 +27,7 @@ ## + ## diff --git a/brewman/brewman/views/services/voucher/__init__.py b/brewman/brewman/views/services/voucher/__init__.py index 9277a2ed..2d353c15 100644 --- a/brewman/brewman/views/services/voucher/__init__.py +++ b/brewman/brewman/views/services/voucher/__init__.py @@ -130,7 +130,7 @@ def delete(request): DBSession.delete(b) DBSession.delete(voucher) transaction.commit() - return blank_voucher(additionalInfo=json_voucher) + return blank_voucher(info=json_voucher) @view_config(request_method='GET', route_name='api_voucher_id', renderer='json') @@ -187,28 +187,39 @@ def voucher_info(voucher): return json_voucher -def blank_voucher(type=None, date=None, additionalInfo=None): - if type is None and 'Type' not in additionalInfo: - raise ValidationError('Voucher Type is null and no information is provided in additional information') - elif type is None: - type = additionalInfo['Type'] - if date is None and 'Date' not in additionalInfo: - raise ValidationError('Both Date and Additional Information cannot be null') - elif date is None: - date = additionalInfo['Date'] - json_voucher = {'Type': type, 'Date': date, 'Posted': False, 'Narration': "", 'Journals': [], 'Inventories': []} +def blank_voucher(info): + if 'Type' not in info: + raise ValidationError('Voucher Type is null') + type = info['Type'] + if 'Date' not in info: + raise ValidationError('Date cannot be null') + json_voucher = {'Type': type, 'Date': info['Date'], 'Posted': False, 'Narration': "", 'Journals': [], 'Inventories': []} if type == 'Journal': pass elif type == 'Payment': - json_voucher['Journals'].append({'Ledger': LedgerBase.cash_in_hand(), 'Amount': 0, 'Debit': -1}) + ledger = None + if info is not None and 'Account' in info and info['Account'] is not None: + ledger = LedgerBase.by_id(info['Account']) + if ledger is not None: + ledger = {'LedgerID': ledger.id, 'Name':ledger.name} + else: + ledger = LedgerBase.cash_in_hand() + json_voucher['Journals'].append({'Ledger': ledger, 'Amount': 0, 'Debit': -1}) elif type == 'Receipt': - json_voucher['Journals'].append({'Ledger': LedgerBase.cash_in_hand(), 'Amount': 0, 'Debit': 1}) + ledger = None + if info is not None and 'Account' in info and info['Account'] is not None: + ledger = LedgerBase.by_id(info['Account']) + if ledger is not None: + ledger = {'LedgerID': ledger.id, 'Name':ledger.name} + else: + ledger = LedgerBase.cash_in_hand() + json_voucher['Journals'].append({'Ledger': ledger, 'Amount': 0, 'Debit': 1}) elif type == 'Purchase': json_voucher['Journals'].append({'Ledger': LedgerBase.local_purchase(), 'Amount': 0, 'Debit': -1}) elif type == 'Purchase Return': json_voucher['Journals'].append({'Ledger': LedgerBase.local_purchase(), 'Amount': 0, 'Debit': 1}) elif type == 'Issue': - if additionalInfo is None: + if info is None: json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()}, 'Amount': 0, 'Debit': -1, @@ -217,18 +228,18 @@ def blank_voucher(type=None, date=None, additionalInfo=None): 'Amount': 0, 'Debit': 1, 'CostCenter': {'CostCenterID': CostCenter.cost_center_kitchen()}}) - elif 'Source' in additionalInfo and 'Destination' in additionalInfo: + elif 'Source' in info and 'Destination' in info: json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()}, 'Amount': 0, 'Debit': -1, - 'CostCenter': {'CostCenterID': additionalInfo['Source']}}) + 'CostCenter': {'CostCenterID': info['Source']}}) json_voucher['Journals'].append({'Ledger': {'LedgerID': LedgerBase.all_purchases()}, 'Amount': 0, 'Debit': 1, - 'CostCenter': {'CostCenterID': additionalInfo['Destination']}}) + 'CostCenter': {'CostCenterID': info['Destination']}}) else: - json_voucher['Date'] = additionalInfo['Date'] - for item in additionalInfo['Journals']: + json_voucher['Date'] = info['Date'] + for item in info['Journals']: json_voucher['Journals'].append({'Ledger': {'LedgerID': item['Ledger']['LedgerID']}, 'Amount': 0, 'Debit': item['Debit'], diff --git a/brewman/brewman/views/services/voucher/empty_voucher.py b/brewman/brewman/views/services/voucher/empty_voucher.py index 4776fc97..06d25fea 100644 --- a/brewman/brewman/views/services/voucher/empty_voucher.py +++ b/brewman/brewman/views/services/voucher/empty_voucher.py @@ -17,12 +17,14 @@ class blank_voucher_view(object): @view_config(request_param='type=Payment', permission='Payment') def payment(self): - return self.get_blank() + account = self.request.GET.get('a', None) + return self.get_blank({'Account': account}) @view_config(request_param='type=Receipt', permission='Receipt') def receipt(self): - return self.get_blank() + account = self.request.GET.get('a', None) + return self.get_blank({'Account': account}) @view_config(request_param='type=Purchase', permission='Purchase') @@ -47,11 +49,15 @@ class blank_voucher_view(object): 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}) + return blank_voucher({'Type': voucher_type, 'Date': date, 'Source': source, 'Destination': destination}) else: return self.get_blank() - def get_blank(self): + def get_blank(self, additional_info=None): voucher_type = self.request.GET.get('type', None) - return blank_voucher(type=voucher_type, date=session_current_date(self.request)) + if additional_info is None: + additional_info = {} + additional_info['Date'] = session_current_date(self.request) + additional_info['Type'] = voucher_type + + return blank_voucher(additional_info)