mirror of https://github.com/OCA/web.git
[IMP] web_pivot_computed_measure: black, isort, prettier
parent
5cde5a7bfc
commit
d1a044b374
|
@ -2,20 +2,15 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': "Web Pivot Computed Measure",
|
"name": "Web Pivot Computed Measure",
|
||||||
'category': "web",
|
"category": "web",
|
||||||
'version': "12.0.1.0.2",
|
"version": "12.0.1.0.2",
|
||||||
'author': "Tecnativa, "
|
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||||
"Odoo Community Association (OCA)",
|
"license": "AGPL-3",
|
||||||
'license': 'AGPL-3',
|
"website": "https://github.com/OCA/web",
|
||||||
'website': 'https://github.com/OCA/web',
|
"depends": ["web"],
|
||||||
'depends': ['web'],
|
"data": ["view/assets.xml"],
|
||||||
'data': [
|
"qweb": ["static/src/xml/web_pivot_computed_measure.xml",],
|
||||||
'view/assets.xml'
|
"auto_install": False,
|
||||||
],
|
"installable": True,
|
||||||
'qweb': [
|
|
||||||
'static/src/xml/web_pivot_computed_measure.xml',
|
|
||||||
],
|
|
||||||
'auto_install': False,
|
|
||||||
'installable': True,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
/* Copyright 2020 Tecnativa - Alexandre Díaz
|
/* Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
|
||||||
|
|
||||||
odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require('web.core');
|
var core = require("web.core");
|
||||||
var config = require('web.config');
|
var config = require("web.config");
|
||||||
var PivotController = require('web.PivotController');
|
var PivotController = require("web.PivotController");
|
||||||
|
|
||||||
var QWeb = core.qweb;
|
var QWeb = core.qweb;
|
||||||
|
|
||||||
|
|
||||||
PivotController.include({
|
PivotController.include({
|
||||||
custom_events: _.extend({}, PivotController.prototype.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,
|
||||||
|
@ -25,7 +24,7 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
getContext: function () {
|
getContext: function() {
|
||||||
var res = this._super.apply(this, arguments);
|
var res = this._super.apply(this, arguments);
|
||||||
var state = this.model.get();
|
var state = this.model.get();
|
||||||
res.pivot_computed_measures = state.computed_measures;
|
res.pivot_computed_measures = state.computed_measures;
|
||||||
|
@ -47,27 +46,50 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_onButtonClick: function (event) {
|
_onButtonClick: function(event) {
|
||||||
var $target = $(event.target);
|
var $target = $(event.target);
|
||||||
if ($target.parents("div[data-id='__computed__']").length) {
|
if ($target.parents("div[data-id='__computed__']").length) {
|
||||||
var hideMenu = false;
|
var hideMenu = false;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if ($target.hasClass('dropdown-item') || $target.hasClass('o_submenu_switcher')) {
|
if (
|
||||||
|
$target.hasClass("dropdown-item") ||
|
||||||
|
$target.hasClass("o_submenu_switcher")
|
||||||
|
) {
|
||||||
this.computed_measures_open = !this.computed_measures_open;
|
this.computed_measures_open = !this.computed_measures_open;
|
||||||
this._renderComputedMeasures();
|
this._renderComputedMeasures();
|
||||||
} else if ($target.hasClass('o_add_computed_measure')) {
|
} else if ($target.hasClass("o_add_computed_measure")) {
|
||||||
hideMenu = true;
|
hideMenu = true;
|
||||||
var field1 = this.$buttons_measures_ex.find('#computed_measure_field_1').val();
|
var field1 = this.$buttons_measures_ex
|
||||||
var field2 = this.$buttons_measures_ex.find('#computed_measure_field_2').val();
|
.find("#computed_measure_field_1")
|
||||||
var oper = this.$buttons_measures_ex.find('#computed_measure_operation').val();
|
.val();
|
||||||
|
var field2 = this.$buttons_measures_ex
|
||||||
|
.find("#computed_measure_field_2")
|
||||||
|
.val();
|
||||||
|
var oper = this.$buttons_measures_ex
|
||||||
|
.find("#computed_measure_operation")
|
||||||
|
.val();
|
||||||
if (oper === "custom") {
|
if (oper === "custom") {
|
||||||
oper = this.$buttons_measures_ex.find('#computed_measure_operation_custom').val();
|
oper = this.$buttons_measures_ex
|
||||||
|
.find("#computed_measure_operation_custom")
|
||||||
|
.val();
|
||||||
}
|
}
|
||||||
var name = this.$buttons_measures_ex.find('#computed_measure_name').val();
|
var name = this.$buttons_measures_ex
|
||||||
var format = this.$buttons_measures_ex.find('#computed_measure_format').val();
|
.find("#computed_measure_name")
|
||||||
var uniqueId = (new Date()).getTime();
|
.val();
|
||||||
this.model.createComputedMeasure(uniqueId, field1, field2, oper, name, format)
|
var format = this.$buttons_measures_ex
|
||||||
|
.find("#computed_measure_format")
|
||||||
|
.val();
|
||||||
|
var uniqueId = new Date().getTime();
|
||||||
|
this.model
|
||||||
|
.createComputedMeasure(
|
||||||
|
uniqueId,
|
||||||
|
field1,
|
||||||
|
field2,
|
||||||
|
oper,
|
||||||
|
name,
|
||||||
|
format
|
||||||
|
)
|
||||||
.then(this.update.bind(this, {}, {reload: false}));
|
.then(this.update.bind(this, {}, {reload: false}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,18 +111,36 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
this.$buttons_measures_ex.remove();
|
this.$buttons_measures_ex.remove();
|
||||||
}
|
}
|
||||||
var self = this;
|
var self = this;
|
||||||
var measures = _.sortBy(_.pairs(_.omit(this.measures, '__count')), function (x) { return x[1].string.toLowerCase(); });
|
var measures = _.sortBy(_.pairs(_.omit(this.measures, "__count")), function(
|
||||||
this.$buttons_measures_ex = $(QWeb.render('web_pivot_computed_measure.ExtendedMenu', {
|
x
|
||||||
isOpen: this.computed_measures_open,
|
) {
|
||||||
debug: config.debug,
|
return x[1].string.toLowerCase();
|
||||||
measures: measures,
|
});
|
||||||
computed_measures: _.map(_.reject(measures, function(item) { return !item[1].__computed_id; }), function(item) {
|
this.$buttons_measures_ex = $(
|
||||||
item[1].active = _.contains(self.model.data.measures, item[0]);
|
QWeb.render("web_pivot_computed_measure.ExtendedMenu", {
|
||||||
return item;
|
isOpen: this.computed_measures_open,
|
||||||
}),
|
debug: config.debug,
|
||||||
}));
|
measures: measures,
|
||||||
this.$buttons_measures_ex.find('#computed_measure_operation').on('change', this._onChangeComputedMeasureOperation.bind(this));
|
computed_measures: _.map(
|
||||||
this.$buttons.find('.o_pivot_measures_list').append(this.$buttons_measures_ex);
|
_.reject(measures, function(item) {
|
||||||
|
return !item[1].__computed_id;
|
||||||
|
}),
|
||||||
|
function(item) {
|
||||||
|
item[1].active = _.contains(
|
||||||
|
self.model.data.measures,
|
||||||
|
item[0]
|
||||||
|
);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
this.$buttons_measures_ex
|
||||||
|
.find("#computed_measure_operation")
|
||||||
|
.on("change", this._onChangeComputedMeasureOperation.bind(this));
|
||||||
|
this.$buttons
|
||||||
|
.find(".o_pivot_measures_list")
|
||||||
|
.append(this.$buttons_measures_ex);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,15 +171,20 @@ odoo.define('web_pivot_computed_measure.PivotController', function (require) {
|
||||||
_onChangeComputedMeasureOperation: function(ev) {
|
_onChangeComputedMeasureOperation: function(ev) {
|
||||||
var $option = $(ev.target.options[ev.target.selectedIndex]);
|
var $option = $(ev.target.options[ev.target.selectedIndex]);
|
||||||
if ($(ev.target).val() === "custom") {
|
if ($(ev.target).val() === "custom") {
|
||||||
this.$buttons_measures_ex.find('#container_computed_measure_operation_custom').removeClass('d-none');
|
this.$buttons_measures_ex
|
||||||
|
.find("#container_computed_measure_operation_custom")
|
||||||
|
.removeClass("d-none");
|
||||||
} else {
|
} else {
|
||||||
var format = $option.data('format');
|
var format = $option.data("format");
|
||||||
if (format) {
|
if (format) {
|
||||||
this.$buttons_measures_ex.find('#computed_measure_format').val(format);
|
this.$buttons_measures_ex
|
||||||
|
.find("#computed_measure_format")
|
||||||
|
.val(format);
|
||||||
}
|
}
|
||||||
this.$buttons_measures_ex.find('#container_computed_measure_operation_custom').addClass('d-none');
|
this.$buttons_measures_ex
|
||||||
|
.find("#container_computed_measure_operation_custom")
|
||||||
|
.addClass("d-none");
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,32 +1,35 @@
|
||||||
/* Copyright 2020 Tecnativa - Alexandre Díaz
|
/* Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) */
|
||||||
|
|
||||||
odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
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 ComparisonUtils = require("web.dataComparisonUtils");
|
||||||
|
|
||||||
var _t = core._t;
|
var _t = core._t;
|
||||||
|
|
||||||
|
|
||||||
PivotModel.include({
|
PivotModel.include({
|
||||||
_computed_measures: [],
|
_computed_measures: [],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
* @param {string} operation
|
* @param {String} operation
|
||||||
* @param {string} name
|
* @param {String} name
|
||||||
* @param {string} format
|
* @param {String} format
|
||||||
*/
|
*/
|
||||||
createComputedMeasure: function(id, field1, field2, operation, name, format) {
|
createComputedMeasure: function(id, field1, field2, operation, name, format) {
|
||||||
var measure = _.find(this._computed_measures, function(item) {
|
var measure = _.find(this._computed_measures, function(item) {
|
||||||
return item.field1 === field1 && item.field2 === field2 && item.operation === operation;
|
return (
|
||||||
|
item.field1 === field1 &&
|
||||||
|
item.field2 === field2 &&
|
||||||
|
item.operation === operation
|
||||||
|
);
|
||||||
});
|
});
|
||||||
if (measure) {
|
if (measure) {
|
||||||
return $.Deferred(function(d) {
|
return $.Deferred(function(d) {
|
||||||
|
@ -35,13 +38,17 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
}
|
}
|
||||||
var fieldM1 = this.fields[field1];
|
var fieldM1 = this.fields[field1];
|
||||||
var fieldM2 = this.fields[field2];
|
var fieldM2 = this.fields[field2];
|
||||||
var cmId = '__computed_' + id;
|
var cmId = "__computed_" + id;
|
||||||
var oper = operation.replace(/m1/g, field1).replace(/m2/g, field2);
|
var oper = operation.replace(/m1/g, field1).replace(/m2/g, field2);
|
||||||
var oper_human = operation.replace(
|
var oper_human = operation
|
||||||
/m1/g,
|
.replace(
|
||||||
fieldM1.__computed_id?"("+fieldM1.string+")":fieldM1.string).replace(
|
/m1/g,
|
||||||
/m2/g,
|
fieldM1.__computed_id ? "(" + fieldM1.string + ")" : fieldM1.string
|
||||||
fieldM2.__computed_id?"("+fieldM2.string+")":fieldM2.string);
|
)
|
||||||
|
.replace(
|
||||||
|
/m2/g,
|
||||||
|
fieldM2.__computed_id ? "(" + fieldM2.string + ")" : fieldM2.string
|
||||||
|
);
|
||||||
var cmTotal = this._computed_measures.push({
|
var cmTotal = this._computed_measures.push({
|
||||||
field1: field1,
|
field1: field1,
|
||||||
field2: field2,
|
field2: field2,
|
||||||
|
@ -51,7 +58,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
format: format,
|
format: format,
|
||||||
});
|
});
|
||||||
|
|
||||||
return this._createVirtualMeasure(this._computed_measures[cmTotal-1]);
|
return this._createVirtualMeasure(this._computed_measures[cmTotal - 1]);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,10 +71,10 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
var arrFields = fields || this.fields;
|
var arrFields = fields || this.fields;
|
||||||
// This is a minimal 'fake' field info
|
// This is a minimal 'fake' field info
|
||||||
arrFields[cmDef.id] = {
|
arrFields[cmDef.id] = {
|
||||||
type: cmDef.format, // Used to format the value
|
type: cmDef.format, // Used to format the value
|
||||||
string: cmDef.name, // Used to print the header name
|
string: cmDef.name, // Used to print the header name
|
||||||
__computed_id: cmDef.id, // Used to know if is a computed measure field
|
__computed_id: cmDef.id, // Used to know if is a computed measure field
|
||||||
}
|
};
|
||||||
this.trigger_up("add_measure", {
|
this.trigger_up("add_measure", {
|
||||||
id: cmDef.id,
|
id: cmDef.id,
|
||||||
def: arrFields[cmDef.id],
|
def: arrFields[cmDef.id],
|
||||||
|
@ -93,7 +100,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
}
|
}
|
||||||
return $.Deferred(function(d) {
|
return $.Deferred(function(d) {
|
||||||
d.resolve();
|
d.resolve();
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,22 +116,22 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
* @param {Object} dataPoint
|
* @param {Object} dataPoint
|
||||||
* @param {Object} dataPointComp
|
* @param {Object} dataPointComp
|
||||||
*/
|
*/
|
||||||
_fillComputedMeasuresData: function (dataPoint, dataPointComp) {
|
_fillComputedMeasuresData: function(dataPoint, dataPointComp) {
|
||||||
var self = this;
|
var self = this;
|
||||||
_.each(this._computed_measures, function (cm) {
|
_.each(this._computed_measures, function(cm) {
|
||||||
if (!self._isMeasureEnabled(cm.id)) {
|
if (!self._isMeasureEnabled(cm.id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (dataPointComp) {
|
if (dataPointComp) {
|
||||||
var resData =
|
var resData = py.eval(cm.operation, dataPointComp.data);
|
||||||
py.eval(cm.operation, dataPointComp.data);
|
var resComparison = py.eval(cm.operation, dataPointComp.comparison);
|
||||||
var resComparison =
|
|
||||||
py.eval(cm.operation, dataPointComp.comparison);
|
|
||||||
dataPoint[cm.id] = {
|
dataPoint[cm.id] = {
|
||||||
data: resData,
|
data: resData,
|
||||||
comparisonData: resComparison,
|
comparisonData: resComparison,
|
||||||
variation: ComparisonUtils.computeVariation(
|
variation: ComparisonUtils.computeVariation(
|
||||||
resData, resComparison),
|
resData,
|
||||||
|
resComparison
|
||||||
|
),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
dataPoint[cm.id] = py.eval(cm.operation, dataPoint);
|
dataPoint[cm.id] = py.eval(cm.operation, dataPoint);
|
||||||
|
@ -137,7 +144,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
*
|
*
|
||||||
* @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 len = 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 < len; ++index) {
|
for (var index = 0; index < len; ++index) {
|
||||||
|
@ -148,24 +155,23 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
if (_.isEmpty(dataPoint)) {
|
if (_.isEmpty(dataPoint)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ('__comparisonDomain' in dataPoint) {
|
if ("__comparisonDomain" in dataPoint) {
|
||||||
// Transform comparison dataPoint object to be compatible
|
// Transform comparison dataPoint object to be compatible
|
||||||
var pairsDataPoint = _.pairs(dataPoint);
|
var pairsDataPoint = _.pairs(dataPoint);
|
||||||
var dataPointComp = {
|
var dataPointComp = {
|
||||||
data: _.object(_.map(
|
data: _.object(
|
||||||
pairsDataPoint, (item) => {
|
_.map(pairsDataPoint, item => {
|
||||||
return [
|
return [item[0], item[1] && item[1].data];
|
||||||
item[0],
|
})
|
||||||
item[1] && item[1].data,
|
),
|
||||||
];
|
comparison: _.object(
|
||||||
})),
|
_.map(pairsDataPoint, item => {
|
||||||
comparison: _.object(_.map(
|
|
||||||
pairsDataPoint, (item) => {
|
|
||||||
return [
|
return [
|
||||||
item[0],
|
item[0],
|
||||||
item[1] && item[1].comparisonData,
|
item[1] && item[1].comparisonData,
|
||||||
];
|
];
|
||||||
})),
|
})
|
||||||
|
),
|
||||||
};
|
};
|
||||||
// Update datas. Required by computed measures that uses
|
// Update datas. Required by computed measures that uses
|
||||||
// other computed measures to work
|
// other computed measures to work
|
||||||
|
@ -188,9 +194,12 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
load: function (params) {
|
load: function(params) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this._computed_measures = params.context.pivot_computed_measures || params.computed_measures || [];
|
this._computed_measures =
|
||||||
|
params.context.pivot_computed_measures ||
|
||||||
|
params.computed_measures ||
|
||||||
|
[];
|
||||||
var toActive = [];
|
var toActive = [];
|
||||||
var l = this._computed_measures.length;
|
var l = this._computed_measures.length;
|
||||||
for (var x = 0; x < l; ++x) {
|
for (var x = 0; x < l; ++x) {
|
||||||
|
@ -199,7 +208,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
type: cmDef.format,
|
type: cmDef.format,
|
||||||
string: cmDef.name,
|
string: cmDef.name,
|
||||||
__computed_id: cmDef.id,
|
__computed_id: cmDef.id,
|
||||||
}
|
};
|
||||||
toActive.push(cmDef.field1, cmDef.field2, cmDef.id);
|
toActive.push(cmDef.field1, cmDef.field2, cmDef.id);
|
||||||
}
|
}
|
||||||
return this._super(params).then(function() {
|
return this._super(params).then(function() {
|
||||||
|
@ -221,9 +230,12 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
reload: function (handle, params) {
|
reload: function(handle, params) {
|
||||||
if ('context' in params) {
|
if ("context" in params) {
|
||||||
this._computed_measures = params.context.pivot_computed_measures || params.computed_measures || [];
|
this._computed_measures =
|
||||||
|
params.context.pivot_computed_measures ||
|
||||||
|
params.computed_measures ||
|
||||||
|
[];
|
||||||
}
|
}
|
||||||
var l = this._computed_measures.length;
|
var l = this._computed_measures.length;
|
||||||
for (var x = 0; x < l; ++x) {
|
for (var x = 0; x < l; ++x) {
|
||||||
|
@ -234,10 +246,13 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
for (var x = 0; x < fieldNames.length; ++x) {
|
for (var x = 0; x < fieldNames.length; ++x) {
|
||||||
var field = this.fields[fieldNames[x]];
|
var field = this.fields[fieldNames[x]];
|
||||||
if (field.__computed_id) {
|
if (field.__computed_id) {
|
||||||
var cm = _.find(this._computed_measures, {id:field.__computed_id});
|
var cm = _.find(this._computed_measures, {id: field.__computed_id});
|
||||||
if (!cm) {
|
if (!cm) {
|
||||||
delete this.fields[fieldNames[x]];
|
delete this.fields[fieldNames[x]];
|
||||||
this.data.measures = _.without(this.data.measures, fieldNames[x]);
|
this.data.measures = _.without(
|
||||||
|
this.data.measures,
|
||||||
|
fieldNames[x]
|
||||||
|
);
|
||||||
this.trigger_up("remove_measure", {
|
this.trigger_up("remove_measure", {
|
||||||
id: fieldNames[x],
|
id: fieldNames[x],
|
||||||
});
|
});
|
||||||
|
@ -252,7 +267,7 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
get: function () {
|
get: function() {
|
||||||
var res = this._super.apply(this, arguments);
|
var res = this._super.apply(this, arguments);
|
||||||
res.computed_measures = this._computed_measures;
|
res.computed_measures = this._computed_measures;
|
||||||
return res;
|
return res;
|
||||||
|
@ -264,15 +279,19 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
toggleMeasure: function (field) {
|
toggleMeasure: function(field) {
|
||||||
if (this._isMeasureEnabled(field)) {
|
if (this._isMeasureEnabled(field)) {
|
||||||
// Measure is disabled
|
// Measure is disabled
|
||||||
var umeasures = _.filter(this._computed_measures, function(item) {
|
var umeasures = _.filter(this._computed_measures, function(item) {
|
||||||
return item.field1 === field || item.field2 === field;
|
return item.field1 === field || item.field2 === field;
|
||||||
})
|
});
|
||||||
if (umeasures.length && this._isMeasureEnabled(umeasures[0].id)) {
|
if (umeasures.length && this._isMeasureEnabled(umeasures[0].id)) {
|
||||||
return $.Deferred(function(d) {
|
return $.Deferred(function(d) {
|
||||||
d.reject(_t("This measure is currently used by a 'computed measure'. Please, disable the computed measure first."));
|
d.reject(
|
||||||
|
_t(
|
||||||
|
"This measure is currently used by a 'computed measure'. Please, disable the computed measure first."
|
||||||
|
)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -283,7 +302,9 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
var afield = toAnalize.shift();
|
var afield = toAnalize.shift();
|
||||||
var fieldDef = this.fields[afield];
|
var fieldDef = this.fields[afield];
|
||||||
if (fieldDef.__computed_id) {
|
if (fieldDef.__computed_id) {
|
||||||
var cm = _.find(this._computed_measures, {id:fieldDef.__computed_id});
|
var cm = _.find(this._computed_measures, {
|
||||||
|
id: fieldDef.__computed_id,
|
||||||
|
});
|
||||||
toAnalize.push(cm.field1, cm.field2);
|
toAnalize.push(cm.field1, cm.field2);
|
||||||
var toEnableFields = [];
|
var toEnableFields = [];
|
||||||
if (!this.fields[cm.field1].__computed_id) {
|
if (!this.fields[cm.field1].__computed_id) {
|
||||||
|
@ -303,5 +324,4 @@ odoo.define('web_pivot_computed_measure.PivotModel', function (require) {
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!--
|
<!--
|
||||||
Copyright 2020 Tecnativa - Alexandre Díaz
|
Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
-->
|
-->
|
||||||
<templates>
|
<templates>
|
||||||
|
|
||||||
<t t-name="web_pivot_computed_measure.ComputedMeasureOperations">
|
<t t-name="web_pivot_computed_measure.ComputedMeasureOperations">
|
||||||
<option name="sum" value="m1+m2">
|
<option name="sum" value="m1+m2">
|
||||||
Sum (m1 + m2)
|
Sum (m1 + m2)
|
||||||
|
@ -25,7 +24,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
Custom
|
Custom
|
||||||
</option>
|
</option>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="web_pivot_computed_measure.ComputedMeasureFormats">
|
<t t-name="web_pivot_computed_measure.ComputedMeasureFormats">
|
||||||
<option name="int" value="integer">
|
<option name="int" value="integer">
|
||||||
Integer
|
Integer
|
||||||
|
@ -37,24 +35,36 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
Percentage
|
Percentage
|
||||||
</option>
|
</option>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="web_pivot_computed_measure.ExtendedMenu">
|
<t t-name="web_pivot_computed_measure.ExtendedMenu">
|
||||||
<div role="separator" class="dropdown-divider"/>
|
<div role="separator" class="dropdown-divider" />
|
||||||
<t t-foreach="computed_measures" t-as="cm">
|
<t t-foreach="computed_measures" t-as="cm">
|
||||||
<a role="menuitem" href="#" t-attf-class="dropdown-item {{cm[1].active and 'selected' or ''}}" t-data-computed="1" t-att-data-field="cm[0]"><t t-esc="cm[1].string"/></a>
|
<a
|
||||||
|
role="menuitem"
|
||||||
|
href="#"
|
||||||
|
t-attf-class="dropdown-item {{cm[1].active and 'selected' or ''}}"
|
||||||
|
t-data-computed="1"
|
||||||
|
t-att-data-field="cm[0]"
|
||||||
|
>
|
||||||
|
<t t-esc="cm[1].string" />
|
||||||
|
</a>
|
||||||
</t>
|
</t>
|
||||||
<div class="o_menu_item" data-id="__computed__">
|
<div class="o_menu_item" data-id="__computed__">
|
||||||
<a href="#" role="menuitem" class="dropdown-item">
|
<a href="#" role="menuitem" class="dropdown-item">
|
||||||
Computed Measure
|
Computed Measure
|
||||||
|
|
||||||
<span class="o_submenu_switcher" data-id="__computed__">
|
<span class="o_submenu_switcher" data-id="__computed__">
|
||||||
<span t-att-class="isOpen ? 'fa fa-caret-down' : 'fa fa-caret-right'"></span>
|
<span
|
||||||
|
t-att-class="isOpen ? 'fa fa-caret-down' : 'fa fa-caret-right'"
|
||||||
|
/>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
<t t-if="isOpen">
|
<t t-if="isOpen">
|
||||||
<div class="dropdown-item-text">
|
<div class="dropdown-item-text">
|
||||||
<label for="computed_measure_field_1">Measure 1</label>
|
<label for="computed_measure_field_1">Measure 1</label>
|
||||||
<select class="o_input o_date_field_selector" id="computed_measure_field_1">
|
<select
|
||||||
|
class="o_input o_date_field_selector"
|
||||||
|
id="computed_measure_field_1"
|
||||||
|
>
|
||||||
<t t-foreach="measures" t-as="measure">
|
<t t-foreach="measures" t-as="measure">
|
||||||
<option t-att-value="measure[0]">
|
<option t-att-value="measure[0]">
|
||||||
<t t-esc="measure[1].string" />
|
<t t-esc="measure[1].string" />
|
||||||
|
@ -64,7 +74,10 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-item-text">
|
<div class="dropdown-item-text">
|
||||||
<label for="computed_measure_field_2">Measure 2</label>
|
<label for="computed_measure_field_2">Measure 2</label>
|
||||||
<select class="o_input o_time_range_selector" id="computed_measure_field_2">
|
<select
|
||||||
|
class="o_input o_time_range_selector"
|
||||||
|
id="computed_measure_field_2"
|
||||||
|
>
|
||||||
<t t-foreach="measures" t-as="measure">
|
<t t-foreach="measures" t-as="measure">
|
||||||
<option t-att-value="measure[0]">
|
<option t-att-value="measure[0]">
|
||||||
<t t-esc="measure[1].string" />
|
<t t-esc="measure[1].string" />
|
||||||
|
@ -74,29 +87,47 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-item-text">
|
<div class="dropdown-item-text">
|
||||||
<label for="computed_measure_operation">Operation</label>
|
<label for="computed_measure_operation">Operation</label>
|
||||||
<select class="o_input o_time_range_selector" id="computed_measure_operation">
|
<select
|
||||||
<t t-call="web_pivot_computed_measure.ComputedMeasureOperations" />
|
class="o_input o_time_range_selector"
|
||||||
|
id="computed_measure_operation"
|
||||||
|
>
|
||||||
|
<t
|
||||||
|
t-call="web_pivot_computed_measure.ComputedMeasureOperations"
|
||||||
|
/>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div t-if="debug" class="dropdown-item-text d-none" id="container_computed_measure_operation_custom">
|
<div
|
||||||
|
t-if="debug"
|
||||||
|
class="dropdown-item-text d-none"
|
||||||
|
id="container_computed_measure_operation_custom"
|
||||||
|
>
|
||||||
<label for="computed_measure_operation_custom">Formula</label>
|
<label for="computed_measure_operation_custom">Formula</label>
|
||||||
<input type="text" id="computed_measure_operation_custom" />
|
<input type="text" id="computed_measure_operation_custom" />
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-item-text">
|
<div class="dropdown-item-text">
|
||||||
<label for="computed_measure_name">Name</label>
|
<label for="computed_measure_name">Name</label>
|
||||||
<input placeholder="Can be empty" type="text" id="computed_measure_name" />
|
<input
|
||||||
|
placeholder="Can be empty"
|
||||||
|
type="text"
|
||||||
|
id="computed_measure_name"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-item-text">
|
<div class="dropdown-item-text">
|
||||||
<label for="computed_measure_format">Format</label>
|
<label for="computed_measure_format">Format</label>
|
||||||
<select class="o_input o_time_range_selector" id="computed_measure_format">
|
<select
|
||||||
|
class="o_input o_time_range_selector"
|
||||||
|
id="computed_measure_format"
|
||||||
|
>
|
||||||
<t t-call="web_pivot_computed_measure.ComputedMeasureFormats" />
|
<t t-call="web_pivot_computed_measure.ComputedMeasureFormats" />
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-item-text">
|
<div class="dropdown-item-text">
|
||||||
<button class="btn btn-primary o_add_computed_measure" type="button">Add</button>
|
<button
|
||||||
|
class="btn btn-primary o_add_computed_measure"
|
||||||
|
type="button"
|
||||||
|
>Add</button>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
</templates>
|
</templates>
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<template id="assets_backend" inherit_id="web.assets_backend">
|
<template id="assets_backend" inherit_id="web.assets_backend">
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/web_pivot_computed_measure/static/src/js/pivot_model.js"></script>
|
<script
|
||||||
<script type="text/javascript" src="/web_pivot_computed_measure/static/src/js/pivot_controller.js"></script>
|
type="text/javascript"
|
||||||
|
src="/web_pivot_computed_measure/static/src/js/pivot_model.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_pivot_computed_measure/static/src/js/pivot_controller.js"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue