[FIX] web: render reference fields as integer in pivot view

The value of the `order_reference` field introduced in [this PR] cannot
be displayed in pivot views
[this PR]:https://github.com/odoo/odoo/pull/116830

Solution:
Render `reference` fields like `many2one`

closes odoo/odoo#116830

Related: odoo/upgrade#4751
Related: odoo/enterprise#38895
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
MerlinGuillaume
2023-06-13 14:07:28 +02:00
parent 7bbec42f07
commit 23c43bd5cc
4 changed files with 62 additions and 3 deletions
@@ -39,7 +39,7 @@ export class PivotRenderer extends Component {
let formatType = this.model.metaData.widgets[cell.measure];
if (!formatType) {
const fieldType = field.type;
formatType = fieldType === "many2one" ? "integer" : fieldType;
formatType = ["many2one", "reference"].includes(fieldType) ? "integer" : fieldType;
}
//If the formatter is not found on the registry, search on the legacy fieldUtils.format.
//This must be removed when all the formatters will be on the registry
@@ -1079,7 +1079,7 @@ export class MockServer {
return;
}
if (
fields[fieldName].type === "many2one" &&
["many2one", "reference"].includes(fields[fieldName].type) &&
!["count_distinct", "array_agg"].includes(func)
) {
return;
@@ -1103,7 +1103,8 @@ export class MockServer {
}
break;
}
case "many2one": {
case "many2one":
case "reference": {
const ids = records.map((r) => r[fieldName]);
if (func === "array_agg") {
group[name] = ids.map((id) => (id ? id : null));
@@ -44,6 +44,10 @@ QUnit.module("MockServer", (hooks) => {
relation: "foo",
inverse_fname_by_model_name: { foo: "many2many_field" },
},
partner_ref: {
type: "reference",
selection: [["partner", "Partner"]],
},
},
records: [
{
@@ -54,6 +58,7 @@ QUnit.module("MockServer", (hooks) => {
name: "zzz",
partner_ids: [1, 2],
select: "dev",
partner_ref: "partner,1",
},
{
foo: 1,
@@ -64,6 +69,7 @@ QUnit.module("MockServer", (hooks) => {
partner_id: 2,
partner_ids: [1],
select: "new",
partner_ref: "partner,2"
},
{
foo: 17,
@@ -1285,6 +1291,23 @@ QUnit.module("MockServer", (hooks) => {
partner_id: 0,
},
]);
const result4 = await server.performRPC("", {
model: "bar",
method: "read_group",
args: [[]],
kwargs: {
fields: ["partner_ref:count_distinct"],
domain: [],
groupby: [],
},
});
assert.deepEqual(result4, [
{
__count: 6,
partner_ref: 2,
},
]);
});
QUnit.test("performRPC: read_progress_bar grouped by boolean", async (assert) => {
@@ -116,6 +116,15 @@ QUnit.module("Views", (hooks) => {
group_operator: undefined,
store: true,
},
ref: {
string: "Reference",
type: "reference",
selection: [
["product", "Product"],
["customer", "Customer"],
],
group_operator: "count_distinct",
},
},
records: [
{
@@ -127,6 +136,7 @@ QUnit.module("Views", (hooks) => {
customer: 1,
computed_field: 19,
company_type: "company",
ref: "product,37",
},
{
id: 2,
@@ -137,6 +147,7 @@ QUnit.module("Views", (hooks) => {
customer: 2,
computed_field: 23,
company_type: "individual",
ref: "product,41",
},
{
id: 3,
@@ -147,6 +158,7 @@ QUnit.module("Views", (hooks) => {
customer: 2,
computed_field: 26,
company_type: "company",
ref: "customer,1",
},
{
id: 4,
@@ -157,6 +169,7 @@ QUnit.module("Views", (hooks) => {
customer: 1,
computed_field: 19,
company_type: "individual",
ref: "customer,2",
},
],
},
@@ -3218,6 +3231,28 @@ QUnit.module("Views", (hooks) => {
);
});
QUnit.test("pivot view with reference field as a measure", async function (assert) {
assert.expect(1);
await makeView({
type: "pivot",
resModel: "partner",
serverData,
arch: `
<pivot>
<field name="ref" type="measure"/>
<field name="date" interval="month" type="col"/>
</pivot>`,
});
assert.strictEqual(
target.querySelector("table tbody tr").innerText.replace(/\s/g, ""),
"Total1124",
"should display ref distinct count as measure"
);
});
QUnit.test("m2o as measure, drilling down into data", async function (assert) {
assert.expect(1);