Permalink
Browse files

[IMP] account: reconciliation: improve search based on amount

FIX: amount_currency can allow negative searches
IMP: can search on positive or negative amount only if use '-' or '+'
IMP: search for move lines based on the amount by clicking on the balance
amount. Search in 2 currencies if possible.
  • Loading branch information...
Gorash committed Oct 18, 2017
1 parent 51d676d commit c09a62749bc593487c4320158253c27afe7f76bb
@@ -651,19 +651,36 @@ def domain_move_lines_for_reconciliation(self, str):
'|', ('date_maturity', 'like', str),
'&', ('name', '!=', '/'), ('name', 'ilike', str)
]
try:
amount = float(str)
amount_domain = [
'|', ('amount_residual', '=', amount),
'|', ('amount_residual_currency', '=', amount),
'|', ('amount_residual', '=', -amount),
'|', ('amount_residual_currency', '=', -amount),
'&', ('account_id.internal_type', '=', 'liquidity'),
'|', '|', ('debit', '=', amount), ('credit', '=', amount), ('amount_currency', '=', amount),
]
str_domain = expression.OR([str_domain, amount_domain])
except:
pass
if str[0] in ['-', '+']:
try:
amounts_str = str.split('|')
for amount_str in amounts_str:
amount = amount_str[0] == '-' and float(amount_str) or float(amount_str[1:])
amount_domain = [
'|', ('amount_residual', '=', amount),
'|', ('amount_residual_currency', '=', amount),
'|', (amount_str[0] == '-' and 'credit' or 'debit', '=', float(amount_str[1:])),
('amount_currency', '=', amount),
]
str_domain = expression.OR([str_domain, amount_domain])
except:
pass
else:
try:
amount = float(str)
amount_domain = [
'|', ('amount_residual', '=', amount),
'|', ('amount_residual_currency', '=', amount),
'|', ('amount_residual', '=', -amount),
'|', ('amount_residual_currency', '=', -amount),
'&', ('account_id.internal_type', '=', 'liquidity'),
'|', '|', '|', ('debit', '=', amount), ('credit', '=', amount),
('amount_currency', '=', amount),
('amount_currency', '=', -amount),
]
str_domain = expression.OR([str_domain, amount_domain])
except:
pass
return str_domain
def _domain_move_lines_for_manual_reconciliation(self, account_id, partner_id=False, excluded_ids=None, str=False):
@@ -20,6 +20,7 @@ var StatementAction = Widget.extend(ControlPanelMixin, {
change_offset: '_onAction',
change_partner: '_onAction',
add_proposition: '_onAction',
search_balance_amount: '_onAction',
remove_proposition: '_onAction',
update_proposition: '_onAction',
create_proposition: '_onAction',
@@ -493,6 +493,25 @@ var StatementModel = BasicModel.extend({
}
return def;
},
searchBalanceAmount: function (handle) {
var line = this.getLine(handle);
var amount = line.balance.amount;
var amount_str = _.str.sprintf('%.2f', Math.abs(amount));
amount_str = (amount > '0' ? '-' : '+') + amount_str;
if (line.balance.amount_currency) {
var amount_currency = line.balance.amount_currency;
var amount_currency_str = _.str.sprintf('%.2f', Math.abs(amount_currency));
amount_str += '|' + (amount_currency > '0' ? '-' : '+') + amount_currency_str;
}
if (amount_str === line.filter) {
line.filter = '';
line.offset = 0;
return this.changeMode(handle, 'create');
}
line.filter = amount_str;
line.offset = 0;
return this.changeMode(handle, 'match');
},
/**
* Force the partial reconciliation to display the reconciliate button.
* This method should only be called when there is onely one proposition.
@@ -792,12 +811,14 @@ var StatementModel = BasicModel.extend({
amount: total,
amount_str: field_utils.format.monetary(Math.abs(total), {}, formatOptions),
currency_id: isOtherCurrencyId,
amount_currency: isOtherCurrencyId ? amount_currency : false,
amount_currency_str: isOtherCurrencyId ? field_utils.format.monetary(Math.abs(amount_currency), {}, {
currency_id: isOtherCurrencyId
}) : false,
account_code: self.accounts[line.st_line.open_balance_account_id],
};
line.balance.type = line.balance.amount ? (line.balance.amount > 0 && line.st_line.partner_id ? 0 : -1) : 1;
line.balance.type = (isOtherCurrencyId && amount_currency || line.balance.amount) ?
(line.balance.amount > 0 && line.st_line.partner_id ? 0 : -1) : 1;
});
},
/**
@@ -1258,7 +1279,7 @@ var ManualModel = StatementModel.extend({
*/
_computeLine: function (line) {
return this._super(line).then(function () {
var props = line.reconciliation_proposition;
var props = _.reject(line.reconciliation_proposition, 'invalid');
line.balance.type = -1;
if (!line.balance.amount && props.length) {
line.balance.type = 1;
@@ -242,7 +242,8 @@ var LineRenderer = Widget.extend(FieldManagerMixin, {
events: {
'click .accounting_view caption .o_buttons button': '_onValidate',
'click .accounting_view thead td': '_onTogglePanel',
'click .accounting_view tfoot td': '_onShowPanel',
'click .accounting_view tfoot td:not(.cell_left,.cell_right)': '_onShowPanel',
'click tfoot .cell_left, tfoot .cell_right': '_onSearchBalanceAmount',
'input input.filter': '_onFilterChange',
'click .match_controls .fa-chevron-left:not(.disabled)': '_onPrevious',
'click .match_controls .fa-chevron-right:not(.disabled)': '_onNext',
@@ -395,6 +396,11 @@ var LineRenderer = Widget.extend(FieldManagerMixin, {
this.$('.popover').remove();
this.$('table tfoot').html(qweb.render("reconciliation.line.balance", {'state': state}));
// filter
if (_.str.strip(this.$('input.filter').val()) !== state.filter) {
this.$('input.filter').val(state.filter);
}
// create form
if (state.createForm) {
if (!this.fields.account_id) {
@@ -583,6 +589,12 @@ var LineRenderer = Widget.extend(FieldManagerMixin, {
var mode = this.$el.data('mode') === 'inactive' ? 'match' : 'inactive';
this.trigger_up('change_mode', {'data': mode});
},
/**
* @private
*/
_onSearchBalanceAmount: function () {
this.trigger_up('search_balance_amount');
},
/**
* @private
*/

0 comments on commit c09a627

Please sign in to comment.