[IMP] account: bank statement reconciliation widget: ctrl-enter makes only 1 RPC call

This commit is contained in:
Arthur Maniet 2014-09-16 17:15:54 +02:00
parent c6ca31dd9f
commit 197ce282bd
4 changed files with 93 additions and 24 deletions

View File

@ -554,7 +554,7 @@ class account_bank_statement_line(osv.osv):
sign = -1
if st_line.amount_currency:
amount = st_line.amount_currency
else:
else:
amount = st_line.amount
match_id = self.get_move_lines_for_reconciliation(cr, uid, st_line, excluded_ids=excluded_ids, offset=0, limit=1, additional_domain=[(amount_field, '=', (sign * amount))])
@ -650,6 +650,10 @@ class account_bank_statement_line(osv.osv):
'account_id': account_id
}
def process_reconciliations(self, cr, uid, data, context=None):
for datum in data:
self.process_reconciliation(cr, uid, datum[0], datum[1], context=context)
def process_reconciliation(self, cr, uid, id, mv_line_dicts, context=None):
""" Creates a move line for each item of mv_line_dicts and for the statement line. Reconcile a new move line with its counterpart_move_line_id if specified. Finally, mark the statement line as reconciled by putting the newly created move id in the column journal_entry_id.

View File

@ -137,9 +137,8 @@
transform: rotate(90deg); }
.openerp .oe_bank_statement_reconciliation .oe_bank_statement_reconciliation_line .partner_name .change_partner {
display: none;
cursor: pointer; }
.openerp .oe_bank_statement_reconciliation .oe_bank_statement_reconciliation_line .partner_name .change_partner .glyphicon {
margin: 0 5px; }
cursor: pointer;
margin: 0 10px 0 5px; }
.openerp .oe_bank_statement_reconciliation .oe_bank_statement_reconciliation_line .partner_name:hover .change_partner {
display: inline; }
.openerp .oe_bank_statement_reconciliation .oe_bank_statement_reconciliation_line .change_partner_container {

View File

@ -200,10 +200,7 @@ $aestetic_animation_speed: 300ms;
.change_partner {
display: none;
cursor: pointer;
.glyphicon {
margin: 0 5px;
}
margin: 0 10px 0 5px;
}
&:hover .change_partner {
display: inline;

View File

@ -283,14 +283,81 @@ openerp.account = function (instance) {
keyboardShortcutsHandler: function(e) {
var self = this;
if ((e.which === 13 || e.which === 10) && (e.ctrlKey || e.metaKey)) {
$.each(self.getChildren(), function(i, o){
if (o.is_valid && o.persistAndDestroy()) {
self.lines_reconciled_with_ctrl_enter++;
}
});
self.persistReconciliations(_.filter(self.getChildren(), function(o) { return o.is_valid; }));
}
},
persistReconciliations: function(reconciliations) {
if (reconciliations.length === 0) return;
var self = this;
// Prepare data
var data = [];
for (var i=0; i<reconciliations.length; i++) {
var child = reconciliations[i];
data.push([child.st_line_id, child.makeMoveLineDicts()]);
}
var deferred_animation = self.$(".reconciliation_lines_container").fadeOut(self.aestetic_animation_speed);
deferred_rpc = self.model_bank_statement_line.call("process_reconciliations", [data]);
return $.when(deferred_animation, deferred_rpc)
.done(function() {
// Remove children
for (var i=0; i<reconciliations.length; i++) {
var child = reconciliations[i];
self.unexcludeMoveLines(child, child.partner_id, child.get("mv_lines_selected"));
$.each(child.$(".bootstrap_popover"), function(){ $(this).popover('destroy') });
child.destroy();
}
// Update interface
self.lines_reconciled_with_ctrl_enter += reconciliations.length;
self.reconciled_lines += reconciliations.length;
self.updateProgressbar();
self.doReloadMenuReconciliation();
// Display new line if there are left
if (self.last_displayed_reconciliation_index < self.st_lines.length) {
var begin = self.last_displayed_reconciliation_index;
var end = Math.min((begin+self.max_reconciliations_displayed), self.st_lines.length);
var reconciliations_to_show = self.st_lines.slice(begin, end);
return self.model_bank_statement_line
.call("get_data_for_reconciliations", [reconciliations_to_show])
.then(function (data) {
var child_promises = [];
var datum;
while ((datum = data.shift()) !== undefined) {
var context = {
st_line_id: datum.st_line.id,
mode: 'inactive',
animate_entrance: false,
initial_data_provided: true,
st_line: datum.st_line,
reconciliation_proposition: datum.reconciliation_proposition,
};
var widget = new instance.web.account.bankStatementReconciliationLine(self, context);
child_promises.push(widget.appendTo(self.$(".reconciliation_lines_container")));
}
self.last_displayed_reconciliation_index += reconciliations_to_show.length;
return $.when.apply($, child_promises).then(function() {
// Put the first line in match mode
if (self.reconciled_lines !== self.st_lines.length) {
var first_child = self.getChildren()[0];
if (first_child.get("mode") === "inactive") {
first_child.set("mode", "match");
}
}
self.$(".reconciliation_lines_container").fadeIn(self.aestetic_animation_speed);
});
});
}
// Congratulate the user if the work is done
if (self.reconciled_lines === self.st_lines.length) {
self.displayDoneMessage();
}
}).fail(function() {
self.$(".reconciliation_lines_container").fadeIn(self.aestetic_animation_speed);
});
},
// Adds move line ids to the list of move lines not to fetch for a given partner
// This is required because the same move line cannot be selected for multiple reconciliation
// and because for a partial reconciliation only one line can be fetched)
@ -644,6 +711,7 @@ openerp.account = function (instance) {
return self.model_bank_statement_line
.call("get_data_for_reconciliations", [[self.st_line_id], excluded_move_lines_ids, self.do_load_reconciliation_proposition])
.then(function (data) {
console.log(data);
self.st_line = data[0].st_line;
self.decorateStatementLine(self.st_line);
self.partner_id = data[0].st_line.partner_id;
@ -1542,6 +1610,7 @@ openerp.account = function (instance) {
.call("write", [[self.st_line_id], {'partner_id': partner_id}])
.then(function () {
self.do_load_reconciliation_proposition = false; // of the server might set the statement line's partner
self.animation_speed = 0;
return $.when(self.restart(self.get("mode"))).then(function(){
self.do_load_reconciliation_proposition = true;
self.is_consistent = true;
@ -1589,6 +1658,15 @@ openerp.account = function (instance) {
return dict;
},
makeMoveLineDicts: function() {
var self = this;
var mv_line_dicts = [];
_.each(self.get("mv_lines_selected"), function(o) { mv_line_dicts.push(self.prepareSelectedMoveLineForPersisting(o)) });
_.each(self.getCreatedLines(), function(o) { mv_line_dicts.push(self.prepareCreatedMoveLineForPersisting(o)) });
if (Math.abs(self.get("balance")).toFixed(3) !== "0.000") mv_line_dicts.push(self.prepareOpenBalanceForPersisting());
return mv_line_dicts;
},
// Persist data, notify parent view and terminate widget
persistAndDestroy: function(speed) {
@ -1608,7 +1686,8 @@ openerp.account = function (instance) {
var deferred_animation = self.$el.parent().slideUp(speed*height/150);
// RPC
return $.when(self.makeRPCForPersisting())
return self.model_bank_statement_line
.call("process_reconciliation", [self.st_line_id, self.makeMoveLineDicts()])
.then(function () {
$.each(self.$(".bootstrap_popover"), function(){ $(this).popover('destroy') });
return $.when(deferred_animation).then(function(){
@ -1624,16 +1703,6 @@ openerp.account = function (instance) {
});
});
},
makeRPCForPersisting: function() {
var self = this;
var mv_line_dicts = [];
_.each(self.get("mv_lines_selected"), function(o) { mv_line_dicts.push(self.prepareSelectedMoveLineForPersisting(o)) });
_.each(self.getCreatedLines(), function(o) { mv_line_dicts.push(self.prepareCreatedMoveLineForPersisting(o)) });
if (Math.abs(self.get("balance")).toFixed(3) !== "0.000") mv_line_dicts.push(self.prepareOpenBalanceForPersisting());
return self.model_bank_statement_line
.call("process_reconciliation", [self.st_line_id, mv_line_dicts]);
},
});
instance.web.views.add('tree_account_reconciliation', 'instance.web.account.ReconciliationListView');