forked from Techsystech/web
[IMP] web_time_range_menu_custom: black, isort, prettier
parent
ca6428db56
commit
af81b51413
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
]);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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" ||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue