Skip to content

Commit

Permalink
Merge PR #44 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Sep 4, 2024
2 parents 3b5a3b1 + a864da7 commit c5014b6
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def _insert_pivot_dashboard_spreadsheet(self):
import_data["new"] = 1
if self.dynamic:
import_data["dyn_number_of_rows"] = self.number_of_rows
if self.dynamic_cols:
import_data["dyn_number_of_cols"] = self.number_of_cols
return {
"type": "ir.actions.client",
"tag": "action_spreadsheet_oca",
Expand All @@ -42,6 +44,8 @@ def _insert_pivot_dashboard(self, new_sheet=False):
import_data["new_sheet"] = new_sheet
if self.dynamic:
import_data["dyn_number_of_rows"] = self.number_of_rows
if self.dynamic_cols:
import_data["dyn_number_of_cols"] = self.number_of_cols
return {
"type": "ir.actions.client",
"tag": "action_spreadsheet_oca",
Expand Down
6 changes: 3 additions & 3 deletions spreadsheet_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ Usage
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Go to any pivot
* Press on insert button
* Select the dynamic option and set a number of rows
* Select the dynamic rows or dynamic columns option and set a number of rows/columns

A new table that will be updated with the actual or filtered values will be added.

* Note: When a pivot has multiple levels of aggrupations in the rows, the number of rows
selected will be transfered to each level.
* Note: When a pivot has multiple levels of aggrupations in the rows or the columns,
the number of rows/columns selected will be transfered to each level.

Example:
number of groups -> 2
Expand Down
3 changes: 2 additions & 1 deletion spreadsheet_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"spreadsheet_oca/static/src/spreadsheet/bundle/odoo_panels.esm.js",
"spreadsheet_oca/static/src/spreadsheet/bundle/chart_panels.esm.js",
"spreadsheet_oca/static/src/spreadsheet/bundle/chart_panel.esm.js",
"spreadsheet_oca/static/src/spreadsheet/utils/dynamic_row_generator.esm.js",
"spreadsheet_oca/static/src/spreadsheet/utils/dynamic_generators.esm.js",
"spreadsheet_oca/static/src/pivot/pivot_table.esm.js",
],
},
}
46 changes: 38 additions & 8 deletions spreadsheet_oca/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-18 13:08+0000\n"
"PO-Revision-Date: 2024-07-18 15:09+0200\n"
"POT-Creation-Date: 2024-09-03 11:51+0000\n"
"PO-Revision-Date: 2024-09-03 13:54+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
Expand Down Expand Up @@ -206,9 +206,20 @@ msgid "Duplicated groupbys in pivot are not supprted"
msgstr "Las agrupaciones duplicadas en la vista pivot no están soportadas"

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_select_row_number__dynamic_cols
msgid "Dynamic Cols"
msgstr "Columnas Dinámicas"

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_spreadsheet_import__dynamic_cols
msgid "Dynamic Columns"
msgstr "Columnas Dinámicas"

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_select_row_number__dynamic_rows
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_spreadsheet_import__dynamic
msgid "Dynamic"
msgstr "Dinámico"
msgid "Dynamic Rows"
msgstr "Filas Dinámicas"

#. module: spreadsheet_oca
#: model_terms:ir.ui.view,arch_db:spreadsheet_oca.spreadsheet_spreadsheet_form_view
Expand Down Expand Up @@ -403,12 +414,22 @@ msgstr "Siguiente"
msgid "Next Revision"
msgstr "Siguiente revisión"

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_select_row_number__number_of_cols
msgid "Number Of Cols"
msgstr "Número de columnas"

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_select_row_number__number_of_rows
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_spreadsheet_import__number_of_rows
msgid "Number Of Rows"
msgstr "Número de filas"

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_spreadsheet_import__number_of_cols
msgid "Number of Columns"
msgstr "Número de columnas"

