From a2f20904b8cfa91bb93f0d5fe85c28d8b3c5a962 Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Mon, 16 Jan 2023 12:25:49 +0100 Subject: [PATCH] [IMP] web_time_range_menu_custom: black, isort, prettier --- .../odoo/addons/web_time_range_menu_custom | 1 + setup/web_time_range_menu_custom/setup.py | 6 ++ .../static/src/js/control_panel_controller.js | 4 +- .../static/src/js/control_panel_model.js | 72 ++++++++++--------- .../src/js/control_panel_view_parameters.js | 40 +++++++---- .../static/src/js/domain.js | 30 ++++---- .../static/src/js/search_facet.js | 4 +- .../static/src/js/time_range_menu.js | 26 +++---- 8 files changed, 104 insertions(+), 79 deletions(-) create mode 120000 setup/web_time_range_menu_custom/odoo/addons/web_time_range_menu_custom create mode 100644 setup/web_time_range_menu_custom/setup.py diff --git a/setup/web_time_range_menu_custom/odoo/addons/web_time_range_menu_custom b/setup/web_time_range_menu_custom/odoo/addons/web_time_range_menu_custom new file mode 120000 index 000000000..ac6f76901 --- /dev/null +++ b/setup/web_time_range_menu_custom/odoo/addons/web_time_range_menu_custom @@ -0,0 +1 @@ +../../../../web_time_range_menu_custom \ No newline at end of file diff --git a/setup/web_time_range_menu_custom/setup.py b/setup/web_time_range_menu_custom/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_time_range_menu_custom/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_time_range_menu_custom/static/src/js/control_panel_controller.js b/web_time_range_menu_custom/static/src/js/control_panel_controller.js index d309e8877..0ee8c98a7 100644 --- a/web_time_range_menu_custom/static/src/js/control_panel_controller.js +++ b/web_time_range_menu_custom/static/src/js/control_panel_controller.js @@ -1,4 +1,4 @@ -odoo.define("web_time_range_menu_custom.ControlPanelController", function(require) { +odoo.define("web_time_range_menu_custom.ControlPanelController", function (require) { "use strict"; const ControlPanelController = require("web.ControlPanelController"); @@ -11,7 +11,7 @@ odoo.define("web_time_range_menu_custom.ControlPanelController", function(requir /** * @override */ - _onActivateCustomTimeRange: function(ev) { + _onActivateCustomTimeRange: function (ev) { ev.stopPropagation(); this.model.activateTimeRangeCustom( ev.data.id, diff --git a/web_time_range_menu_custom/static/src/js/control_panel_model.js b/web_time_range_menu_custom/static/src/js/control_panel_model.js index 7f11398e2..0bb555ace 100644 --- a/web_time_range_menu_custom/static/src/js/control_panel_model.js +++ b/web_time_range_menu_custom/static/src/js/control_panel_model.js @@ -1,6 +1,6 @@ /* Copyright 2021 Tecnativa - Alexandre D. Díaz * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ -odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) { +odoo.define("web_time_range_menu_custom.ControlPanelModel", function (require) { "use strict"; const core = require("web.core"); @@ -10,7 +10,7 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) { const _t = core._t; ControlPanelModel.include({ - activateTimeRangeCustom: function( + activateTimeRangeCustom: function ( filterId, timeRangeId, comparisonTimeRangeId, @@ -26,20 +26,21 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) { /** * @override */ - _getTimeRangeMenuData: function(evaluation) { + _getTimeRangeMenuData: function (evaluation) { const context = this._super.apply(this, arguments); // GroupOfTimeRanges can be undefined in case with withSearchBar is false var groupOfTimeRanges = this.groups[this._getGroupIdOfType("timeRange")]; if (groupOfTimeRanges && groupOfTimeRanges.activeFilterIds.length) { var filter = this.filters[groupOfTimeRanges.activeFilterIds[0][0]]; if (filter.timeRangeId === "custom_period") { - context.timeRangeMenuData.timeRange = Domain.prototype.constructCustomDomain( - filter.fieldName, - filter.timeRangeId, - filter.fieldType, - undefined, - filter.timeRangeCustom - ); + context.timeRangeMenuData.timeRange = + Domain.prototype.constructCustomDomain( + filter.fieldName, + filter.timeRangeId, + filter.fieldType, + undefined, + filter.timeRangeCustom + ); context.timeRangeMenuData.timeRangeDescription = _t("Last ") + `${filter.timeRangeCustom.value} ${filter.timeRangeCustom.type}`; @@ -48,12 +49,32 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) { context.timeRangeMenuData.timeRangeCustomType = filter.timeRangeCustom.type; if (evaluation) { - context.timeRangeMenuData.timeRange = Domain.prototype.stringToArray( - context.timeRangeMenuData.timeRange - ); + context.timeRangeMenuData.timeRange = + Domain.prototype.stringToArray( + context.timeRangeMenuData.timeRange + ); } if (filter.comparisonTimeRangeId !== "custom_comparison_period") { - context.timeRangeMenuData.comparisonTimeRange = Domain.prototype.constructCustomDomain( + context.timeRangeMenuData.comparisonTimeRange = + Domain.prototype.constructCustomDomain( + filter.fieldName, + filter.timeRangeId, + filter.fieldType, + filter.comparisonTimeRangeId, + filter.timeRangeCustom, + filter.comparisonTimeRangeCustom + ); + if (evaluation) { + context.timeRangeMenuData.comparisonTimeRange = + Domain.prototype.stringToArray( + context.timeRangeMenuData.comparisonTimeRange + ); + } + } + } + if (filter.comparisonTimeRangeId === "custom_comparison_period") { + context.timeRangeMenuData.comparisonTimeRange = + Domain.prototype.constructCustomDomain( filter.fieldName, filter.timeRangeId, filter.fieldType, @@ -61,22 +82,6 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) { filter.timeRangeCustom, filter.comparisonTimeRangeCustom ); - if (evaluation) { - context.timeRangeMenuData.comparisonTimeRange = Domain.prototype.stringToArray( - context.timeRangeMenuData.comparisonTimeRange - ); - } - } - } - if (filter.comparisonTimeRangeId === "custom_comparison_period") { - context.timeRangeMenuData.comparisonTimeRange = Domain.prototype.constructCustomDomain( - filter.fieldName, - filter.timeRangeId, - filter.fieldType, - filter.comparisonTimeRangeId, - filter.timeRangeCustom, - filter.comparisonTimeRangeCustom - ); context.timeRangeMenuData.comparisonTimeRangeDescription = _t("Previous ") + `${filter.comparisonTimeRangeCustom.value} ${filter.comparisonTimeRangeCustom.type}`; @@ -86,9 +91,10 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) { filter.comparisonTimeRangeCustom.type; if (evaluation) { - context.timeRangeMenuData.comparisonTimeRange = Domain.prototype.stringToArray( - context.timeRangeMenuData.comparisonTimeRange - ); + context.timeRangeMenuData.comparisonTimeRange = + Domain.prototype.stringToArray( + context.timeRangeMenuData.comparisonTimeRange + ); } } } diff --git a/web_time_range_menu_custom/static/src/js/control_panel_view_parameters.js b/web_time_range_menu_custom/static/src/js/control_panel_view_parameters.js index 9e9acdcc8..f077c18c5 100644 --- a/web_time_range_menu_custom/static/src/js/control_panel_view_parameters.js +++ b/web_time_range_menu_custom/static/src/js/control_panel_view_parameters.js @@ -1,20 +1,32 @@ /* Copyright 2021 Tecnativa - Alexandre D. Díaz * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ -odoo.define("web_time_range_menu_custom.controlPanelViewParameters", function(require) { - "use strict"; +odoo.define( + "web_time_range_menu_custom.controlPanelViewParameters", + function (require) { + "use strict"; - const controlPanelViewParameters = require("web.controlPanelViewParameters"); - const core = require("web.core"); + const controlPanelViewParameters = require("web.controlPanelViewParameters"); + const core = require("web.core"); - const _lt = core._lt; + const _lt = core._lt; - controlPanelViewParameters.PERIOD_OPTIONS = controlPanelViewParameters.PERIOD_OPTIONS.concat( - [{description: _lt("Custom Period"), optionId: "custom_period", groupId: 4}] - ); - controlPanelViewParameters.TIME_RANGE_OPTIONS = - controlPanelViewParameters.PERIOD_OPTIONS; + controlPanelViewParameters.PERIOD_OPTIONS = + controlPanelViewParameters.PERIOD_OPTIONS.concat([ + { + description: _lt("Custom Period"), + optionId: "custom_period", + groupId: 4, + }, + ]); + controlPanelViewParameters.TIME_RANGE_OPTIONS = + controlPanelViewParameters.PERIOD_OPTIONS; - controlPanelViewParameters.COMPARISON_TIME_RANGE_OPTIONS = controlPanelViewParameters.COMPARISON_TIME_RANGE_OPTIONS.concat( - [{description: _lt("Custom Period"), optionId: "custom_comparison_period"}] - ); -}); + controlPanelViewParameters.COMPARISON_TIME_RANGE_OPTIONS = + controlPanelViewParameters.COMPARISON_TIME_RANGE_OPTIONS.concat([ + { + description: _lt("Custom Period"), + optionId: "custom_comparison_period", + }, + ]); + } +); diff --git a/web_time_range_menu_custom/static/src/js/domain.js b/web_time_range_menu_custom/static/src/js/domain.js index f879f1fb1..0972069cd 100644 --- a/web_time_range_menu_custom/static/src/js/domain.js +++ b/web_time_range_menu_custom/static/src/js/domain.js @@ -1,6 +1,6 @@ /* Copyright 2021 Tecnativa - Alexandre D. Díaz * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ -odoo.define("web_time_range_menu_custom.Domain", function(require) { +odoo.define("web_time_range_menu_custom.Domain", function (require) { "use strict"; const Domain = require("web.Domain"); @@ -9,7 +9,7 @@ odoo.define("web_time_range_menu_custom.Domain", function(require) { /** * @override */ - constructCustomDomain: function( + constructCustomDomain: function ( fieldName, period, type, @@ -26,7 +26,7 @@ odoo.define("web_time_range_menu_custom.Domain", function(require) { function makeInterval() { switch (comparisonPeriod) { case "previous_period": - _.each(offsetPeriodParams, function(value, key) { + _.each(offsetPeriodParams, function (value, key) { if ( !leftBoundaryParams[key] || _.isNumber(leftBoundaryParams[key]) @@ -59,22 +59,20 @@ odoo.define("web_time_range_menu_custom.Domain", function(require) { break; case "custom_comparison_period": // This case is the addition for custom periods - leftBoundaryParams[ - comparisonPeriodCustom.type - ] = leftBoundaryParams[comparisonPeriodCustom.type] - ? leftBoundaryParams[comparisonPeriodCustom.type] - - comparisonPeriodCustom.value - : -comparisonPeriodCustom.value; - rightBoundaryParams[ - comparisonPeriodCustom.type - ] = rightBoundaryParams[comparisonPeriodCustom.type] - ? rightBoundaryParams[comparisonPeriodCustom.type] - - comparisonPeriodCustom.value - : -comparisonPeriodCustom.value; + leftBoundaryParams[comparisonPeriodCustom.type] = + leftBoundaryParams[comparisonPeriodCustom.type] + ? leftBoundaryParams[comparisonPeriodCustom.type] - + comparisonPeriodCustom.value + : -comparisonPeriodCustom.value; + rightBoundaryParams[comparisonPeriodCustom.type] = + rightBoundaryParams[comparisonPeriodCustom.type] + ? rightBoundaryParams[comparisonPeriodCustom.type] - + comparisonPeriodCustom.value + : -comparisonPeriodCustom.value; break; } - var stringifyParams = function(value, key) { + var stringifyParams = function (value, key) { return key + "=" + value; }; var leftBoundaryStringifyParams = _.map( diff --git a/web_time_range_menu_custom/static/src/js/search_facet.js b/web_time_range_menu_custom/static/src/js/search_facet.js index 95d9174c6..8f8c1d9dd 100644 --- a/web_time_range_menu_custom/static/src/js/search_facet.js +++ b/web_time_range_menu_custom/static/src/js/search_facet.js @@ -1,6 +1,6 @@ /* Copyright 2021 Tecnativa - Alexandre D. Díaz * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ -odoo.define("web_time_range_menu_custom.SearchFacet", function(require) { +odoo.define("web_time_range_menu_custom.SearchFacet", function (require) { "use strict"; const core = require("web.core"); @@ -12,7 +12,7 @@ odoo.define("web_time_range_menu_custom.SearchFacet", function(require) { /** * @override */ - _getFilterDescription: function(filter) { + _getFilterDescription: function (filter) { if ( filter.type === "timeRange" && (filter.timeRangeId === "custom_period" || diff --git a/web_time_range_menu_custom/static/src/js/time_range_menu.js b/web_time_range_menu_custom/static/src/js/time_range_menu.js index 9cae35db7..90cb83519 100644 --- a/web_time_range_menu_custom/static/src/js/time_range_menu.js +++ b/web_time_range_menu_custom/static/src/js/time_range_menu.js @@ -1,6 +1,6 @@ /* Copyright 2021 Tecnativa - Alexandre D. Díaz * License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ -odoo.define("web_time_range_menu_custom.TimeRangeMenu", function(require) { +odoo.define("web_time_range_menu_custom.TimeRangeMenu", function (require) { "use strict"; const TimeRangeMenu = require("web.TimeRangeMenu"); @@ -12,7 +12,7 @@ odoo.define("web_time_range_menu_custom.TimeRangeMenu", function(require) { "_onChangeComparisonTimeRangeSelector", }), - renderElement: function() { + renderElement: function () { this._super.apply(this, arguments); this.$time_range_selector = this.$el.find("#time_range_selector"); this.$comparison_time_range_selector = this.$el.find( @@ -28,12 +28,14 @@ odoo.define("web_time_range_menu_custom.TimeRangeMenu", function(require) { this.$selector_comparison_custom = this.$el.find( "#comparison_time_range_selector_custom" ); - this.$selector_comparison_custom_field_value = this.$selector_comparison_custom.find( - "#date_field_selector_comparison_custom_value" - ); - this.$selector_comparison_custom_field_type = this.$selector_comparison_custom.find( - "#date_field_selector_comparison_custom_type" - ); + this.$selector_comparison_custom_field_value = + this.$selector_comparison_custom.find( + "#date_field_selector_comparison_custom_value" + ); + this.$selector_comparison_custom_field_type = + this.$selector_comparison_custom.find( + "#date_field_selector_comparison_custom_type" + ); this.$selector_custom.toggleClass( "d-none", @@ -59,21 +61,21 @@ odoo.define("web_time_range_menu_custom.TimeRangeMenu", function(require) { } }, - _onChangeTimeRangeSelector: function(ev) { + _onChangeTimeRangeSelector: function (ev) { this.$selector_custom.toggleClass( "d-none", ev.target.value !== "custom_period" ); }, - _onChangeComparisonTimeRangeSelector: function(ev) { + _onChangeComparisonTimeRangeSelector: function (ev) { this.$selector_comparison_custom.toggleClass( "d-none", ev.target.value !== "custom_comparison_period" ); }, - _onCheckBoxClick: function() { + _onCheckBoxClick: function () { this._super.apply(this, arguments); const comparisonTimeRangeId = this.$( ".o_comparison_time_range_selector" @@ -85,7 +87,7 @@ odoo.define("web_time_range_menu_custom.TimeRangeMenu", function(require) { ); }, - _onApplyButtonClick: function() { + _onApplyButtonClick: function () { const id = this.$(".o_date_field_selector").val(); const timeRangeId = this.$(".o_time_range_selector").val(); let comparisonTimeRangeId = false;