mirror of https://github.com/OCA/web.git
[IMP+FIX] web_pivot_computed_measure: Time Ranges Comparison + Change custom_events addition
[IMP] web_pivot_computed_measure: Time Ranges Comparison [FIX] web_pivot_computed_measure: Change custom_events addition Previous this commit, the controller events are discarted. With this commit the existing events are respectedpull/2755/head
parent
1cee9f4685
commit
1dbdf5d267
|
@ -4,7 +4,7 @@
|
||||||
{
|
{
|
||||||
'name': "Web Pivot Computed Measure",
|
'name': "Web Pivot Computed Measure",
|
||||||
'category': "web",
|
'category': "web",
|
||||||
'version': "12.0.1.0.0",
|
'version': "12.0.1.0.1",
|
||||||
'author': "Tecnativa, "
|
'author': "Tecnativa, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
|
|
@ -141,7 +141,7 @@ msgstr ""
|
||||||
|
|
||||||
#. module: web_pivot_computed_measure
|
#. module: web_pivot_computed_measure
|
||||||
#. openerp-web
|
#. openerp-web
|
||||||
#: code:addons/web_pivot_computed_measure/static/src/js/pivot_model.js:224
|
#: code:addons/web_pivot_computed_measure/static/src/js/pivot_model.js:275
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "This measure is currently used by a 'computed measure'. Please, disable the computed measure first."
|
msgid "This measure is currently used by a 'computed measure'. Please, disable the computed measure first."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
@ -12,10 +12,10 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
|
|
||||||
|
|
||||||
PivotController.include({
|
PivotController.include({
|
||||||
custom_events: {
|
custom_events: _.extend({}, PivotController.prototype.custom_events, {
|
||||||
'add_measure': '_onAddMeasure',
|
add_measure: '_onAddMeasure',
|
||||||
'remove_measure': '_onRemoveMeasure',
|
remove_measure: '_onRemoveMeasure',
|
||||||
},
|
}),
|
||||||
|
|
||||||
computed_measures_open: false,
|
computed_measures_open: false,
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle click event on measures menu to support computed measures sub-menu
|
* Handle click event on measures menu to support computed measures sub-menu
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_onButtonClick: function (event) {
|
_onButtonClick: function (event) {
|
||||||
|
@ -105,8 +105,8 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom event to add a new measure
|
* Custom event to add a new measure
|
||||||
*
|
*
|
||||||
* @param {CustomEvent} ev
|
* @param {CustomEvent} ev
|
||||||
*/
|
*/
|
||||||
_onAddMeasure: function(ev) {
|
_onAddMeasure: function(ev) {
|
||||||
this.measures[ev.data.id] = ev.data.def;
|
this.measures[ev.data.id] = ev.data.def;
|
||||||
|
@ -115,8 +115,8 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom event to remove a measure
|
* Custom event to remove a measure
|
||||||
*
|
*
|
||||||
* @param {CustomEvent} ev
|
* @param {CustomEvent} ev
|
||||||
*/
|
*/
|
||||||
_onRemoveMeasure: function(ev) {
|
_onRemoveMeasure: function(ev) {
|
||||||
delete this.measures[ev.data.id];
|
delete this.measures[ev.data.id];
|
||||||
|
@ -125,7 +125,7 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set default values related with the selected operation
|
* Set default values related with the selected operation
|
||||||
*
|
*
|
||||||
* @param {ChangeEvent} ev
|
* @param {ChangeEvent} ev
|
||||||
*/
|
*/
|
||||||
_onChangeComputedMeasureOperation: function(ev) {
|
_onChangeComputedMeasureOperation: function(ev) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
|
|
||||||
var core = require('web.core');
|
var core = require('web.core');
|
||||||
var PivotModel = require('web.PivotModel');
|
var PivotModel = require('web.PivotModel');
|
||||||
|
var ComparisonUtils = require('web.dataComparisonUtils');
|
||||||
|
|
||||||
var _t = core._t;
|
var _t = core._t;
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new computed measure
|
* Create a new computed measure
|
||||||
*
|
*
|
||||||
* @param {string} id
|
* @param {string} id
|
||||||
* @param {string} field1
|
* @param {string} field1
|
||||||
* @param {string} field2
|
* @param {string} field2
|
||||||
|
@ -55,7 +56,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and enable a measure based on a 'fake' field
|
* Create and enable a measure based on a 'fake' field
|
||||||
*
|
*
|
||||||
* @param {Object} cmDef
|
* @param {Object} cmDef
|
||||||
* @param {List} fields *Optional*
|
* @param {List} fields *Optional*
|
||||||
*/
|
*/
|
||||||
|
@ -102,29 +103,79 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
return _.contains(this.data.measures, field);
|
return _.contains(this.data.measures, field);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to add computed measure fields data into 'dataPoint'
|
||||||
|
*
|
||||||
|
* @param {Object} dataPoint
|
||||||
|
* @param {Object} dataPointComp
|
||||||
|
*/
|
||||||
|
_fillComputedMeasuresData: function (dataPoint, dataPointComp) {
|
||||||
|
var self = this;
|
||||||
|
_.each(this._computed_measures, function (cm) {
|
||||||
|
if (!self._isMeasureEnabled(cm.id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (dataPointComp) {
|
||||||
|
var resData =
|
||||||
|
py.eval(cm.operation, dataPointComp.data);
|
||||||
|
var resComparison =
|
||||||
|
py.eval(cm.operation, dataPointComp.comparison);
|
||||||
|
dataPoint[cm.id] = {
|
||||||
|
data: resData,
|
||||||
|
comparisonData: resComparison,
|
||||||
|
variation: ComparisonUtils.computeVariation(
|
||||||
|
resData, resComparison),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
dataPoint[cm.id] = py.eval(cm.operation, dataPoint);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill the dataPoints with the computed measures values
|
* Fill the dataPoints with the computed measures values
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_mergeData: function (data, comparisonData, groupBys) {
|
_mergeData: function (data, comparisonData, groupBys) {
|
||||||
var res = this._super.apply(this, arguments);
|
var res = this._super.apply(this, arguments);
|
||||||
var l = groupBys.length; // Cached loop (This is not python! hehe)
|
var len = groupBys.length; // Cached loop (This is not python! hehe)
|
||||||
for (var index = 0; index < l; ++index) {
|
for (var index = 0; index < len; ++index) {
|
||||||
if (data.length) {
|
if (res.length) {
|
||||||
var l2 = data[index].length;
|
var len2 = res[index].length;
|
||||||
for (var k = 0; k < l2; ++k) {
|
for (var k = 0; k < len2; ++k) {
|
||||||
var dataPoint = data[index][k];
|
var dataPoint = res[index][k];
|
||||||
if (_.isEmpty(dataPoint)) {
|
if (_.isEmpty(dataPoint)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var l3 = this._computed_measures.length;
|
if ('__comparisonDomain' in dataPoint) {
|
||||||
for (var x = 0; x < l3; ++x) {
|
// Transform comparison dataPoint object to be compatible
|
||||||
var cm = this._computed_measures[x];
|
var pairsDataPoint = _.pairs(dataPoint);
|
||||||
if (!this._isMeasureEnabled(cm.id)) {
|
var dataPointComp = {
|
||||||
continue;
|
data: _.object(_.map(
|
||||||
}
|
pairsDataPoint, (item) => {
|
||||||
dataPoint[cm.id] = py.eval(cm.operation, dataPoint);
|
return [
|
||||||
|
item[0],
|
||||||
|
item[1] && item[1].data,
|
||||||
|
];
|
||||||
|
})),
|
||||||
|
comparison: _.object(_.map(
|
||||||
|
pairsDataPoint, (item) => {
|
||||||
|
return [
|
||||||
|
item[0],
|
||||||
|
item[1] && item[1].comparisonData,
|
||||||
|
];
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
// Update datas. Required by computed measures that uses
|
||||||
|
// other computed measures to work
|
||||||
|
this._fillComputedMeasuresData(dataPointComp.data);
|
||||||
|
this._fillComputedMeasuresData(dataPointComp.comparison);
|
||||||
|
// Update comparison dataPoint
|
||||||
|
this._fillComputedMeasuresData(dataPoint, dataPointComp);
|
||||||
|
} else {
|
||||||
|
// Update standard dataPoint
|
||||||
|
this._fillComputedMeasuresData(dataPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +185,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the computed measures in context. This is used by filters.
|
* Load the computed measures in context. This is used by filters.
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
load: function (params) {
|
load: function (params) {
|
||||||
|
@ -167,7 +218,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the computed measures in context. This is used by filters.
|
* Load the computed measures in context. This is used by filters.
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
reload: function (handle, params) {
|
reload: function (handle, params) {
|
||||||
|
@ -198,7 +249,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the computed measures to the state. This is used by filters.
|
* Add the computed measures to the state. This is used by filters.
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
get: function () {
|
get: function () {
|
||||||
|
@ -210,7 +261,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
/**
|
/**
|
||||||
* Adds a rule to deny that measures can be disabled if are being used by a computed measure.
|
* Adds a rule to deny that measures can be disabled if are being used by a computed measure.
|
||||||
* In the other hand, when enables a measure analyzes it to active all involved measures.
|
* In the other hand, when enables a measure analyzes it to active all involved measures.
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
toggleMeasure: function (field) {
|
toggleMeasure: function (field) {
|
||||||
|
|
Loading…
Reference in New Issue