From 5ed198294ff73e7d5177d1bd8560ecf33a3c526b Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 19 Apr 2017 10:14:45 +0200 Subject: [PATCH] [FIX] account: fixes reconciliation mode change When reconciliating manually, it may be possible to filter between `All`, `Customers`, `Suppliers`, `Others`. When changing this mode, we could end up in a situation such as: 1) - reconciliation widget X is available - reconciliation widget line XB is being loaded - mode is changed -> reconciliation widget X is removed - reconciliation widget line XB loading finishes -> error because the parent reconciliation widget exists no more. 2) having no (or less than the expected) or too few results because removing reconciliation items (when for example we switch from supplier to customer mode) can be done asynchronically. But the code expected it to be done synchronically. Also all elements displayed were removed instead of only the ones of other types. thus instead of displaying the expected number of reconciliation items: MIN({num of record to display}, 10) the records displayed were: MIN({num of record to display}, 10 - {num records displayed before}) which could amount to 0 event if there was thousands available ones. This commit solves these two issues: 1) by not adding line to a reconciliation item without error, 2) by counting and removing displayed items correctly opw-725796 opw-728309 --- .../src/js/account_reconciliation_widgets.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/account/static/src/js/account_reconciliation_widgets.js b/addons/account/static/src/js/account_reconciliation_widgets.js index aa58012dd8a..453bd4149a5 100644 --- a/addons/account/static/src/js/account_reconciliation_widgets.js +++ b/addons/account/static/src/js/account_reconciliation_widgets.js @@ -453,6 +453,8 @@ var abstractReconciliationLine = Widget.extend({ start: function() { var self = this; + // fail silently if reconciliation widget is removed (eg. mode is changed) + var parent = this.getParent(); return self._super().then(function() { // no animation while loading @@ -468,8 +470,8 @@ var abstractReconciliationLine = Widget.extend({ return $.when(self.render()).then(function(){ self.is_consistent = true; // Make an entrance - self.animation_speed = self.getParent().animation_speed; - self.aestetic_animation_speed = self.getParent().aestetic_animation_speed; + self.animation_speed = parent.animation_speed; + self.aestetic_animation_speed = parent.aestetic_animation_speed; if (self.context.animate_entrance) { return self.$el.stop(true, true).fadeIn({ duration: self.aestetic_animation_speed, queue: false }).css('display', 'none').slideDown(self.aestetic_animation_speed); } @@ -2293,13 +2295,19 @@ var manualReconciliation = abstractReconciliation.extend({ animate_entrance = defaultIfUndef(animate_entrance, true); var self = this; var displayed_collections = self.getDisplayedCollections(); + var plural = { 'customer': 'customers', 'supplier': 'suppliers', 'account': 'others' }; self.updateProgressbar(); + // number of reconciliation items already displayed + var num_child_displayed = self.getChildren().length; + // Remove children that should not be displayed if (self.mode !== 'all') { _.each(self.getChildren(), function(child) { - if (child.data.reconciliation_type !== self.mode) { + var type = plural[child.data.reconciliation_type]; + if (type !== self.mode) { + num_child_displayed--; child.$el.slideUp(self.aestetic_animation_speed, function(){ child.destroy() }); child.data.displayed = false; } @@ -2312,7 +2320,7 @@ var manualReconciliation = abstractReconciliation.extend({ var items_to_display = _.foldl(displayed_collections, function(prev, current){ return prev.concat(current.items) }, []); // Filter out those which are already displayed items_to_display = _.filter(items_to_display, function(item) { return item.displayed === false; }) - .slice(0, self.num_reconciliations_fetched_in_batch - self.getChildren().length); + .slice(0, self.num_reconciliations_fetched_in_batch - num_child_displayed); _.each(items_to_display, function(item){ children_promises.push(self.displayReconciliation(item, animate_entrance)); });