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