diff --git a/web_widget_x2many_2d_matrix/README.rst b/web_widget_x2many_2d_matrix/README.rst index 12ab573a868b..b4b4e0e68a07 100644 --- a/web_widget_x2many_2d_matrix/README.rst +++ b/web_widget_x2many_2d_matrix/README.rst @@ -202,6 +202,7 @@ Authors * Camptocamp * CorporateHub * Onestein +* SodexisTeam Contributors ------------ @@ -219,6 +220,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 2bca94609464..32912bfefb13 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": ( @@ -14,6 +14,7 @@ "Camptocamp, " "CorporateHub, " "Onestein, " + "SodexisTeam, " "Odoo Community Association (OCA)" ), "website": "https://github.com/OCA/web", @@ -35,7 +36,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 55fb0156480a..abfc17c881fb 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 cdba6301298f..1c682fa83cc8 100644 --- a/web_widget_x2many_2d_matrix/static/description/index.html +++ b/web_widget_x2many_2d_matrix/static/description/index.html @@ -556,6 +556,7 @@

Authors

  • Camptocamp
  • CorporateHub
  • Onestein
  • +
  • SodexisTeam
  • @@ -574,6 +575,7 @@

    Contributors

  • 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 9bfa424a87e1..40ca3ac50d0d 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, + 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}, }; + 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, - }; +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); +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 424527189acd..9cc76e5442a0 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 @@ -31,11 +31,12 @@ $x2many_2d_matrix_max_height: 450px; } > td { - text-align: left; + text-align: right; &:first-child { position: sticky; left: 0; + text-align: left; border-right-width: 1px; border-right-color: $gray-300; border-right-style: solid; @@ -56,8 +57,7 @@ $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; @@ -67,6 +67,7 @@ $x2many_2d_matrix_max_height: 450px; 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 1f908861361b..c6b02aea6ba9 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 95d7ad9c66e4..56cb698ddc43 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 be7e979bf16f..562d565d299b 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 d3efe854997c..000000000000 --- 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); - }, -});
    - +
    - + - +