-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Voucher cash transfer, generic income and expense tools #1586
Conversation
@jniles could you review this PR |
@mbayopanda this is ~900 lines of code to review + functionality .. it's a lot for me to review here at Vanga. You can either ask @sfount to do it, or I'll review it when I get back... |
@mbayopanda @jniles I will look at this pull request this morning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will be reviewing the functionality of this pull request soon, I have made some comments on how the code here can be significantly reduced - this would help make it much easier to read!
lastRow.configure(rows[n]); | ||
} | ||
|
||
setTimeout(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use the Angular js library $timeout which ensures that methods are called within $apply
etc.
It would also be useful to leave a comment here explaining why this timeout of 0 seconds is needed!
@@ -105,6 +111,134 @@ function ComplexJournalVoucherController(Vouchers, $translate, Currencies, Sessi | |||
}); | |||
} | |||
|
|||
// open generic income function | |||
function openGenericIncomeTool() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that all of these tool chains do exactly the same thing which is to configure the rows - we could greatly reduce the code here by making all of these one function.
For example:
Toolkit.open(voucherTool)
.then(processVoucherToolRows);
function processVoucherToolRows(result) {
// ...
}
We also then may not even need the opening methods - I'm not sure exactly how this would work:
genericIncomeTool.action = openVoucherTool(genericIncomeTool);
function openVoucherTool(voucherTool) {
return function() {
Toolkit.open(voucherTool) //...
}
}
There are a lot of patterns here that could be reduced into helper methods with clear comments!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:+1
// initial clear | ||
vm.Voucher.clear(); | ||
|
||
while (n--) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be written as a helper method on the VoucherFormService
? It seems like it may be used a lot.
For example:
// voucher-form.service.js
VoucherForm.prototype.replaceFormRows = function replaceFormRows(rows) {
this.clear();
rows.forEach(function (row) {
//...
});
}
I would also encourage using methods on arrays like forEach
and map
, while
loops are useful for creating utilities that do not create an additional scope however methods like forEach
and map
are much easier to read and understand for other developers.
☔ The latest upstream changes (presumably 2ff9b91) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -0,0 +1,4 @@ | |||
<a href> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What typeahead dropdown does Complex Vouchers use? Can this code be removed and your PR use the same one?
* @param {object} result | ||
*/ | ||
function updateView(result) { | ||
$timeout(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use:
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ROW);
does this eliminate the need to $timeout()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it's doesn't fill the need.
* | ||
* @description remove null rows | ||
*/ | ||
function removeNullRows() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a well-named function. 👍
@@ -41,7 +56,8 @@ function VoucherToolkitService($http, Modal, util) { | |||
controller : option.controller, | |||
controllerAs : 'ToolCtrl', | |||
size : 'md', | |||
resolve : { data : function () { return option; } } | |||
backdrop : 'static', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
}; | ||
} | ||
|
||
// on select cashbox |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these functions for and why are they empty?
account : vm.account, | ||
}); | ||
|
||
var msgTransfer = $translate.instant('VOUCHERS.GLOBAL.CASH_TRANSFER'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be much easier to maintain if you use one translate key and then do parameter substition as proposed in #408.
Like this:
var ms = $translate.instant('VOUCHER.TOOLS.SOME_DESCRIPTION', {
cashbox: vm.cashbox.label,
account: vm.account.label,
amount: vm.amount,
symbol : vm.cashbox.symbol
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
VoucherForm.prototype.replaceFormRows = function replaceFormRows(rows) { | ||
this.clear(); | ||
|
||
var form = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice alias 👍
var lastRowIdx = form.store.data.length - 1; | ||
var lastRow = form.store.data[lastRowIdx]; | ||
|
||
lastRow.configure(rows[--n]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is creative!
The reason I originally used while (n--)
was to make sure we were adding the rows on to the end of the complex voucher. Since you are directly accessing the store, there is no need for this anymore.
Can you just do lastRow.configure(row)
?
@@ -54,8 +54,8 @@ | |||
<tr> | |||
<td>{{number}}</td> | |||
<td>{{label}}</td> | |||
<td class="text-right">{{currency debit currency_id}}</td> | |||
<td class="text-right">{{currency credit currency_id}}</td> | |||
<td class="text-right">{{currency debit ../details.currency_id}}</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -54,8 +54,8 @@ | |||
<tr> | |||
<td>{{number}}</td> | |||
<td>{{label}}</td> | |||
<td class="text-right">{{currency debit currency_id}}</td> | |||
<td class="text-right">{{currency credit currency_id}}</td> | |||
<td class="text-right">{{currency debit ../details.currency_id}}</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #1595
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me!
Instance.close({ | ||
rows : bundle, | ||
description : msg, | ||
type_id : bhConstants.transactionType.TRANSFER, // Cash transfer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
account : vm.account, | ||
}); | ||
|
||
var msg = $translate.instant('VOUCHERS.GLOBAL.TRANSFER_DESCRIPTION', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
(<label class="control-label" translate>FORM.LABELS.CREDIT</label>) | ||
|
||
<!-- input typeahead --> | ||
<input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point, we should formalize when to use an account typeahead versus an account ui-select. We could eliminate a lot of code from this PR if we used a component!
@jniles could you review this PR please |
LGTM! |
Fix grid rows updating Test e2e for generic income and expense Cash transfer tool and test update test values Fix and enhancements Fix test e2e Fix and enhancements voucher tools Fix and enhancements
This PR add tools for journal voucher :
issue #1550