#. module: spreadsheet_oca
#: model_terms:ir.ui.view,arch_db:spreadsheet_oca.spreadsheet_spreadsheet_import_form_view
msgid "OK"
Expand Down Expand Up @@ -557,14 +578,23 @@ msgstr "Hojas de cálculo"
msgid "Stacked"
msgstr "Apilados"

#. module: spreadsheet_oca
#: model:ir.model.fields,help:spreadsheet_oca.field_spreadsheet_spreadsheet_import__dynamic_cols
msgid ""
"This field allows you to generate tables that its cols are updated with the "
"filters set in the spreadsheets."
msgstr ""
"Este campo permite generar tablas en las que se actualizan sus columnas con "
"los filtros establecidos en las hojas de cálculo."

#. module: spreadsheet_oca
#: model:ir.model.fields,help:spreadsheet_oca.field_spreadsheet_spreadsheet_import__dynamic
msgid ""
"This field allows you to generate tables that are updated with the filters "
"set in the spreadsheets."
"This field allows you to generate tables that its rows are updated with the "
"filters set in the spreadsheets."
msgstr ""
"Este campo permite generar tablas que se actualizan con los filtros "
"establecidos en las hojas de cálculo."
"Este campo permite generar tablas en las que se actualizan sus filas con "
"los filtros establecidos en las hojas de cálculo."

#. module: spreadsheet_oca
#. odoo-javascript
Expand Down
36 changes: 33 additions & 3 deletions spreadsheet_oca/i18n/spreadsheet_oca.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-09-03 11:51+0000\n"
"PO-Revision-Date: 2024-09-03 11:51+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -208,8 +210,19 @@ msgid "Duplicated groupbys in pivot are not supprted"
msgstr ""

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_select_row_number__dynamic_cols
msgid "Dynamic Cols"
msgstr ""

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_spreadsheet_import__dynamic_cols
msgid "Dynamic Columns"
msgstr ""

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_select_row_number__dynamic_rows
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_spreadsheet_import__dynamic
msgid "Dynamic"
msgid "Dynamic Rows"
msgstr ""

#. module: spreadsheet_oca
Expand Down Expand Up @@ -413,12 +426,22 @@ msgstr ""
msgid "Next Revision"
msgstr ""

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_select_row_number__number_of_cols
msgid "Number Of Cols"
msgstr ""

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_select_row_number__number_of_rows
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_spreadsheet_import__number_of_rows
msgid "Number Of Rows"
msgstr ""

#. module: spreadsheet_oca
#: model:ir.model.fields,field_description:spreadsheet_oca.field_spreadsheet_spreadsheet_import__number_of_cols
msgid "Number of Columns"
msgstr ""

#. module: spreadsheet_oca
#: model_terms:ir.ui.view,arch_db:spreadsheet_oca.spreadsheet_spreadsheet_import_form_view
msgid "OK"
Expand Down Expand Up @@ -567,11 +590,18 @@ msgstr ""
msgid "Stacked"
msgstr ""

#. module: spreadsheet_oca
#: model:ir.model.fields,help:spreadsheet_oca.field_spreadsheet_spreadsheet_import__dynamic_cols
msgid ""
"This field allows you to generate tables that its cols are updated with the "
"filters set in the spreadsheets."
msgstr ""

#. module: spreadsheet_oca
#: model:ir.model.fields,help:spreadsheet_oca.field_spreadsheet_spreadsheet_import__dynamic
msgid ""
"This field allows you to generate tables that are updated with the filters "
"set in the spreadsheets."
"This field allows you to generate tables that its rows are updated with the "
"filters set in the spreadsheets."
msgstr ""

#. module: spreadsheet_oca
Expand Down
6 changes: 3 additions & 3 deletions spreadsheet_oca/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Go to any pivot
* Press on insert button
* Select the dynamic option and set a number of rows
* Select the dynamic rows or dynamic columns option and set a number of rows/columns

A new table that will be updated with the actual or filtered values will be added.

