diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index a877dd15f17..8493bcebe24 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -588,20 +588,16 @@ class account_bank_statement_line(osv.osv): if not st_line.partner_id.id: return [] - # Look for a set of move line whose amount is <= to the line's amount + # Select move lines until their total amount is greater than the statement line amount domain += [('account_id.type', 'in', ((amount > 0 and 'receivable' or 'payable'), 'liquidity'))] # Make sure we can't mix receivable and payable - if amount_field == 'amount_currency' and amount < 0: - domain += [(amount_field, '<', 0), (amount_field, '>', (sign * amount))] - else: - domain += [(amount_field, '>', 0), (amount_field, '<', (sign * amount))] + domain += (amount_field == 'amount_currency' and amount < 0) and [(amount_field, '<', 0)] or [(amount_field, '>', 0)] mv_lines = self.get_move_lines_for_reconciliation(cr, uid, st_line, excluded_ids=excluded_ids, limit=5, additional_domain=domain) ret = [] total = 0 for line in mv_lines: total += abs(line['debit'] - line['credit']) - if float_compare(total, abs(amount), precision_digits=precision_digits) != 1: - ret.append(line) - else: + ret.append(line) + if float_compare(total, abs(amount), precision_digits=precision_digits) != -1: break return ret diff --git a/addons/account/static/src/js/widgets.js b/addons/account/static/src/js/widgets.js index dab4b98860a..8e57c499092 100644 --- a/addons/account/static/src/js/widgets.js +++ b/addons/account/static/src/js/widgets.js @@ -1348,12 +1348,13 @@ var bankStatementReconciliationLine = Widget.extend({ // Show or hide partial reconciliation if (self.get("mv_lines_selected").length > 0) { + var last_line = _.last(self.get("mv_lines_selected")); var propose_partial = self.getCreatedLines().length === 0 - && self.get("mv_lines_selected").length === 1 && balance_type === "greater" - && ! self.get("mv_lines_selected")[0].partial_reconcile + && Math.abs(self.get("balance")) < Math.abs(last_line.debit - last_line.credit) + && ! last_line.partial_reconcile && ! self.is_rapprochement; - self.get("mv_lines_selected")[0].propose_partial_reconcile = propose_partial; + last_line.propose_partial_reconcile = propose_partial; self.updateAccountingViewMatchedLines(); } @@ -1452,7 +1453,13 @@ var bankStatementReconciliationLine = Widget.extend({ mvLinesSelectedChanged: function(elt, val) { var self = this; - + + // Reset partial reconciliation + _.each(self.get("mv_lines_selected"), function(line) { + if (line.partial_reconcile === true) self.unpartialReconcileLine(line); + if (line.propose_partial_reconcile === true) line.propose_partial_reconcile = false; + }); + var added_lines = _.difference(val.newValue, val.oldValue); var removed_lines = _.difference(val.oldValue, val.newValue); @@ -1600,16 +1607,6 @@ var bankStatementReconciliationLine = Widget.extend({ updateBalance: function() { var self = this; var mv_lines_selected = self.get("mv_lines_selected"); - var lines_selected_num = mv_lines_selected.length; - - // Undo partial reconciliation if necessary - if (lines_selected_num !== 1) { - _.each(mv_lines_selected, function(line) { - if (line.partial_reconcile === true) self.unpartialReconcileLine(line); - if (line.propose_partial_reconcile === true) line.propose_partial_reconcile = false; - }); - self.updateAccountingViewMatchedLines(); - } // Compute balance var balance = 0;