From b36b8b804e6385493683940c65fbcfc3b3f79016 Mon Sep 17 00:00:00 2001 From: chien Date: Fri, 28 Jul 2023 09:30:04 +0700 Subject: [PATCH] [FIX] web_m2x_options: Avoid constant RPC calls Instead of calling interactively to the server to get the options, they are stored at the beginning of the session. --- web_m2x_options/models/__init__.py | 1 + web_m2x_options/models/ir_http.py | 11 ++++++++++ .../static/src/components/form.esm.js | 20 +++---------------- .../src/components/relational_utils.esm.js | 14 ++----------- 4 files changed, 17 insertions(+), 29 deletions(-) create mode 100644 web_m2x_options/models/ir_http.py diff --git a/web_m2x_options/models/__init__.py b/web_m2x_options/models/__init__.py index bd3aa9f10..60b90d385 100644 --- a/web_m2x_options/models/__init__.py +++ b/web_m2x_options/models/__init__.py @@ -1 +1,2 @@ from . import ir_config_parameter +from . import ir_http diff --git a/web_m2x_options/models/ir_http.py b/web_m2x_options/models/ir_http.py new file mode 100644 index 000000000..f7933c4d2 --- /dev/null +++ b/web_m2x_options/models/ir_http.py @@ -0,0 +1,11 @@ +from odoo import models + + +class Http(models.AbstractModel): + _inherit = "ir.http" + + def session_info(self): + IrConfigSudo = self.env["ir.config_parameter"].sudo() + session_info = super().session_info() + session_info.update({"web_m2x_options": IrConfigSudo.get_web_m2x_options()}) + return session_info diff --git a/web_m2x_options/static/src/components/form.esm.js b/web_m2x_options/static/src/components/form.esm.js index 2b2923105..5ff7efe82 100644 --- a/web_m2x_options/static/src/components/form.esm.js +++ b/web_m2x_options/static/src/components/form.esm.js @@ -19,7 +19,7 @@ import {patch} from "@web/core/utils/patch"; import {sprintf} from "@web/core/utils/strings"; import {useService} from "@web/core/utils/hooks"; -const {Component, onWillStart} = owl; +const {Component} = owl; /** * Patch Many2ManyTagsField @@ -157,16 +157,7 @@ CreateConfirmationDialog.template = patch(Many2OneField.prototype, "web_m2x_options.Many2OneField", { setup() { this._super(...arguments); - const ormService = useService("orm"); - this.user_context = Component.env.session.user_context; - onWillStart(async () => { - this.ir_options = await ormService.call( - "ir.config_parameter", - "get_web_m2x_options", - [], - {context: this.user_context} - ); - }); + this.ir_options = Component.env.session.web_m2x_options; }, /** * @override @@ -371,12 +362,7 @@ patch(FormController.prototype, "web_m2x_options.FormController", { * add more method to add subview limit on formview */ async _setSubViewLimit() { - const ir_options = await this.model.orm.call( - "ir.config_parameter", - "get_web_m2x_options", - [], - {context: this.user_context} - ); + const ir_options = Component.env.session.web_m2x_options; const activeFields = this.archInfo.activeFields, fields = this.props.fields, diff --git a/web_m2x_options/static/src/components/relational_utils.esm.js b/web_m2x_options/static/src/components/relational_utils.esm.js index 645fa1bd9..1fbe39eae 100644 --- a/web_m2x_options/static/src/components/relational_utils.esm.js +++ b/web_m2x_options/static/src/components/relational_utils.esm.js @@ -3,8 +3,7 @@ import {Many2XAutocomplete} from "@web/views/fields/relational_utils"; import {patch} from "@web/core/utils/patch"; import {sprintf} from "@web/core/utils/strings"; -import {useService} from "@web/core/utils/hooks"; -const {Component, onWillStart} = owl; +const {Component} = owl; export function is_option_set(option) { if (_.isUndefined(option)) return false; @@ -16,16 +15,7 @@ export function is_option_set(option) { patch(Many2XAutocomplete.prototype, "web_m2x_options.Many2XAutocomplete", { setup() { this._super(...arguments); - const ormService = useService("orm"); - this.user_context = Component.env.session.user_context; - onWillStart(async () => { - this.ir_options = await ormService.call( - "ir.config_parameter", - "get_web_m2x_options", - [], - {context: this.user_context} - ); - }); + this.ir_options = Component.env.session.web_m2x_options; }, async loadOptionsSource(request) {