This module allows to show an x2many field with 3-tuples ($x_value,
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 cb429feff4ae..9f4dceced343 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
@@ -3,17 +3,14 @@
import {Component, onWillUpdateProps} from "@odoo/owl";
import {evaluateBooleanExpr, evaluateExpr} from "@web/core/py_js/py";
import {Domain} from "@web/core/domain";
+import {Record} from "@web/model/relational_model/record";
import {getFieldContext} from "@web/model/relational_model/utils";
-import {registry} from "@web/core/registry";
-const fieldRegistry = registry.category("fields");
export class X2Many2DMatrixRenderer extends Component {
setup() {
- this.ValueFieldComponent = this._getValueFieldComponent();
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);
@@ -28,6 +25,7 @@ export class X2Many2DMatrixRenderer extends Component {
const column = {
value: record.data[this.matrixFields.x],
text: record.data[this.matrixFields.x],
+ rawValue: record.data[this.matrixFields.x],
};
if (record.fields[this.matrixFields.x].type === "many2one") {
column.text = column.value[1];
@@ -45,6 +43,7 @@ export class X2Many2DMatrixRenderer extends Component {
const row = {
value: record.data[this.matrixFields.y],
text: record.data[this.matrixFields.y],
+ rawValue: record.data[this.matrixFields.y],
};
if (record.fields[this.matrixFields.y].type === "many2one") {
row.text = row.value[1];
@@ -94,62 +93,41 @@ export class X2Many2DMatrixRenderer extends Component {
return this.props.matrixFields;
}
- _getValueField() {
- const field = this.list.fields[this.matrixFields.value];
- if (!field.widget) {
- return fieldRegistry.get(field.type);
- }
- return fieldRegistry.get(field.widget);
- }
-
- _getValueFieldComponent() {
- return this._getValueField().component;
+ get valueFieldComponent() {
+ return this.props.list_view.fieldNodes[this.matrixFields.value + "_0"].field
+ .component;
}
- _getValueFieldType() {
- const field = this.list.fields[this.matrixFields.value];
- return field.type;
+ get xFieldComponent() {
+ return this.props.list_view.fieldNodes[this.matrixFields.x + "_0"].field
+ .component;
}
- _getXAxisField() {
- return this.list.fields[this.matrixFields.x];
- }
-
- _getYAxisField() {
- return this.list.fields[this.matrixFields.y];
+ get yFieldComponent() {
+ return this.props.list_view.fieldNodes[this.matrixFields.y + "_0"].field
+ .component;
}
_aggregateRow(row) {
const y = this.rows.findIndex((r) => r.value === row);
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);
+ return total;
}
_aggregateColumn(column) {
const x = this.columns.findIndex((c) => c.value === column);
-
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);
+ return total;
}
_aggregateAll() {
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);
+ return total;
}
_canAggregate() {
@@ -158,26 +136,43 @@ export class X2Many2DMatrixRenderer extends Component {
);
}
- getValueFieldProps(column, row) {
+ _getValueFieldProps(column, row) {
const x = this.columns.findIndex((c) => c.value === column);
const y = this.rows.findIndex((r) => r.value === row);
- let record = null;
- let value = null;
- if (
- this.matrix[y] &&
- this.matrix[y][x] &&
- (record = this.matrix[y][x].records[0])
- ) {
- record = this.matrix[y][x].records[0];
- value = this.matrix[y][x].value;
- }
- value = record ? record.data[this.matrixFields.value] : value;
- this.matrix[y][x].value = value;
+ const record = this.matrix[y][x].records[0];
+
if (!record) {
return null;
}
+ return this._getMatrixFieldProps(record, "value");
+ }
+
+ _getAxisFieldProps(value, axis) {
+ const fieldName = this.matrixFields[axis];
+ const record = new Record(this.list.model, this.list._config, {
+ [fieldName]: value,
+ });
+ const props = this._getMatrixFieldProps(record, axis);
+ if (this.list.fields[fieldName].type === "many2one") {
+ props.canOpen =
+ axis === "x" ? this.props.isXClickable : this.props.isYClickable;
+ }
+ props.readonly = true;
+ return props;
+ }
+
+ _getAggregateProps(value) {
+ const record = new Record(this.list.model, this.list._config, {
+ [this.matrixFields.value]: value,
+ });
+ const props = this._getMatrixFieldProps(record, "value");
+ props.readonly = true;
+ return props;
+ }
+
+ _getMatrixFieldProps(record, fieldName) {
const fieldInfo =
- this.props.list_view.fieldNodes[this.matrixFields.value + "_0"];
+ this.props.list_view.fieldNodes[this.matrixFields[fieldName] + "_0"];
const dynamicInfo = {
get context() {
return getFieldContext(record, fieldInfo.name, fieldInfo.context);
@@ -201,19 +196,15 @@ export class X2Many2DMatrixRenderer extends Component {
record.evalContextWithVirtualIds
),
};
- const valueField = this._getValueField();
const result = {
readonly: dynamicInfo.readonly,
record: record,
- name: this.matrixFields.value,
- ...(valueField.extractProps || (() => ({}))).apply(valueField, [
+ name: this.matrixFields[fieldName],
+ ...(fieldInfo.field.extractProps || (() => ({}))).apply(fieldInfo.field, [
fieldInfo,
dynamicInfo,
]),
};
- if (value === null) {
- result.readonly = true;
- }
return result;
}
}
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 edc7b67fa5db..6aff7687dbf5 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
@@ -14,15 +14,10 @@
t-key="column.value"
class="text-center"
>
-