-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] spreadsheet_*_oca: Add possibility to make columns dynamic
With these changes, we have added the ability to make the columns dynamic, just as is done with the rows. To add this type of table, we will need to select the dynamic columns option and choose the number of columns to insert. Keep in mind that if multiple column levels are selected, the chosen number will apply to each of these levels. In addition to this, the wizard that opens with the spreadsheet button has been updated to allow us to choose the type of dynamism we expect in the inserted table.
- Loading branch information
1 parent
7046778
commit a864da7
Showing
16 changed files
with
357 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** @odoo-module */ | ||
/* Copyright 2024 Tecnativa - Carlos Roca | ||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */ | ||
import {SpreadsheetPivotTable} from "@spreadsheet/pivot/pivot_table"; | ||
import {patch} from "@web/core/utils/patch"; | ||
|
||
patch(SpreadsheetPivotTable.prototype, "spreadsheet_oca.SpreadsheetPivotTable", { | ||
get _dynamic_cols() { | ||
return this._cols[this._cols.length - 1] === "dynamic_cols"; | ||
}, | ||
getNumberOfMeasures() { | ||
if (this._dynamic_cols) { | ||
// We have disabled the computation of the last column to prevent showing | ||
// the totalization of the columns when they are of a dynamic type. If | ||
// shown, it would display the total of all records corresponding to the | ||
// row, rather than what is being displayed on the screen. | ||
return 1; | ||
} | ||
return this._super(...arguments); | ||
}, | ||
getColHeaders() { | ||
if (this._dynamic_cols) { | ||
// We return a copy of this._cols without the last entry of the array, | ||
// which indicates that these are dynamic columns. | ||
var cols = [...this._cols]; | ||
cols.pop(); | ||
return cols; | ||
} | ||
return this._super(...arguments); | ||
}, | ||
getMeasureHeaders() { | ||
if (this._dynamic_cols) { | ||
return this._cols[this._cols.length - 2]; | ||
} | ||
return this._super(...arguments); | ||
}, | ||
getColWidth() { | ||
if (this._dynamic_cols) { | ||
return this._cols[this._cols.length - 2].length; | ||
} | ||
return this._super(...arguments); | ||
}, | ||
getColHeight() { | ||
if (this._dynamic_cols) { | ||
return this._cols.length - 1; | ||
} | ||
return this._super(...arguments); | ||
}, | ||
getColMeasureIndex(values) { | ||
if (this._dynamic_cols) { | ||
var cols = [...this._cols]; | ||
cols.pop(); | ||
const vals = JSON.stringify(values); | ||
const maxLength = Math.max(...cols.map((col) => col.length)); | ||
for (let i = 0; i < maxLength; i++) { | ||
const cellValues = cols.map((col) => | ||
JSON.stringify((col[i] || {}).values) | ||
); | ||
if (cellValues.includes(vals)) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
return this._super(...arguments); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.