mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG] web_pivot_computed_measure: Migration to 13.0
This commit is contained in:
committed by
CarlosRoca13
parent
bea8716db7
commit
b66c149b71
@@ -4,11 +4,11 @@
|
||||
odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
"use strict";
|
||||
|
||||
var core = require("web.core");
|
||||
var config = require("web.config");
|
||||
var PivotController = require("web.PivotController");
|
||||
const core = require("web.core");
|
||||
const config = require("web.config");
|
||||
const PivotController = require("web.PivotController");
|
||||
|
||||
var QWeb = core.qweb;
|
||||
const QWeb = core.qweb;
|
||||
|
||||
PivotController.include({
|
||||
custom_events: _.extend({}, PivotController.prototype.custom_events, {
|
||||
@@ -24,10 +24,10 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
getContext: function() {
|
||||
var res = this._super.apply(this, arguments);
|
||||
var state = this.model.get();
|
||||
res.pivot_computed_measures = state.computed_measures;
|
||||
getOwnedQueryParams: function() {
|
||||
const res = this._super.apply(this, arguments);
|
||||
const state = this.model.get({raw: true});
|
||||
res.context.pivot_computed_measures = state.computed_measures;
|
||||
return res;
|
||||
},
|
||||
|
||||
@@ -47,9 +47,9 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
* @override
|
||||
*/
|
||||
_onButtonClick: function(event) {
|
||||
var $target = $(event.target);
|
||||
const $target = $(event.target);
|
||||
if ($target.parents("div[data-id='__computed__']").length) {
|
||||
var hideMenu = false;
|
||||
let hideMenu = false;
|
||||
event.preventDefault();
|
||||
|
||||
if (
|
||||
@@ -60,13 +60,13 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
this._renderComputedMeasures();
|
||||
} else if ($target.hasClass("o_add_computed_measure")) {
|
||||
hideMenu = true;
|
||||
var field1 = this.$buttons_measures_ex
|
||||
const field1 = this.$buttons_measures_ex
|
||||
.find("#computed_measure_field_1")
|
||||
.val();
|
||||
var field2 = this.$buttons_measures_ex
|
||||
const field2 = this.$buttons_measures_ex
|
||||
.find("#computed_measure_field_2")
|
||||
.val();
|
||||
var oper = this.$buttons_measures_ex
|
||||
let oper = this.$buttons_measures_ex
|
||||
.find("#computed_measure_operation")
|
||||
.val();
|
||||
if (oper === "custom") {
|
||||
@@ -74,13 +74,13 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
.find("#computed_measure_operation_custom")
|
||||
.val();
|
||||
}
|
||||
var name = this.$buttons_measures_ex
|
||||
const name = this.$buttons_measures_ex
|
||||
.find("#computed_measure_name")
|
||||
.val();
|
||||
var format = this.$buttons_measures_ex
|
||||
const format = this.$buttons_measures_ex
|
||||
.find("#computed_measure_format")
|
||||
.val();
|
||||
var uniqueId = new Date().getTime();
|
||||
const uniqueId = new Date().getTime();
|
||||
this.model
|
||||
.createComputedMeasure(
|
||||
uniqueId,
|
||||
@@ -105,29 +105,28 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
|
||||
/**
|
||||
* Render computed measures menu
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_renderComputedMeasures: function() {
|
||||
if (this.$buttons_measures_ex && this.$buttons_measures_ex.length) {
|
||||
this.$buttons_measures_ex.remove();
|
||||
}
|
||||
var self = this;
|
||||
var measures = _.sortBy(_.pairs(_.omit(this.measures, "__count")), function(
|
||||
x
|
||||
) {
|
||||
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.debug,
|
||||
debug: config.isDebug(),
|
||||
measures: measures,
|
||||
computed_measures: _.map(
|
||||
_.reject(measures, function(item) {
|
||||
_.reject(measures, item => {
|
||||
return !item[1].__computed_id;
|
||||
}),
|
||||
function(item) {
|
||||
item => {
|
||||
item[1].active = _.contains(
|
||||
self.model.data.measures,
|
||||
this.model.data.measures,
|
||||
item[0]
|
||||
);
|
||||
return item;
|
||||
@@ -138,14 +137,16 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
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);
|
||||
if (this.$buttons)
|
||||
this.$buttons
|
||||
.find(".o_pivot_measures_list")
|
||||
.append(this.$buttons_measures_ex);
|
||||
},
|
||||
|
||||
/**
|
||||
* Custom event to add a new measure
|
||||
*
|
||||
* @private
|
||||
* @param {CustomEvent} ev
|
||||
*/
|
||||
_onAddMeasure: function(ev) {
|
||||
@@ -156,6 +157,7 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
/**
|
||||
* Custom event to remove a measure
|
||||
*
|
||||
* @private
|
||||
* @param {CustomEvent} ev
|
||||
*/
|
||||
_onRemoveMeasure: function(ev) {
|
||||
@@ -166,16 +168,17 @@ odoo.define("web_pivot_computed_measure.PivotController", function(require) {
|
||||
/**
|
||||
* Set default values related with the selected operation
|
||||
*
|
||||
* @private
|
||||
* @param {ChangeEvent} ev
|
||||
*/
|
||||
_onChangeComputedMeasureOperation: function(ev) {
|
||||
var $option = $(ev.target.options[ev.target.selectedIndex]);
|
||||
const $option = $(ev.target.options[ev.target.selectedIndex]);
|
||||
if ($(ev.target).val() === "custom") {
|
||||
this.$buttons_measures_ex
|
||||
.find("#container_computed_measure_operation_custom")
|
||||
.removeClass("d-none");
|
||||
} else {
|
||||
var format = $option.data("format");
|
||||
const format = $option.data("format");
|
||||
if (format) {
|
||||
this.$buttons_measures_ex
|
||||
.find("#computed_measure_format")
|
||||
|
||||
Reference in New Issue
Block a user