mirror of https://github.com/OCA/web.git
[IMP] web_pivot_computed_measure: black, isort, prettier
parent
76f9fe8d91
commit
513fba15ad
|
@ -1,7 +1,7 @@
|
||||||
/* 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";
|
||||||
|
|
||||||
const core = require("web.core");
|
const core = require("web.core");
|
||||||
|
@ -24,7 +24,7 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
getOwnedQueryParams: function() {
|
getOwnedQueryParams: function () {
|
||||||
const res = this._super.apply(this, arguments);
|
const res = this._super.apply(this, arguments);
|
||||||
const state = this.model.get({raw: true});
|
const state = this.model.get({raw: true});
|
||||||
res.context.pivot_computed_measures = state.computed_measures;
|
res.context.pivot_computed_measures = state.computed_measures;
|
||||||
|
@ -34,7 +34,7 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
renderButtons: function($node) {
|
renderButtons: function ($node) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
if ($node) {
|
if ($node) {
|
||||||
this._renderComputedMeasures();
|
this._renderComputedMeasures();
|
||||||
|
@ -46,7 +46,7 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_onButtonClick: function(event) {
|
_onButtonClick: function (event) {
|
||||||
const $target = $(event.target);
|
const $target = $(event.target);
|
||||||
if ($target.parents("div[data-id='__computed__']").length) {
|
if ($target.parents("div[data-id='__computed__']").length) {
|
||||||
let hideMenu = false;
|
let hideMenu = false;
|
||||||
|
@ -108,23 +108,26 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_renderComputedMeasures: function() {
|
_renderComputedMeasures: function () {
|
||||||
if (this.$buttons_measures_ex && this.$buttons_measures_ex.length) {
|
if (this.$buttons_measures_ex && this.$buttons_measures_ex.length) {
|
||||||
this.$buttons_measures_ex.remove();
|
this.$buttons_measures_ex.remove();
|
||||||
}
|
}
|
||||||
const measures = _.sortBy(_.pairs(_.omit(this.measures, "__count")), x => {
|
const measures = _.sortBy(
|
||||||
|
_.pairs(_.omit(this.measures, "__count")),
|
||||||
|
(x) => {
|
||||||
return x[1].string.toLowerCase();
|
return x[1].string.toLowerCase();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
this.$buttons_measures_ex = $(
|
this.$buttons_measures_ex = $(
|
||||||
QWeb.render("web_pivot_computed_measure.ExtendedMenu", {
|
QWeb.render("web_pivot_computed_measure.ExtendedMenu", {
|
||||||
isOpen: this.computed_measures_open,
|
isOpen: this.computed_measures_open,
|
||||||
debug: config.isDebug(),
|
debug: config.isDebug(),
|
||||||
measures: measures,
|
measures: measures,
|
||||||
computed_measures: _.map(
|
computed_measures: _.map(
|
||||||
_.reject(measures, item => {
|
_.reject(measures, (item) => {
|
||||||
return !item[1].__computed_id;
|
return !item[1].__computed_id;
|
||||||
}),
|
}),
|
||||||
item => {
|
(item) => {
|
||||||
item[1].active = _.contains(
|
item[1].active = _.contains(
|
||||||
this.model.data.measures,
|
this.model.data.measures,
|
||||||
item[0]
|
item[0]
|
||||||
|
@ -149,7 +152,7 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||||
* @private
|
* @private
|
||||||
* @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;
|
||||||
this._renderComputedMeasures();
|
this._renderComputedMeasures();
|
||||||
},
|
},
|
||||||
|
@ -160,7 +163,7 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||||
* @private
|
* @private
|
||||||
* @param {CustomEvent} ev
|
* @param {CustomEvent} ev
|
||||||
*/
|
*/
|
||||||
_onRemoveMeasure: function(ev) {
|
_onRemoveMeasure: function (ev) {
|
||||||
delete this.measures[ev.data.id];
|
delete this.measures[ev.data.id];
|
||||||
this._renderComputedMeasures();
|
this._renderComputedMeasures();
|
||||||
},
|
},
|
||||||
|
@ -171,7 +174,7 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||||
* @private
|
* @private
|
||||||
* @param {ChangeEvent} ev
|
* @param {ChangeEvent} ev
|
||||||
*/
|
*/
|
||||||
_onChangeComputedMeasureOperation: function(ev) {
|
_onChangeComputedMeasureOperation: function (ev) {
|
||||||
const $option = $(ev.target.options[ev.target.selectedIndex]);
|
const $option = $(ev.target.options[ev.target.selectedIndex]);
|
||||||
if ($(ev.target).val() === "custom") {
|
if ($(ev.target).val() === "custom") {
|
||||||
this.$buttons_measures_ex
|
this.$buttons_measures_ex
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* 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";
|
||||||
|
|
||||||
const core = require("web.core");
|
const core = require("web.core");
|
||||||
|
@ -23,8 +23,8 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
* @param {String} format
|
* @param {String} format
|
||||||
* @returns a promise
|
* @returns a promise
|
||||||
*/
|
*/
|
||||||
createComputedMeasure: function(id, field1, field2, operation, name, format) {
|
createComputedMeasure: function (id, field1, field2, operation, name, format) {
|
||||||
const measure = _.find(this._computed_measures, item => {
|
const measure = _.find(this._computed_measures, (item) => {
|
||||||
return (
|
return (
|
||||||
item.field1 === field1 &&
|
item.field1 === field1 &&
|
||||||
item.field2 === field2 &&
|
item.field2 === field2 &&
|
||||||
|
@ -67,7 +67,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
* @param {List} fields *Optional*
|
* @param {List} fields *Optional*
|
||||||
* @returns a promise
|
* @returns a promise
|
||||||
*/
|
*/
|
||||||
_createVirtualMeasure: function(cmDef, fields) {
|
_createVirtualMeasure: function (cmDef, fields) {
|
||||||
const arrFields = fields || this.fields;
|
const arrFields = fields || this.fields;
|
||||||
// This is a minimal 'fake' field info
|
// This is a minimal 'fake' field info
|
||||||
arrFields[cmDef.id] = {
|
arrFields[cmDef.id] = {
|
||||||
|
@ -89,7 +89,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
* @private
|
* @private
|
||||||
* @param {List of Strings} fields
|
* @param {List of Strings} fields
|
||||||
*/
|
*/
|
||||||
_activeMeasures: function(fields) {
|
_activeMeasures: function (fields) {
|
||||||
let needLoad = false;
|
let needLoad = false;
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
if (!this._isMeasureEnabled(field)) {
|
if (!this._isMeasureEnabled(field)) {
|
||||||
|
@ -107,7 +107,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
* @private
|
* @private
|
||||||
* @param {String} field
|
* @param {String} field
|
||||||
*/
|
*/
|
||||||
_isMeasureEnabled: function(field) {
|
_isMeasureEnabled: function (field) {
|
||||||
return _.contains(this.data.measures, field);
|
return _.contains(this.data.measures, field);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} subGroupData
|
* @param {Object} subGroupData
|
||||||
*/
|
*/
|
||||||
_fillComputedMeasuresData: function(subGroupData) {
|
_fillComputedMeasuresData: function (subGroupData) {
|
||||||
for (const cm of this._computed_measures) {
|
for (const cm of this._computed_measures) {
|
||||||
if (!this._isMeasureEnabled(cm.id)) return;
|
if (!this._isMeasureEnabled(cm.id)) return;
|
||||||
if (subGroupData.__count === 0) {
|
if (subGroupData.__count === 0) {
|
||||||
|
@ -134,7 +134,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_prepareData: function(group, groupSubdivisions) {
|
_prepareData: function (group, groupSubdivisions) {
|
||||||
for (const groupSubdivision of groupSubdivisions) {
|
for (const groupSubdivision of groupSubdivisions) {
|
||||||
for (const subGroup of groupSubdivision.subGroups) {
|
for (const subGroup of groupSubdivision.subGroups) {
|
||||||
this._fillComputedMeasuresData(subGroup);
|
this._fillComputedMeasuresData(subGroup);
|
||||||
|
@ -152,7 +152,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_getGroupSubdivision: function() {
|
_getGroupSubdivision: function () {
|
||||||
const computed_measures = [];
|
const computed_measures = [];
|
||||||
for (let i = 0; i < this.data.measures.length; i++)
|
for (let i = 0; i < this.data.measures.length; i++)
|
||||||
if (this.data.measures[i].startsWith("__computed_")) {
|
if (this.data.measures[i].startsWith("__computed_")) {
|
||||||
|
@ -170,7 +170,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
load: function(params) {
|
load: function (params) {
|
||||||
this._computed_measures =
|
this._computed_measures =
|
||||||
params.context.pivot_computed_measures ||
|
params.context.pivot_computed_measures ||
|
||||||
params.computed_measures ||
|
params.computed_measures ||
|
||||||
|
@ -202,7 +202,7 @@ 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 =
|
this._computed_measures =
|
||||||
params.context.pivot_computed_measures ||
|
params.context.pivot_computed_measures ||
|
||||||
|
@ -236,7 +236,7 @@ odoo.define("web_pivot_computed_measure.PivotModel", function(require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
get: function() {
|
get: function () {
|
||||||
const res = this._super.apply(this, arguments);
|
const res = this._super.apply(this, arguments);
|
||||||
res.computed_measures = this._computed_measures;
|
res.computed_measures = this._computed_measures;
|
||||||
return res;
|
return res;
|
||||||
|
@ -248,10 +248,10 @@ 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
|
||||||
const umeasures = _.filter(this._computed_measures, item => {
|
const umeasures = _.filter(this._computed_measures, (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)) {
|
||||||
|
|
Loading…
Reference in New Issue