[FIX] spreadsheet: compute aggregates resulting to zero
When the aggregated value is 0 (9000 + -9000 = 0), it displays an empty cell in spreadsheet, instead of zero. closes odoo/odoo#159148 Task: 3827502 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
This commit is contained in:
@@ -289,7 +289,7 @@ export class SpreadsheetPivotModel extends PivotModel {
|
||||
const { cols, rows } = this._getColsRowsValuesFromDomain(domain);
|
||||
const group = JSON.stringify([rows, cols]);
|
||||
const values = this.data.measurements[group];
|
||||
return (values && values[0][measure]) || "";
|
||||
return (values && values[0][measure]) ?? "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -599,6 +599,29 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => {
|
||||
assert.equal(getCellValue(model, "E4"), 95);
|
||||
});
|
||||
|
||||
QUnit.test("aggregate to 0", async function (assert) {
|
||||
const serverData = getBasicServerData();
|
||||
serverData.models.partner.records = [
|
||||
{ id: 1, name: "A", probability: 10 },
|
||||
{ id: 2, name: "B", probability: -10 },
|
||||
];
|
||||
|
||||
const { model } = await createSpreadsheetWithPivot({
|
||||
serverData,
|
||||
arch: /*xml*/ `
|
||||
<pivot>
|
||||
<field name="name" type="row"/>
|
||||
<field name="probability" type="measure"/>
|
||||
</pivot>`,
|
||||
});
|
||||
setCellContent(model, "A1", '=ODOO.PIVOT(1, "probability", "name", "A")');
|
||||
setCellContent(model, "A2", '=ODOO.PIVOT(1, "probability", "name", "B")');
|
||||
setCellContent(model, "A3", '=ODOO.PIVOT(1, "probability")');
|
||||
assert.strictEqual(getEvaluatedCell(model, "A1").value, 10);
|
||||
assert.strictEqual(getEvaluatedCell(model, "A2").value, -10);
|
||||
assert.strictEqual(getEvaluatedCell(model, "A3").value, 0);
|
||||
});
|
||||
|
||||
QUnit.test("can import/export sorted pivot", async (assert) => {
|
||||
const spreadsheetData = {
|
||||
pivots: {
|
||||
|
||||
Reference in New Issue
Block a user