* Note: When a pivot has multiple levels of aggrupations in the rows, the number of rows
selected will be transfered to each level.
* Note: When a pivot has multiple levels of aggrupations in the rows or the columns,
the number of rows/columns selected will be transfered to each level.

Example:
number of groups -> 2
Expand Down
6 changes: 3 additions & 3 deletions spreadsheet_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,12 @@ <h2><a class="toc-backref" href="#toc-entry-3"><strong>Create a new dynamic spre
<ul class="simple">
<li>Go to any pivot</li>
<li>Press on insert button</li>
<li>Select the dynamic option and set a number of rows</li>
<li>Select the dynamic rows or dynamic columns option and set a number of rows/columns</li>
</ul>
<p>A new table that will be updated with the actual or filtered values will be added.</p>
<ul>
<li><p class="first">Note: When a pivot has multiple levels of aggrupations in the rows, the number of rows
selected will be transfered to each level.</p>
<li><p class="first">Note: When a pivot has multiple levels of aggrupations in the rows or the columns,
the number of rows/columns selected will be transfered to each level.</p>
<p>Example:
number of groups -&gt; 2
number of rows -&gt; 3</p>
Expand Down
67 changes: 67 additions & 0 deletions spreadsheet_oca/static/src/pivot/pivot_table.esm.js
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);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
import {time_to_str} from "web.time";
import {useService} from "@web/core/utils/hooks";
import {FormViewDialog} from "@web/views/view_dialogs/form_view_dialog";
import {makeDynamicRows} from "../utils/dynamic_row_generator.esm";
import {makeDynamicCols, makeDynamicRows} from "../utils/dynamic_generators.esm";

const {sidePanelRegistry, topbarMenuRegistry} = spreadsheet.registries;
const {createFullMenuItem} = spreadsheet.helpers;
Expand Down Expand Up @@ -127,30 +127,45 @@ export class PivotPanelDisplay extends Component {
.getPivotDataSource(this.props.pivotId)
.copyModelWithOriginalDomain();
var {cols, rows, measures} = datasourceModel.getTableStructure().export();
const number_of_rows = await new Promise((resolve) => {
this.dialog.add(
FormViewDialog,
{
title: this.env._t("Select the quantity of rows"),
resModel: "spreadsheet.select.row.number",
onRecordSaved: async (record) => {
resolve(record.data.number_of_rows);
const {dynamic_rows, number_of_rows, dynamic_cols, number_of_cols} =
await new Promise((resolve) => {
this.dialog.add(
FormViewDialog,
{
title: this.env._t("Select the quantity of rows"),
resModel: "spreadsheet.select.row.number",
onRecordSaved: async (record) => {
resolve({
dynamic_rows: record.data.dynamic_rows,
number_of_rows: record.data.number_of_rows,
dynamic_cols: record.data.dynamic_cols,
number_of_cols: record.data.number_of_cols,
});
},
},
},
{onClose: () => resolve(false)}
);
});
if (!number_of_rows) {
{onClose: () => resolve(false)}
);
});
if (!dynamic_rows && !dynamic_cols) {
return;
}
const indentations = rows.map((r) => r.indent);
const max_indentation = Math.max(...indentations);
rows = makeDynamicRows(
this.props.pivotDefinition.rowGroupBys,
number_of_rows,
1,
max_indentation
);
if (dynamic_rows) {
const indentations = rows.map((r) => r.indent);
const max_indentation = Math.max(...indentations);
rows = makeDynamicRows(
this.props.pivotDefinition.rowGroupBys,
number_of_rows,
1,
max_indentation
);
}
if (dynamic_cols) {
cols = makeDynamicCols(
this.props.pivotDefinition.colGroupBys,
number_of_cols,
this.props.pivotDefinition.measures
);
}
const table = {
cols,
rows,
Expand Down
Loading

0 comments on commit c5014b6

Please sign in to comment.