From 79e4a1f1b116a447b72fb9d1c846260ae6b3ac2c Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 8 Jun 2017 10:11:50 +0200 Subject: [FIX] web: ModelFieldSelector: add a way to clear the cache The ModelFieldSelector keeps an internal cache for the fields_get. This cache needs to be cleared in the tests environment because a model with the same name may be defined several times accross the tests modules, but they may contain different fields. This could also be a problem with studio: when a field is created, the ModelFieldSelector cache must be cleared as well (in addition to the data_manager one). We thus introduce a new 'clear_cache' event on core.bus. When triggered, the ModelFieldSelector and the data_manager clear their respective cache. We use this event in the test environment to ensure that the cache is cleared at the end of each test using a mockEnvironment. This rev. also fixes an infinite loop in the override of destroy() in the mockEnvironment, which occured when both session and config were specified in the params. --- addons/web/static/src/js/widgets/model_field_selector.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'addons/web/static/src/js/widgets/model_field_selector.js') diff --git a/addons/web/static/src/js/widgets/model_field_selector.js b/addons/web/static/src/js/widgets/model_field_selector.js index 279428e8939..6607561a2bb 100644 --- a/addons/web/static/src/js/widgets/model_field_selector.js +++ b/addons/web/static/src/js/widgets/model_field_selector.js @@ -16,6 +16,11 @@ var modelFieldsCache = { cacheDefs: {}, }; +core.bus.on('clear_cache', null, function () { + modelFieldsCache.cache = {}; + modelFieldsCache.cacheDefs = {}; +}); + /** * The ModelFieldSelector widget can be used to display/select a particular * field chain from a given model. -- cgit v1.2.3