From 3ff0568051af25c39573181d9eca8df626a298e1 Mon Sep 17 00:00:00 2001 From: Cyril Gaudin Date: Tue, 24 May 2016 17:37:40 +0200 Subject: [PATCH] fix a weird asynchronous stuff bug --- .../static/src/js/account_widgets.js | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/account_operation_rule/static/src/js/account_widgets.js b/account_operation_rule/static/src/js/account_widgets.js index e4bb34c1..8d7a34a7 100644 --- a/account_operation_rule/static/src/js/account_widgets.js +++ b/account_operation_rule/static/src/js/account_widgets.js @@ -7,20 +7,45 @@ odoo.define('account_operation_rule', function (require) { var reconciliation = require('account.reconciliation'); reconciliation.bankStatementReconciliationLine.include({ + init: function(parent, context) { + this._super(parent, context); + this.preset_auto_clicked = false; + }, + operation_rules: function () { var self = this; var model_operation_rule = new Model("account.operation.rule"); model_operation_rule.call("operations_for_reconciliation", - [self.st_line.id, - _.pluck(self.get("mv_lines_selected"), 'id')]) - .then(function (operations) { - _.each(operations, function (operation_id) { - var preset_btn = self.$("button.preset[data-presetid='" + operation_id + "']"); - preset_btn.click(); - self.addLineBeingEdited(); - }); + [self.st_line.id, _.pluck(self.get("mv_lines_selected"), 'id')] + ).then(function (operations) { + _.each(operations, function (operation_id) { + var preset_btn = self.$("button.preset[data-presetid='" + operation_id + "']"); + preset_btn.trigger('click'); + + // Cannot click on add_line link for user here + // even with a when().done() + // because preset_btn click handler makes a rpc call + // via formCreateInputChanged method + // and we have to wait for response + self.preset_auto_clicked = true; }); + }); }, + + /** + * Click on add_line link if preset button have been clicked + * automatically. + */ + formCreateInputChanged: function(elt, val) { + var self = this; + var deferred = this._super(elt, val); + deferred.done(function() { + if (self.preset_auto_clicked) { + self.addLineBeingEdited(); + } + }); + }, + render: function () { var deferred = this._super(); if (deferred) {