-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] pivot: introduce spreadsheet pivot table
This commit introduces the spreadsheet pivot table. It is a new type of pivot table that is based on values from the spreadsheet itself. The pivot table is created by selecting a range of cells in the spreadsheet. The first row of the range is used as the available fields, and the rest of the range is used as the data. The type of the data is automatically detected based on the content of the cells in the column. It could be `date` if all the cells in the column are dates, `boolean` if all the cells are boolean, `number` if all the cells are numbers, or `char` otherwise. Each field can be used as a dimension (row or column) or as a measure (value), based on its type. The user can drag and drop the fields to the corresponding area in the pivot table side panel, select the order, select the granularity if the field is a date. Each measure can be aggregated using different functions (sum, average, count, etc.). For now, the pivot table is updated in real-time when the user changes the range of cells in the spreadsheet. This could be heavy for large spreadsheets, but a flag will be implemented to delay the update in a future task (3897841). This commit is a first version of the pivot table. Features are missing compared to the pivot table implemented in Odoo, for example the possibility to use `PIVOT.HEADER` and `PIVOT.VALUE` functions (and all the features that come with it, autocompletion of formulas, positional arguments, etc.). This will be implemented in a future task (3897857). Task: 3748717 Part-of: #4025 Co-authored-by: rrahir <rar@odoo.com> Co-authored-by: Pierre Rousseau <pro@odoo.com>
- Loading branch information
Showing
79 changed files
with
4,433 additions
and
282 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,138 @@ | ||
const salesperson = [ | ||
"Perceval", | ||
"Arthur", | ||
"Dame Séli", | ||
"Léodagan", | ||
"Karadoc", | ||
"Lancelot du Lac", | ||
"Guenièvre", | ||
"Bohort", | ||
"Père Blaise", | ||
"Yvain", | ||
"Merlin", | ||
"Gauvin", | ||
"Mevanwi", | ||
"Roi Loth", | ||
"Uther Pendragon", | ||
"Goustan le Cruel", | ||
"Ygeme de Tintagel", | ||
]; | ||
|
||
const stages = ["New", "Qualified", "Proposal", "Negotiation", "Won", "Lost"]; | ||
|
||
const sources = ["Web", "Phone", "Email", "In person", "Other"]; | ||
|
||
const customers = Array(30) | ||
.fill(0) | ||
.map((_, i) => `Customer ${i + 1}`); | ||
|
||
const columns = [ | ||
"Salesperson", | ||
"Stage", | ||
"Customer", | ||
"Email", | ||
"Amount", | ||
"Probability", | ||
"Created on", | ||
"Source", | ||
"Active", | ||
]; | ||
|
||
function randomIntFromInterval(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
} | ||
|
||
export function makePivotDataset(rowsNumber = 10_000) { | ||
const cells = { | ||
A1: { content: "Salesperson" }, | ||
B1: { content: "Stage" }, | ||
C1: { content: "Customer" }, | ||
D1: { content: "Email" }, | ||
E1: { content: "Amount" }, | ||
F1: { content: "Probability" }, | ||
G1: { content: "Created on" }, | ||
H1: { content: "Source" }, | ||
I1: { content: "Active" }, | ||
}; | ||
let rowIndex = 2; | ||
const data = []; | ||
for (let i = 0; i < rowsNumber; i++) { | ||
const customer = customers[randomIntFromInterval(0, customers.length - 1)]; | ||
cells[`A${rowIndex}`] = { | ||
content: salesperson[randomIntFromInterval(0, salesperson.length - 1)], | ||
}; | ||
cells[`B${rowIndex}`] = { content: stages[randomIntFromInterval(0, stages.length - 1)] }; | ||
cells[`C${rowIndex}`] = { content: customer }; | ||
cells[`D${rowIndex}`] = { | ||
content: `${customer.replace(/\s/g, "").toLowerCase()}@example.com}`, | ||
}; | ||
cells[`E${rowIndex}`] = { content: `${randomIntFromInterval(0, 100000)}`, format: 2 }; | ||
cells[`F${rowIndex}`] = { content: `${randomIntFromInterval(0, 100)}`, format: 3 }; | ||
cells[`G${rowIndex}`] = { content: `${randomIntFromInterval(40179, 45657)}`, format: 1 }; //random date between 1/1/2010 and 31/12/2024 | ||
cells[`H${rowIndex}`] = { content: sources[randomIntFromInterval(0, sources.length - 1)] }; | ||
cells[`I${rowIndex}`] = { content: Math.random() > 0.5 ? "true" : "false" }; | ||
rowIndex++; | ||
} | ||
return { | ||
sheets: [ | ||
{ | ||
name: "Pivot", | ||
id: "pivot", | ||
colNumber: 256, | ||
rowNumber: rowsNumber + 1, | ||
cells: { | ||
A1: { | ||
content: `=PIVOT("1")`, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Data", | ||
id: "data", | ||
colNumber: columns.length, | ||
rowNumber: rowsNumber + 1, | ||
cells, | ||
}, | ||
], | ||
formats: { | ||
1: "d/m/yyyy", | ||
2: "[$$]#,##0.00", | ||
3: "0.00%", | ||
}, | ||
pivotNextId: 2, | ||
pivots: { | ||
1: { | ||
type: "SPREADSHEET", | ||
columns: [ | ||
{ | ||
name: "Stage", | ||
}, | ||
], | ||
rows: [ | ||
{ | ||
name: "Created on", | ||
granularity: "year_number", | ||
order: "asc", | ||
}, | ||
], | ||
measures: [ | ||
{ | ||
name: "Amount", | ||
aggregator: "sum", | ||
}, | ||
], | ||
name: "My pivot", | ||
dataSet: { | ||
zone: { | ||
top: 0, | ||
bottom: rowsNumber, | ||
left: 0, | ||
right: 8, | ||
}, | ||
sheetId: "data", | ||
}, | ||
formulaId: "1", | ||
}, | ||
}, | ||
}; | ||
} |
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,26 @@ | ||
/** | ||
* The only aim of this file is to make ts-jest happy, as it does not support | ||
* Object.groupBy and Map.groupBy at the current version (29.1.2) | ||
* This is a workaround to make it work. | ||
*/ | ||
|
||
interface ObjectConstructor { | ||
/** | ||
* Groups members of an iterable according to the return value of the passed callback. | ||
* @param items An iterable. | ||
* @param keySelector A callback which will be invoked for each item in items. | ||
*/ | ||
groupBy<K extends PropertyKey, T>( | ||
items: Iterable<T>, | ||
keySelector: (item: T, index: number) => K | ||
): Partial<Record<K, T[]>>; | ||
} | ||
|
||
interface MapConstructor { | ||
/** | ||
* Groups members of an iterable according to the return value of the passed callback. | ||
* @param items An iterable. | ||
* @param keySelector A callback which will be invoked for each item in items. | ||
*/ | ||
groupBy<K, T>(items: Iterable<T>, keySelector: (item: T, index: number) => K): Map<K, T[]>; | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
...sions/pivot_dimension/pivot_dimension.xml → ...rator/pivot_dimension/pivot_dimension.xml
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
File renamed without changes.
Oops, something went wrong.