From 01ba699445c17d97bbb6ed96e3f8174e3b44f8b8 Mon Sep 17 00:00:00 2001 From: SodexisTeam Date: Mon, 10 Jun 2024 18:59:05 +0530 Subject: [PATCH] [MIG] web_widget_x2many_2d_matrix: Migration to 17.0 --- web_widget_x2many_2d_matrix/README.rst | 1 + web_widget_x2many_2d_matrix/__manifest__.py | 3 +- .../readme/CONTRIBUTORS.md | 1 + .../static/description/index.html | 1 + .../x2many_2d_matrix_field.esm.js | 105 ++++++------------ .../x2many_2d_matrix_field.scss | 18 ++- .../x2many_2d_matrix_field.xml | 4 +- .../x2many_2d_matrix_renderer.esm.js | 66 +++++------ .../x2many_2d_matrix_renderer.xml | 21 +--- .../views/fields/boolean/boolean_field.esm.js | 13 --- 10 files changed, 88 insertions(+), 145 deletions(-) delete mode 100644 web_widget_x2many_2d_matrix/static/src/views/fields/boolean/boolean_field.esm.js diff --git a/web_widget_x2many_2d_matrix/README.rst b/web_widget_x2many_2d_matrix/README.rst index 12ab573a8..78d07082b 100644 --- a/web_widget_x2many_2d_matrix/README.rst +++ b/web_widget_x2many_2d_matrix/README.rst @@ -219,6 +219,7 @@ Contributors - Adrià Gil Sorribes - Christopher Ormaza +- SodexisTeam Maintainers ----------- diff --git a/web_widget_x2many_2d_matrix/__manifest__.py b/web_widget_x2many_2d_matrix/__manifest__.py index 2bca94609..4a8c40b57 100644 --- a/web_widget_x2many_2d_matrix/__manifest__.py +++ b/web_widget_x2many_2d_matrix/__manifest__.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "2D matrix for x2many fields", - "version": "16.0.1.1.3", + "version": "17.0.1.0.0", "maintainers": ["ChrisOForgeFlow"], "development_status": "Production/Stable", "author": ( @@ -35,7 +35,6 @@ "x2many_2d_matrix_field.xml", "web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/" "x2many_2d_matrix_field.scss", - "web_widget_x2many_2d_matrix/static/src/views/fields/boolean/boolean_field.esm.js", ], }, } diff --git a/web_widget_x2many_2d_matrix/readme/CONTRIBUTORS.md b/web_widget_x2many_2d_matrix/readme/CONTRIBUTORS.md index 55fb01564..abfc17c88 100644 --- a/web_widget_x2many_2d_matrix/readme/CONTRIBUTORS.md +++ b/web_widget_x2many_2d_matrix/readme/CONTRIBUTORS.md @@ -9,3 +9,4 @@ - Alexey Pelykh \<\> - Adrià Gil Sorribes \<\> - Christopher Ormaza \<\> +- SodexisTeam \<\> diff --git a/web_widget_x2many_2d_matrix/static/description/index.html b/web_widget_x2many_2d_matrix/static/description/index.html index cdba63012..470e35561 100644 --- a/web_widget_x2many_2d_matrix/static/description/index.html +++ b/web_widget_x2many_2d_matrix/static/description/index.html @@ -574,6 +574,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
  • Adrià Gil Sorribes <adria.gil@forgeflow.com>
  • Christopher Ormaza <chris.ormaza@forgeflow.com>
  • +
  • SodexisTeam <dev@sodexis.com>
  • diff --git a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.esm.js b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.esm.js index 9bfa424a8..40ca3ac50 100644 --- a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.esm.js +++ b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.esm.js @@ -12,89 +12,46 @@ export class X2Many2DMatrixField extends Component { } getList() { - return this.props.value; + return this.props.record.data[this.props.name]; } get list() { return this.getList(); } - - _getDefaultRecordValues() { - return {}; - } - - async commitChange(x, y, value) { - const fields = this.props.matrixFields; - const values = this._getDefaultRecordValues(); - - const matchingRecords = this.list.records.filter((record) => { - let recordX = record.data[fields.x]; - let recordY = record.data[fields.y]; - if (record.fields[fields.x].type === "many2one") { - recordX = recordX[0]; - } - if (record.fields[fields.y].type === "many2one") { - recordY = recordY[0]; - } - return recordX === x && recordY === y; - }); - if (matchingRecords.length === 1) { - values[fields.value] = value; - await matchingRecords[0].update(values); - } else { - values[fields.x] = x; - values[fields.y] = y; - - if (this.list.fields[this.props.matrixFields.x].type === "many2one") { - values[fields.x] = [x, "/"]; - } - if (this.list.fields[this.props.matrixFields.y].type === "many2one") { - values[fields.y] = [y, "/"]; - } - - let total = 0; - if (matchingRecords.length) { - total = matchingRecords - .map((r) => r.data[fields.value]) - .reduce((aggr, v) => aggr + v); - } - const diff = value - total; - values[fields.value] = diff; - const record = await this.list.addNew({ - mode: "edit", - }); - await record.update(values); - } - this.props.setDirty(false); - } } X2Many2DMatrixField.template = "web_widget_x2many_2d_matrix.X2Many2DMatrixField"; X2Many2DMatrixField.props = { ...standardFieldProps, - matrixFields: Object, - isXClickable: Boolean, - isYClickable: Boolean, - showRowTotals: Boolean, - showColumnTotals: Boolean, -}; -X2Many2DMatrixField.components = {X2Many2DMatrixRenderer}; -X2Many2DMatrixField.extractProps = ({attrs}) => { - return { - matrixFields: { - value: attrs.field_value, - x: attrs.field_x_axis, - y: attrs.field_y_axis, - }, - isXClickable: archParseBoolean(attrs.x_axis_clickable), - isYClickable: archParseBoolean(attrs.y_axis_clickable), - showRowTotals: - "show_row_totals" in attrs ? archParseBoolean(attrs.show_row_totals) : true, - showColumnTotals: - "show_column_totals" in attrs - ? archParseBoolean(attrs.show_column_totals) - : true, - }; + list: {type: Object, optional: true}, + matrixFields: {type: Object, optional: true}, + isXClickable: {type: Boolean, optional: true}, + isYClickable: {type: Boolean, optional: true}, + showRowTotals: {type: Boolean, optional: true}, + showColumnTotals: {type: Boolean, optional: true}, }; -registry.category("fields").add("x2many_2d_matrix", X2Many2DMatrixField); +X2Many2DMatrixField.components = {X2Many2DMatrixRenderer}; +export const x2Many2DMatrixField = { + component: X2Many2DMatrixField, + extractProps({attrs}) { + return { + matrixFields: { + value: attrs.field_value, + x: attrs.field_x_axis, + y: attrs.field_y_axis, + }, + isXClickable: archParseBoolean(attrs.x_axis_clickable), + isYClickable: archParseBoolean(attrs.y_axis_clickable), + showRowTotals: + "show_row_totals" in attrs + ? archParseBoolean(attrs.show_row_totals) + : true, + showColumnTotals: + "show_column_totals" in attrs + ? archParseBoolean(attrs.show_column_totals) + : true, + }; + }, +}; +registry.category("fields").add("x2many_2d_matrix", x2Many2DMatrixField); diff --git a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.scss b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.scss index 424527189..65e600333 100644 --- a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.scss +++ b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.scss @@ -6,6 +6,10 @@ $x2many_2d_matrix_max_height: 450px; overflow-y: auto; } + .o_input { + padding: 1px 0px; + } + .table { > thead > tr > th { white-space: pre-line; @@ -31,18 +35,23 @@ $x2many_2d_matrix_max_height: 450px; } > td { - text-align: left; + text-align: right; + + .o_field_many2one_selection { + text-align: left; + } &:first-child { position: sticky; left: 0; + text-align: left; border-right-width: 1px; border-right-color: $gray-300; border-right-style: solid; box-shadow: -1px 5px 10px $gray-300; } &.row-total { - padding: 0.75rem; + padding: 0.5rem 0.75rem; font-weight: bold; position: sticky; right: 0; @@ -56,17 +65,18 @@ $x2many_2d_matrix_max_height: 450px; } > tfoot > tr > th { - padding: 0.75rem; - text-align: left; + text-align: right; background-color: $o-list-footer-bg-color; position: sticky; bottom: 0; &.col-total { + padding: 0.75rem; right: 0; border-left-width: 1px; border-left-color: $gray-300; border-left-style: solid; + background-color: white; } } } diff --git a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.xml b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.xml index 1f9088613..c6b02aea6 100644 --- a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.xml +++ b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_field/x2many_2d_matrix_field.xml @@ -1,14 +1,12 @@ - +
    diff --git a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_renderer/x2many_2d_matrix_renderer.esm.js b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_renderer/x2many_2d_matrix_renderer.esm.js index 95d7ad9c6..56cb698dd 100644 --- a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_renderer/x2many_2d_matrix_renderer.esm.js +++ b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_renderer/x2many_2d_matrix_renderer.esm.js @@ -2,6 +2,7 @@ import {Component, onWillUpdateProps} from "@odoo/owl"; import {registry} from "@web/core/registry"; +const fieldRegistry = registry.category("fields"); export class X2Many2DMatrixRenderer extends Component { setup() { @@ -9,6 +10,7 @@ export class X2Many2DMatrixRenderer extends Component { this.columns = this._getColumns(); this.rows = this._getRows(); this.matrix = this._getMatrix(); + this.ValueFieldType = this._getValueFieldType(); onWillUpdateProps((newProps) => { this.columns = this._getColumns(newProps.list.records); @@ -90,30 +92,48 @@ export class X2Many2DMatrixRenderer extends Component { } _getValueFieldComponent() { - const field = this.list.activeFields[this.matrixFields.value]; + const field = this.list.fields[this.matrixFields.value]; if (!field.widget) { - return this.list.activeFields[this.matrixFields.value].FieldComponent; + return fieldRegistry.get(field.type).component; } - return registry.category("fields").get(field.widget); + return fieldRegistry.get(field.widget).component; + } + + _getValueFieldType() { + const field = this.list.fields[this.matrixFields.value]; + return field.type; } _aggregateRow(row) { const y = this.rows.findIndex((r) => r.value === row); - return this.matrix[y].map((r) => r.value).reduce((aggr, x) => aggr + x); + const total = this.matrix[y].map((r) => r.value).reduce((aggr, x) => aggr + x); + if (this.ValueFieldType === "integer") { + return total; + } + return Number(total).toFixed(2); } _aggregateColumn(column) { const x = this.columns.findIndex((c) => c.value === column); - return this.matrix + + const total = this.matrix .map((r) => r[x]) .map((r) => r.value) .reduce((aggr, y) => aggr + y); + if (this.ValueFieldType === "integer") { + return total; + } + return Number(total).toFixed(2); } _aggregateAll() { - return this.matrix + const total = this.matrix .map((r) => r.map((x) => x.value).reduce((aggr, x) => aggr + x)) .reduce((aggr, y) => aggr + y); + if (this.ValueFieldType === "integer") { + return total; + } + return Number(total).toFixed(2); } _canAggregate() { @@ -122,18 +142,9 @@ export class X2Many2DMatrixRenderer extends Component { ); } - update(x, y, value) { - this.matrix[y][x].value = value; - const xFieldValue = this.columns[x].value; - const yFieldValue = this.rows[y].value; - - this.props.onUpdate(xFieldValue, yFieldValue, value); - } - getValueFieldProps(column, row) { const x = this.columns.findIndex((c) => c.value === column); const y = this.rows.findIndex((r) => r.value === row); - const {props, propsFromAttrs} = this.list.activeFields[this.matrixFields.value]; let record = null; let value = null; if ( @@ -144,18 +155,9 @@ export class X2Many2DMatrixRenderer extends Component { record = this.matrix[y][x].records[0]; value = this.matrix[y][x].value; } - if (this.list.fields[this.matrixFields.value].type === "boolean") { - record.bypass_readonly = true; - } - value = - !this._canAggregate() && record - ? record.data[this.matrixFields.value] - : value; + value = record ? record.data[this.matrixFields.value] : value; + this.matrix[y][x].value = value; const result = { - ...props, - ...propsFromAttrs, - value: value, - update: (val) => this.update(x, y, val), readonly: this.props.readonly, record: record, name: this.matrixFields.value, @@ -169,11 +171,9 @@ export class X2Many2DMatrixRenderer extends Component { X2Many2DMatrixRenderer.template = "web_widget_x2many_2d_matrix.X2Many2DMatrixRenderer"; X2Many2DMatrixRenderer.props = { - list: Object, - matrixFields: Object, - setDirty: Function, - onUpdate: Function, - readonly: Boolean, - showRowTotals: Boolean, - showColumnTotals: Boolean, + list: {type: Object, optional: true}, + matrixFields: {type: Object, optional: true}, + readonly: {type: Boolean, optional: true}, + showRowTotals: {type: Boolean, optional: true}, + showColumnTotals: {type: Boolean, optional: true}, }; diff --git a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_renderer/x2many_2d_matrix_renderer.xml b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_renderer/x2many_2d_matrix_renderer.xml index be7e979bf..562d565d2 100644 --- a/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_renderer/x2many_2d_matrix_renderer.xml +++ b/web_widget_x2many_2d_matrix/static/src/components/x2many_2d_matrix_renderer/x2many_2d_matrix_renderer.xml @@ -1,6 +1,6 @@ - + @@ -46,18 +43,10 @@ diff --git a/web_widget_x2many_2d_matrix/static/src/views/fields/boolean/boolean_field.esm.js b/web_widget_x2many_2d_matrix/static/src/views/fields/boolean/boolean_field.esm.js deleted file mode 100644 index d3efe8549..000000000 --- a/web_widget_x2many_2d_matrix/static/src/views/fields/boolean/boolean_field.esm.js +++ /dev/null @@ -1,13 +0,0 @@ -/** @odoo-module **/ - -import {BooleanField} from "@web/views/fields/boolean/boolean_field"; -import {patch} from "@web/core/utils/patch"; - -patch(BooleanField.prototype, "web_widget_x2many_2d_matrix", { - get isReadonly() { - if (this.props.record.bypass_readonly) { - return false; - } - return this._super(...arguments); - }, -});
    - +
    - + - +