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)); });