summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-08-11 08:36:20 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2020-08-12 08:52:20 +0000
commit06b8af3212e2debb7e364e0b429ec6c2db5214e8 (patch)
tree1eeb97d2fd295df29a845f5ad83f324a9724cae4 /addons/web/static
parentf3ee2e0cec88495785558dd097e2c567b8364d3a (diff)
[REF] web,purchase: SampleServer: mock registry
This commit changes the API of the SampleServer's mock registry s.t. one can register a mocked version of a method, whatever the model. The former API required a specific model to be specified, and only applied on this model. However, in order to enable the sample data feature on the cohort view, the 'get_cohort_data' method needs to be mocked, whatever the concerned model. One can now register mocked methods for a specific model only (with key 'model/method') or for every models (with key 'method'). Task ID: 2282196
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/views/sample_server.js19
1 files changed, 11 insertions, 8 deletions
diff --git a/addons/web/static/src/js/views/sample_server.js b/addons/web/static/src/js/views/sample_server.js
index d5732aa979a..d716a565b32 100644
--- a/addons/web/static/src/js/views/sample_server.js
+++ b/addons/web/static/src/js/views/sample_server.js
@@ -116,8 +116,12 @@ odoo.define('web.SampleServer', function (require) {
case 'read':
return this._mockRead(params);
}
- const mock = SampleServer.mockRegistry.get(params.model);
- const mockFunction = mock && mock[params.method || params.route];
+ // this rpc can't be mocked by the SampleServer itself, so check if there is an handler
+ // in the mockRegistry: either specific for this model (with key 'model/method'), or
+ // global (with key 'method')
+ const method = params.method || params.route;
+ const mockFunction = SampleServer.mockRegistry.get(`${params.model}/${method}`) ||
+ SampleServer.mockRegistry.get(method);
if (mockFunction) {
return mockFunction.call(this, params);
}
@@ -652,12 +656,11 @@ odoo.define('web.SampleServer', function (require) {
SampleServer.UnimplementedRouteError = UnimplementedRouteError;
- // mockRegistry allows to register mock version of methods or routes for
- // specific models, for instance
- // SampleServer.mockRegistry.registry('res.partner' {
- // some_method: () => 23,
- // some_route: () => "abcd",
- // });
+ // mockRegistry allows to register mock version of methods or routes,
+ // for all models:
+ // SampleServer.mockRegistry.add('some_route', () => "abcd");
+ // for a specific model (e.g. 'res.partner'):
+ // SampleServer.mockRegistry.add('res.partner/some_method', () => 23);
SampleServer.mockRegistry = new Registry();
return SampleServer;