mirror of
https://github.com/bringout/oca-ocb-report.git
synced 2026-04-23 17:02:02 +02:00
19.0 vanilla
This commit is contained in:
parent
62d197ac8b
commit
184bb0e321
667 changed files with 691406 additions and 239886 deletions
|
|
@ -0,0 +1,58 @@
|
|||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import { createModelWithDataSource } from "@spreadsheet/../tests/helpers/model";
|
||||
import { defineSpreadsheetModels } from "../helpers/data";
|
||||
import { LoadingDataError } from "@spreadsheet/o_spreadsheet/errors";
|
||||
|
||||
describe.current.tags("headless");
|
||||
|
||||
defineSpreadsheetModels();
|
||||
|
||||
test("get default currency format when it's in the config", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
modelConfig: { defaultCurrency: { position: "after", symbol: "θ", decimalPlaces: 2 } },
|
||||
mockRPC: async function (route, args) {
|
||||
throw new Error("Should not make any RPC");
|
||||
},
|
||||
});
|
||||
expect(model.getters.getCompanyCurrencyFormat()).toBe("#,##0.00[$θ]");
|
||||
});
|
||||
|
||||
test("get default currency format when it's not in the config", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_company_currency_for_spreadsheet") {
|
||||
return {
|
||||
code: "Odoo",
|
||||
symbol: "θ",
|
||||
position: "after",
|
||||
decimalPlaces: 2,
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(() => model.getters.getCompanyCurrencyFormat()).toThrow(LoadingDataError);
|
||||
await animationFrame();
|
||||
expect(model.getters.getCompanyCurrencyFormat()).toBe("#,##0.00[$θ]");
|
||||
expect.verifySteps([]);
|
||||
});
|
||||
|
||||
test("get specific currency format", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
modelConfig: { defaultCurrency: { position: "after", symbol: "θ", decimalPlaces: 2 } },
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_company_currency_for_spreadsheet" && args.args[0] === 42) {
|
||||
return {
|
||||
code: "Odoo",
|
||||
symbol: "O",
|
||||
position: "after",
|
||||
decimalPlaces: 2,
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
expect(() => model.getters.getCompanyCurrencyFormat(42)).toThrow(LoadingDataError);
|
||||
await animationFrame();
|
||||
expect(model.getters.getCompanyCurrencyFormat(42)).toBe("#,##0.00[$O]");
|
||||
});
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { setCellContent } from "@spreadsheet/../tests/helpers/commands";
|
||||
import { getCellValue, getEvaluatedCell } from "@spreadsheet/../tests/helpers/getters";
|
||||
import { createModelWithDataSource } from "@spreadsheet/../tests/helpers/model";
|
||||
import { waitForDataLoaded } from "@spreadsheet/helpers/model";
|
||||
import { defineSpreadsheetActions, defineSpreadsheetModels } from "../helpers/data";
|
||||
import { RPCError } from "@web/core/network/rpc";
|
||||
|
||||
describe.current.tags("headless");
|
||||
|
||||
defineSpreadsheetModels();
|
||||
defineSpreadsheetActions();
|
||||
|
||||
test("Basic exchange formula", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
const info = args.args[0][0];
|
||||
expect(info.from).toBe("EUR");
|
||||
expect(info.to).toBe("USD");
|
||||
expect(info.date).toBe(undefined);
|
||||
expect.step("rate fetched");
|
||||
return [{ ...info, rate: 0.9 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD")`);
|
||||
expect(getCellValue(model, "A1")).toBe("Loading...");
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe(0.9);
|
||||
expect.verifySteps(["rate fetched"]);
|
||||
});
|
||||
|
||||
test("rate formula at a given date(time)", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
const [A1, A2] = args.args[0];
|
||||
expect(A1.date).toBe("2020-12-31");
|
||||
expect(A2.date).toBe("2020-11-30");
|
||||
expect.step("rate fetched");
|
||||
return [
|
||||
{ ...A1, rate: 0.9 },
|
||||
{ ...A2, rate: 0.9 },
|
||||
];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD", "12-31-2020")`);
|
||||
setCellContent(model, "A2", `=ODOO.CURRENCY.RATE("EUR","USD", "11-30-2020 00:00:00")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["rate fetched"]);
|
||||
});
|
||||
|
||||
test("invalid date", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
throw new Error("Should not be called");
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD", "hello")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe("#ERROR");
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe(
|
||||
"The function ODOO.CURRENCY.RATE expects a number value, but 'hello' is a string, and cannot be coerced to a number."
|
||||
);
|
||||
});
|
||||
|
||||
test("rate formula at a given company", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
const [A1, A2] = args.args[0];
|
||||
expect(A1.company_id).toBe(1);
|
||||
expect(A2.company_id).toBe(2);
|
||||
expect.step("rate fetched");
|
||||
return [
|
||||
{ ...A1, rate: 0.7 },
|
||||
{ ...A2, rate: 0.9 },
|
||||
];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD",, 1)`);
|
||||
setCellContent(model, "A2", `=ODOO.CURRENCY.RATE("EUR","USD",, 2)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["rate fetched"]);
|
||||
expect(getCellValue(model, "A1")).toBe(0.7);
|
||||
expect(getCellValue(model, "A2")).toBe(0.9);
|
||||
});
|
||||
|
||||
test("invalid company id", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
const error = new RPCError();
|
||||
error.data = { message: "Invalid company id." };
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD",, 45)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe("#ERROR");
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe("Invalid company id.");
|
||||
});
|
||||
|
||||
test("Currency rate throw with unknown currency", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
const info = args.args[0][0];
|
||||
return [{ ...info, rate: false }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("INVALID","USD")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe("Currency rate unavailable.");
|
||||
});
|
||||
|
||||
test("Currency rates are only loaded once", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
expect.step("FETCH");
|
||||
const info = args.args[0][0];
|
||||
return [{ ...info, rate: 0.9 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["FETCH"]);
|
||||
setCellContent(model, "A2", `=ODOO.CURRENCY.RATE("EUR","USD")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps([]);
|
||||
});
|
||||
|
||||
test("Currency rates are loaded once by clock", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
expect.step("FETCH:" + args.args[0].length);
|
||||
const info1 = args.args[0][0];
|
||||
const info2 = args.args[0][1];
|
||||
return [
|
||||
{ ...info1, rate: 0.9 },
|
||||
{ ...info2, rate: 1 },
|
||||
];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD")`);
|
||||
setCellContent(model, "A2", `=ODOO.CURRENCY.RATE("EUR","SEK")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["FETCH:2"]);
|
||||
});
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import { setCellContent } from "@spreadsheet/../tests/utils/commands";
|
||||
import { getCell, getCellValue } from "@spreadsheet/../tests/utils/getters";
|
||||
import {
|
||||
createModelWithDataSource,
|
||||
waitForDataSourcesLoaded,
|
||||
} from "@spreadsheet/../tests/utils/model";
|
||||
|
||||
QUnit.module("spreadsheet > Currency");
|
||||
|
||||
QUnit.test("Basic exchange formula", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
const info = args.args[0][0];
|
||||
assert.equal(info.from, "EUR");
|
||||
assert.equal(info.to, "USD");
|
||||
assert.equal(info.date, undefined);
|
||||
assert.step("rate fetched");
|
||||
return [{ ...info, rate: 0.9 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD")`);
|
||||
assert.strictEqual(getCellValue(model, "A1"), "Loading...");
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.strictEqual(getCellValue(model, "A1"), 0.9);
|
||||
assert.verifySteps(["rate fetched"]);
|
||||
});
|
||||
|
||||
QUnit.test("rate formula at a given date(time)", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
const [A1, A2] = args.args[0];
|
||||
assert.equal(A1.date, "2020-12-31");
|
||||
assert.equal(A2.date, "2020-11-30");
|
||||
assert.step("rate fetched");
|
||||
return [
|
||||
{ ...A1, rate: 0.9 },
|
||||
{ ...A2, rate: 0.9 },
|
||||
];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD", "12-31-2020")`);
|
||||
setCellContent(model, "A2", `=ODOO.CURRENCY.RATE("EUR","USD", "11-30-2020 00:00:00")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.verifySteps(["rate fetched"]);
|
||||
});
|
||||
|
||||
QUnit.test("invalid date", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
throw new Error("Should not be called");
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD", "hello")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.strictEqual(getCellValue(model, "A1"), "#ERROR");
|
||||
assert.strictEqual(
|
||||
getCell(model, "A1").evaluated.error.message,
|
||||
"The function ODOO.CURRENCY.RATE expects a number value, but 'hello' is a string, and cannot be coerced to a number."
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("Currency rate throw with unknown currency", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
const info = args.args[0][0];
|
||||
return [{ ...info, rate: false }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("INVALID","USD")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.strictEqual(getCell(model, "A1").evaluated.error.message, "Currency rate unavailable.");
|
||||
});
|
||||
|
||||
QUnit.test("Currency rates are only loaded once", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
assert.step("FETCH");
|
||||
const info = args.args[0][0];
|
||||
return [{ ...info, rate: 0.9 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.verifySteps(["FETCH"]);
|
||||
setCellContent(model, "A2", `=ODOO.CURRENCY.RATE("EUR","USD")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.verifySteps([]);
|
||||
});
|
||||
|
||||
QUnit.test("Currency rates are loaded once by clock", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_rates_for_spreadsheet") {
|
||||
assert.step("FETCH:" + args.args[0].length);
|
||||
const info1 = args.args[0][0];
|
||||
const info2 = args.args[0][1];
|
||||
return [
|
||||
{ ...info1, rate: 0.9 },
|
||||
{ ...info2, rate: 1 },
|
||||
];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CURRENCY.RATE("EUR","USD")`);
|
||||
setCellContent(model, "A2", `=ODOO.CURRENCY.RATE("EUR","SEK")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.verifySteps(["FETCH:2"]);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue