From 9c52041741e5ccb24b9019519d969de853ded272 Mon Sep 17 00:00:00 2001 From: Jessica Date: Fri, 9 Sep 2022 04:51:49 -0500 Subject: [PATCH] [BLUE-1][ADD] Added responsive view description to control panel area --- addons/web/controllers/main.py | 6 +++- .../src/legacy/js/chrome/abstract_action.js | 14 ++++++++ .../src/legacy/js/chrome/action_mixin.js | 32 +++++++++++++++++++ .../legacy/js/control_panel/control_panel.js | 1 + .../src/legacy/js/views/abstract_view.js | 1 + addons/web/static/src/legacy/xml/base.xml | 7 ++++ .../src/search/control_panel/control_panel.js | 5 ++- .../search/control_panel/control_panel.scss | 11 +++++++ .../search/control_panel/control_panel.xml | 9 +++++- .../src/webclient/actions/action_service.js | 7 ++++ odoo/addons/base/models/ir_actions.py | 6 ++-- odoo/addons/base/views/ir_actions_views.xml | 3 +- 12 files changed, 96 insertions(+), 6 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 114009a784616..b54e5e0afb3f7 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -282,6 +282,10 @@ def generate_views(action): # providing at least one view mode is a requirement, not an option view_modes = action['view_mode'].split(',') + # BLUE STINGRAY / METRIC WISE CUSTOM + # make sure the view_description is instantiated + view_description = action['view_description'] or False + if len(view_modes) > 1: if view_id: raise ValueError('Non-db action dictionaries should provide ' @@ -291,7 +295,7 @@ def generate_views(action): view_modes, view_id, action)) action['views'] = [(False, mode) for mode in view_modes] return - action['views'] = [(view_id, view_modes[0])] + action['views'] = [(view_id, view_modes[0], view_description)] def fix_view_modes(action): """ For historical reasons, Odoo has weird dealings in relation to diff --git a/addons/web/static/src/legacy/js/chrome/abstract_action.js b/addons/web/static/src/legacy/js/chrome/abstract_action.js index 53c15c43d95c3..fd539ac0e47ca 100644 --- a/addons/web/static/src/legacy/js/chrome/abstract_action.js +++ b/addons/web/static/src/legacy/js/chrome/abstract_action.js @@ -50,6 +50,17 @@ const AbstractAction = Widget.extend(ActionMixin, { */ withSearchBar: false, + /** + * BLUE STINGRAY / METRIC WISE CUSTOM + * A client action might want to see the view description displayed in its + * control panel, or it choose not to use it. + * + * It also only makes sense if hasControlPanel is set to true. + * + * @type boolean + */ + withViewDescription: false, + /** * This parameter can be set to customize the available sub menus in the * controlpanel (Filters/Group By/Favorites). This is basically a list of @@ -74,6 +85,7 @@ const AbstractAction = Widget.extend(ActionMixin, { init: function (parent, action, options) { this._super(parent); this._title = action.display_name || action.name; + this._viewDescription = action.view_description; this.searchModelConfig = { context: Object.assign({}, action.context), @@ -86,6 +98,7 @@ const AbstractAction = Widget.extend(ActionMixin, { this.extensions.ControlPanel = { actionId: action.id, withSearchBar: this.withSearchBar, + withViewDescription: this.withViewDescription, }; this.viewId = action.search_view_id && action.search_view_id[0]; @@ -95,6 +108,7 @@ const AbstractAction = Widget.extend(ActionMixin, { breadcrumbs: options && options.breadcrumbs, withSearchBar: this.withSearchBar, searchMenuTypes: this.searchMenuTypes, + withViewDescription: this.withViewDescription, }; } }, diff --git a/addons/web/static/src/legacy/js/chrome/action_mixin.js b/addons/web/static/src/legacy/js/chrome/action_mixin.js index 82feba041026f..9a121d66a9d70 100644 --- a/addons/web/static/src/legacy/js/chrome/action_mixin.js +++ b/addons/web/static/src/legacy/js/chrome/action_mixin.js @@ -65,6 +65,14 @@ odoo.define('web.ActionMixin', function (require) { */ _title: '', + /** + * BLUE STINGRAY / METRIC WISE CUSTOM + * String containing the view description of the client action + * + * @see _setViewDescription + */ + _viewDescription: '', + /** * @override */ @@ -154,6 +162,17 @@ odoo.define('web.ActionMixin', function (require) { return this._title; }, + /** + * BLUE STINGRAY / METRIC WISE CUSTOM + * Returns a view_description that may be displayed in center of the + * control panel area. + * + * @returns {string} + */ + getViewDescription: function () { + return this._viewDescription; + }, + /** * Renders the buttons to append, in most cases, to the control panel (in * the bottom left corner). When the action is rendered in a dialog, those @@ -187,6 +206,11 @@ odoo.define('web.ActionMixin', function (require) { this.controlPanelProps.title = this.getTitle(); delete props.title; } + if ('view_description' in props) { + this._setViewDescription(props.view_description); + this.controlPanelProps.view_description = this.getViewDescription(); + delete props.view_description; + } if ('cp_content' in props) { // cp_content has been updated: refresh it. this.controlPanelProps.cp_content = Object.assign({}, @@ -212,6 +236,14 @@ odoo.define('web.ActionMixin', function (require) { this._title = title; }, + /** + * @private + * @param {string} view_description + */ + _setViewDescription: function (view_description) { + this._viewDescription = view_description; + }, + //--------------------------------------------------------------------- // Handlers //--------------------------------------------------------------------- diff --git a/addons/web/static/src/legacy/js/control_panel/control_panel.js b/addons/web/static/src/legacy/js/control_panel/control_panel.js index 638dbce8f0324..ee4790f283c67 100644 --- a/addons/web/static/src/legacy/js/control_panel/control_panel.js +++ b/addons/web/static/src/legacy/js/control_panel/control_panel.js @@ -212,6 +212,7 @@ odoo.define('web.ControlPanel', function (require) { actionMenus: { validate: s => typeof s === 'object' || s === null, optional: 1 }, title: { type: String, optional: 1 }, view: { type: Object, optional: 1 }, + view_description: { type: String, optional: 1 }, views: Array, withBreadcrumbs: Boolean, withSearchBar: Boolean, diff --git a/addons/web/static/src/legacy/js/views/abstract_view.js b/addons/web/static/src/legacy/js/views/abstract_view.js index fba546b0c08c6..8bad99a874291 100644 --- a/addons/web/static/src/legacy/js/views/abstract_view.js +++ b/addons/web/static/src/legacy/js/views/abstract_view.js @@ -256,6 +256,7 @@ var AbstractView = Factory.extend({ fields, searchMenuTypes: params.searchMenuTypes, view: this.fieldsView, + view_description: params.action.view_description || "", views: params.action.views && params.action.views.filter( v => v.multiRecord === this.multi_record ), diff --git a/addons/web/static/src/legacy/xml/base.xml b/addons/web/static/src/legacy/xml/base.xml index bb30b5fe5b72c..b806ac752ada1 100644 --- a/addons/web/static/src/legacy/xml/base.xml +++ b/addons/web/static/src/legacy/xml/base.xml @@ -24,6 +24,13 @@ +
+ +
+
+ + + +

+ + +

@@ -64,5 +72,4 @@ - diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index 23f0e748ae149..8278fd3853539 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -243,6 +243,7 @@ function makeActionManager(env) { return { jsId: controller.jsId, name: controller.title || controller.action.name || env._t("Undefined"), + view_description: controller.action.view_description || env._t("Undefined"), }; }); } @@ -297,6 +298,12 @@ function makeActionManager(env) { const storedAction = browser.sessionStorage.getItem("current_action"); const lastAction = JSON.parse(storedAction || "{}"); if (lastAction.res_model === state.model) { + if (lastAction.context) { + // If this method is called because of a company switch, the + // stored allowed_company_ids is incorrect. + // (Fix will be improved in master) + delete lastAction.context.allowed_company_ids; + } actionRequest = lastAction; options.viewType = state.view_type; } diff --git a/odoo/addons/base/models/ir_actions.py b/odoo/addons/base/models/ir_actions.py index c6121cfd3d5fb..b69f0f33a19e8 100644 --- a/odoo/addons/base/models/ir_actions.py +++ b/odoo/addons/base/models/ir_actions.py @@ -37,6 +37,8 @@ class IrActions(models.Model): ('report', 'Report')], required=True, default='action') binding_view_types = fields.Char(default='list,form') + # BLUE STINGRAY / METRIC WISE CUSTOM + view_description = fields.Char(string='View Description') def _compute_xml_id(self): res = self.get_external_id() @@ -165,7 +167,7 @@ def _get_readable_fields(self): """ return { "binding_model_id", "binding_type", "binding_view_types", - "display_name", "help", "id", "name", "type", "xml_id", + "display_name", "help", "id", "name", "type", "xml_id", "view_description", } @@ -293,7 +295,7 @@ def _get_readable_fields(self): return super()._get_readable_fields() | { "context", "domain", "filter", "groups_id", "limit", "res_id", "res_model", "search_view", "search_view_id", "target", "view_id", - "view_mode", "views", + "view_description", "view_mode", "views", # `flags` is not a real field of ir.actions.act_window but is used # to give the parameters to generate the action "flags" diff --git a/odoo/addons/base/views/ir_actions_views.xml b/odoo/addons/base/views/ir_actions_views.xml index 4f0b81b6ac87d..0df875ee6c799 100644 --- a/odoo/addons/base/views/ir_actions_views.xml +++ b/odoo/addons/base/views/ir_actions_views.xml @@ -159,6 +159,7 @@ + @@ -420,7 +421,7 @@ env['res.partner'].create({'name': partner_name})