mirror of https://github.com/OCA/web.git
[IMP] web_time_range_menu_custom: black, isort, prettier
parent
840ab92bb4
commit
a2f20904b8
|
@ -0,0 +1 @@
|
||||||
|
../../../../web_time_range_menu_custom
|
|
@ -0,0 +1,6 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
|
@ -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";
|
"use strict";
|
||||||
|
|
||||||
const ControlPanelController = require("web.ControlPanelController");
|
const ControlPanelController = require("web.ControlPanelController");
|
||||||
|
@ -11,7 +11,7 @@ odoo.define("web_time_range_menu_custom.ControlPanelController", function(requir
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_onActivateCustomTimeRange: function(ev) {
|
_onActivateCustomTimeRange: function (ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this.model.activateTimeRangeCustom(
|
this.model.activateTimeRangeCustom(
|
||||||
ev.data.id,
|
ev.data.id,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* Copyright 2021 Tecnativa - Alexandre D. Díaz
|
/* Copyright 2021 Tecnativa - Alexandre D. Díaz
|
||||||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
|
* 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";
|
"use strict";
|
||||||
|
|
||||||
const core = require("web.core");
|
const core = require("web.core");
|
||||||
|
@ -10,7 +10,7 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) {
|
||||||
const _t = core._t;
|
const _t = core._t;
|
||||||
|
|
||||||
ControlPanelModel.include({
|
ControlPanelModel.include({
|
||||||
activateTimeRangeCustom: function(
|
activateTimeRangeCustom: function (
|
||||||
filterId,
|
filterId,
|
||||||
timeRangeId,
|
timeRangeId,
|
||||||
comparisonTimeRangeId,
|
comparisonTimeRangeId,
|
||||||
|
@ -26,20 +26,21 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_getTimeRangeMenuData: function(evaluation) {
|
_getTimeRangeMenuData: function (evaluation) {
|
||||||
const context = this._super.apply(this, arguments);
|
const context = this._super.apply(this, arguments);
|
||||||
// GroupOfTimeRanges can be undefined in case with withSearchBar is false
|
// GroupOfTimeRanges can be undefined in case with withSearchBar is false
|
||||||
var groupOfTimeRanges = this.groups[this._getGroupIdOfType("timeRange")];
|
var groupOfTimeRanges = this.groups[this._getGroupIdOfType("timeRange")];
|
||||||
if (groupOfTimeRanges && groupOfTimeRanges.activeFilterIds.length) {
|
if (groupOfTimeRanges && groupOfTimeRanges.activeFilterIds.length) {
|
||||||
var filter = this.filters[groupOfTimeRanges.activeFilterIds[0][0]];
|
var filter = this.filters[groupOfTimeRanges.activeFilterIds[0][0]];
|
||||||
if (filter.timeRangeId === "custom_period") {
|
if (filter.timeRangeId === "custom_period") {
|
||||||
context.timeRangeMenuData.timeRange = Domain.prototype.constructCustomDomain(
|
context.timeRangeMenuData.timeRange =
|
||||||
filter.fieldName,
|
Domain.prototype.constructCustomDomain(
|
||||||
filter.timeRangeId,
|
filter.fieldName,
|
||||||
filter.fieldType,
|
filter.timeRangeId,
|
||||||
undefined,
|
filter.fieldType,
|
||||||
filter.timeRangeCustom
|
undefined,
|
||||||
);
|
filter.timeRangeCustom
|
||||||
|
);
|
||||||
context.timeRangeMenuData.timeRangeDescription =
|
context.timeRangeMenuData.timeRangeDescription =
|
||||||
_t("Last ") +
|
_t("Last ") +
|
||||||
`${filter.timeRangeCustom.value} ${filter.timeRangeCustom.type}`;
|
`${filter.timeRangeCustom.value} ${filter.timeRangeCustom.type}`;
|
||||||
|
@ -48,12 +49,32 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) {
|
||||||
context.timeRangeMenuData.timeRangeCustomType =
|
context.timeRangeMenuData.timeRangeCustomType =
|
||||||
filter.timeRangeCustom.type;
|
filter.timeRangeCustom.type;
|
||||||
if (evaluation) {
|
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") {
|
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.fieldName,
|
||||||
filter.timeRangeId,
|
filter.timeRangeId,
|
||||||
filter.fieldType,
|
filter.fieldType,
|
||||||
|
@ -61,22 +82,6 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) {
|
||||||
filter.timeRangeCustom,
|
filter.timeRangeCustom,
|
||||||
filter.comparisonTimeRangeCustom
|
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 =
|
context.timeRangeMenuData.comparisonTimeRangeDescription =
|
||||||
_t("Previous ") +
|
_t("Previous ") +
|
||||||
`${filter.comparisonTimeRangeCustom.value} ${filter.comparisonTimeRangeCustom.type}`;
|
`${filter.comparisonTimeRangeCustom.value} ${filter.comparisonTimeRangeCustom.type}`;
|
||||||
|
@ -86,9 +91,10 @@ odoo.define("web_time_range_menu_custom.ControlPanelModel", function(require) {
|
||||||
filter.comparisonTimeRangeCustom.type;
|
filter.comparisonTimeRangeCustom.type;
|
||||||
|
|
||||||
if (evaluation) {
|
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
|
/* Copyright 2021 Tecnativa - Alexandre D. Díaz
|
||||||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
|
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
|
||||||
odoo.define("web_time_range_menu_custom.controlPanelViewParameters", function(require) {
|
odoo.define(
|
||||||
"use strict";
|
"web_time_range_menu_custom.controlPanelViewParameters",
|
||||||
|
function (require) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
const controlPanelViewParameters = require("web.controlPanelViewParameters");
|
const controlPanelViewParameters = require("web.controlPanelViewParameters");
|
||||||
const core = require("web.core");
|
const core = require("web.core");
|
||||||
|
|
||||||
const _lt = core._lt;
|
const _lt = core._lt;
|
||||||
|
|
||||||
controlPanelViewParameters.PERIOD_OPTIONS = controlPanelViewParameters.PERIOD_OPTIONS.concat(
|
controlPanelViewParameters.PERIOD_OPTIONS =
|
||||||
[{description: _lt("Custom Period"), optionId: "custom_period", groupId: 4}]
|
controlPanelViewParameters.PERIOD_OPTIONS.concat([
|
||||||
);
|
{
|
||||||
controlPanelViewParameters.TIME_RANGE_OPTIONS =
|
description: _lt("Custom Period"),
|
||||||
controlPanelViewParameters.PERIOD_OPTIONS;
|
optionId: "custom_period",
|
||||||
|
groupId: 4,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
controlPanelViewParameters.TIME_RANGE_OPTIONS =
|
||||||
|
controlPanelViewParameters.PERIOD_OPTIONS;
|
||||||
|
|
||||||
controlPanelViewParameters.COMPARISON_TIME_RANGE_OPTIONS = controlPanelViewParameters.COMPARISON_TIME_RANGE_OPTIONS.concat(
|
controlPanelViewParameters.COMPARISON_TIME_RANGE_OPTIONS =
|
||||||
[{description: _lt("Custom Period"), optionId: "custom_comparison_period"}]
|
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
|
/* Copyright 2021 Tecnativa - Alexandre D. Díaz
|
||||||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
|
* 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";
|
"use strict";
|
||||||
|
|
||||||
const Domain = require("web.Domain");
|
const Domain = require("web.Domain");
|
||||||
|
@ -9,7 +9,7 @@ odoo.define("web_time_range_menu_custom.Domain", function(require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
constructCustomDomain: function(
|
constructCustomDomain: function (
|
||||||
fieldName,
|
fieldName,
|
||||||
period,
|
period,
|
||||||
type,
|
type,
|
||||||
|
@ -26,7 +26,7 @@ odoo.define("web_time_range_menu_custom.Domain", function(require) {
|
||||||
function makeInterval() {
|
function makeInterval() {
|
||||||
switch (comparisonPeriod) {
|
switch (comparisonPeriod) {
|
||||||
case "previous_period":
|
case "previous_period":
|
||||||
_.each(offsetPeriodParams, function(value, key) {
|
_.each(offsetPeriodParams, function (value, key) {
|
||||||
if (
|
if (
|
||||||
!leftBoundaryParams[key] ||
|
!leftBoundaryParams[key] ||
|
||||||
_.isNumber(leftBoundaryParams[key])
|
_.isNumber(leftBoundaryParams[key])
|
||||||
|
@ -59,22 +59,20 @@ odoo.define("web_time_range_menu_custom.Domain", function(require) {
|
||||||
break;
|
break;
|
||||||
case "custom_comparison_period":
|
case "custom_comparison_period":
|
||||||
// This case is the addition for custom periods
|
// This case is the addition for custom periods
|
||||||
leftBoundaryParams[
|
leftBoundaryParams[comparisonPeriodCustom.type] =
|
||||||
comparisonPeriodCustom.type
|
leftBoundaryParams[comparisonPeriodCustom.type]
|
||||||
] = leftBoundaryParams[comparisonPeriodCustom.type]
|
? leftBoundaryParams[comparisonPeriodCustom.type] -
|
||||||
? leftBoundaryParams[comparisonPeriodCustom.type] -
|
comparisonPeriodCustom.value
|
||||||
comparisonPeriodCustom.value
|
: -comparisonPeriodCustom.value;
|
||||||
: -comparisonPeriodCustom.value;
|
rightBoundaryParams[comparisonPeriodCustom.type] =
|
||||||
rightBoundaryParams[
|
rightBoundaryParams[comparisonPeriodCustom.type]
|
||||||
comparisonPeriodCustom.type
|
? rightBoundaryParams[comparisonPeriodCustom.type] -
|
||||||
] = rightBoundaryParams[comparisonPeriodCustom.type]
|
comparisonPeriodCustom.value
|
||||||
? rightBoundaryParams[comparisonPeriodCustom.type] -
|
: -comparisonPeriodCustom.value;
|
||||||
comparisonPeriodCustom.value
|
|
||||||
: -comparisonPeriodCustom.value;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var stringifyParams = function(value, key) {
|
var stringifyParams = function (value, key) {
|
||||||
return key + "=" + value;
|
return key + "=" + value;
|
||||||
};
|
};
|
||||||
var leftBoundaryStringifyParams = _.map(
|
var leftBoundaryStringifyParams = _.map(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* Copyright 2021 Tecnativa - Alexandre D. Díaz
|
/* Copyright 2021 Tecnativa - Alexandre D. Díaz
|
||||||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
|
* 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";
|
"use strict";
|
||||||
|
|
||||||
const core = require("web.core");
|
const core = require("web.core");
|
||||||
|
@ -12,7 +12,7 @@ odoo.define("web_time_range_menu_custom.SearchFacet", function(require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_getFilterDescription: function(filter) {
|
_getFilterDescription: function (filter) {
|
||||||
if (
|
if (
|
||||||
filter.type === "timeRange" &&
|
filter.type === "timeRange" &&
|
||||||
(filter.timeRangeId === "custom_period" ||
|
(filter.timeRangeId === "custom_period" ||
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* Copyright 2021 Tecnativa - Alexandre D. Díaz
|
/* Copyright 2021 Tecnativa - Alexandre D. Díaz
|
||||||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
|
* 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";
|
"use strict";
|
||||||
|
|
||||||
const TimeRangeMenu = require("web.TimeRangeMenu");
|
const TimeRangeMenu = require("web.TimeRangeMenu");
|
||||||
|
@ -12,7 +12,7 @@ odoo.define("web_time_range_menu_custom.TimeRangeMenu", function(require) {
|
||||||
"_onChangeComparisonTimeRangeSelector",
|
"_onChangeComparisonTimeRangeSelector",
|
||||||
}),
|
}),
|
||||||
|
|
||||||
renderElement: function() {
|
renderElement: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.$time_range_selector = this.$el.find("#time_range_selector");
|
this.$time_range_selector = this.$el.find("#time_range_selector");
|
||||||
this.$comparison_time_range_selector = this.$el.find(
|
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(
|
this.$selector_comparison_custom = this.$el.find(
|
||||||
"#comparison_time_range_selector_custom"
|
"#comparison_time_range_selector_custom"
|
||||||
);
|
);
|
||||||
this.$selector_comparison_custom_field_value = this.$selector_comparison_custom.find(
|
this.$selector_comparison_custom_field_value =
|
||||||
"#date_field_selector_comparison_custom_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_type =
|
||||||
);
|
this.$selector_comparison_custom.find(
|
||||||
|
"#date_field_selector_comparison_custom_type"
|
||||||
|
);
|
||||||
|
|
||||||
this.$selector_custom.toggleClass(
|
this.$selector_custom.toggleClass(
|
||||||
"d-none",
|
"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(
|
this.$selector_custom.toggleClass(
|
||||||
"d-none",
|
"d-none",
|
||||||
ev.target.value !== "custom_period"
|
ev.target.value !== "custom_period"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
_onChangeComparisonTimeRangeSelector: function(ev) {
|
_onChangeComparisonTimeRangeSelector: function (ev) {
|
||||||
this.$selector_comparison_custom.toggleClass(
|
this.$selector_comparison_custom.toggleClass(
|
||||||
"d-none",
|
"d-none",
|
||||||
ev.target.value !== "custom_comparison_period"
|
ev.target.value !== "custom_comparison_period"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
_onCheckBoxClick: function() {
|
_onCheckBoxClick: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
const comparisonTimeRangeId = this.$(
|
const comparisonTimeRangeId = this.$(
|
||||||
".o_comparison_time_range_selector"
|
".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 id = this.$(".o_date_field_selector").val();
|
||||||
const timeRangeId = this.$(".o_time_range_selector").val();
|
const timeRangeId = this.$(".o_time_range_selector").val();
|
||||||
let comparisonTimeRangeId = false;
|
let comparisonTimeRangeId = false;
|
||||||
|
|
Loading…
Reference in New Issue