mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-22 11:22:00 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -1,42 +1,68 @@
|
|||
/** @odoo-module */
|
||||
import {
|
||||
SpreadsheetModels,
|
||||
defineSpreadsheetModels,
|
||||
getBasicData,
|
||||
} from "@spreadsheet/../tests/helpers/data";
|
||||
import { fields, models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
import { getBasicData } from "@spreadsheet/../tests/utils/data";
|
||||
export class AccountMoveLine extends models.Model {
|
||||
_name = "account.move.line";
|
||||
|
||||
account_id = fields.Many2one({ relation: "account.account" });
|
||||
date = fields.Date({ string: "Date" });
|
||||
name = fields.Char({ string: "Name" });
|
||||
|
||||
_records = [
|
||||
{ id: 1, name: "line1", account_id: 1, date: "2022-06-01" },
|
||||
{ id: 2, name: "line2", account_id: 2, date: "2022-06-23" },
|
||||
];
|
||||
}
|
||||
|
||||
export class AccountAccount extends models.Model {
|
||||
_name = "account.account";
|
||||
|
||||
code = fields.Char({ string: "Code" });
|
||||
account_type = fields.Char({ string: "Account type" });
|
||||
|
||||
spreadsheet_fetch_debit_credit(args) {
|
||||
return new Array(args.length).fill({ credit: 0, debit: 0 });
|
||||
}
|
||||
|
||||
get_account_group(accountTypes) {
|
||||
const data = accountTypes.map((accountType) => {
|
||||
const records = this.env["account.account"].search_read(
|
||||
[["account_type", "=", accountType]],
|
||||
["code"]
|
||||
);
|
||||
return records.map((record) => record.code);
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
_records = [
|
||||
{ id: 1, code: "100104", account_type: "income" },
|
||||
{ id: 2, code: "100105", account_type: "income_other" },
|
||||
{ id: 3, code: "200104", account_type: "income" },
|
||||
];
|
||||
}
|
||||
|
||||
export function getAccountingData() {
|
||||
return {
|
||||
models: {
|
||||
...getBasicData(),
|
||||
"account.move.line": {
|
||||
fields: {
|
||||
account_id: { type: "many2one", relation: "account.account" },
|
||||
date: { string: "Date", type: "date" },
|
||||
},
|
||||
records: [
|
||||
{ id: 1, name: "line1", account_id: 1, date: "2022-06-01" },
|
||||
{ id: 2, name: "line2", account_id: 2, date: "2022-06-23" },
|
||||
],
|
||||
},
|
||||
"account.account": {
|
||||
fields: {
|
||||
code: { string: "Code", type: "string" },
|
||||
account_type: { string: "Account type", type: "string" },
|
||||
},
|
||||
records: [
|
||||
{ id: 1, code: "100104", account_type: "income" },
|
||||
{ id: 2, code: "100105", account_type: "income_other" },
|
||||
{ id: 3, code: "200104", account_type: "income" },
|
||||
],
|
||||
},
|
||||
},
|
||||
models: { ...getBasicData() },
|
||||
views: {
|
||||
"account.move.line,false,list": /* xml */ `
|
||||
<tree string="Move Lines">
|
||||
<list string="Move Lines">
|
||||
<field name="id"/>
|
||||
<field name="account_id"/>
|
||||
<field name="date"/>
|
||||
</tree>
|
||||
</list>
|
||||
`,
|
||||
"account.move.line,false,search": /* xml */ `<search/>`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function defineSpreadsheetAccountModels() {
|
||||
const SpreadsheetAccountModels = [AccountMoveLine, AccountAccount];
|
||||
Object.assign(SpreadsheetModels, SpreadsheetAccountModels);
|
||||
defineSpreadsheetModels();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
registry
|
||||
|
|
@ -10,10 +8,11 @@ registry
|
|||
.add("account.account/get_account_group", function (route, args, performRPC) {
|
||||
const accountTypes = args.args[0];
|
||||
const data = accountTypes.map((accountType) => {
|
||||
const records = this.mockSearchRead("account.account", [
|
||||
[["account_type", "=", accountType]],
|
||||
["code"],
|
||||
], {});
|
||||
const records = this.mockSearchRead(
|
||||
"account.account",
|
||||
[[["account_type", "=", accountType]], ["code"]],
|
||||
{}
|
||||
);
|
||||
return records.map((record) => record.code);
|
||||
});
|
||||
return data;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { setCellContent } from "@spreadsheet/../tests/helpers/commands";
|
||||
import { getCellValue } from "@spreadsheet/../tests/helpers/getters";
|
||||
import { createModelWithDataSource } from "@spreadsheet/../tests/helpers/model";
|
||||
import { waitForDataLoaded } from "@spreadsheet/helpers/model";
|
||||
import {
|
||||
defineSpreadsheetAccountModels,
|
||||
getAccountingData,
|
||||
} from "@spreadsheet_account/../tests/accounting_test_data";
|
||||
|
||||
describe.current.tags("headless");
|
||||
defineSpreadsheetAccountModels();
|
||||
|
||||
const serverData = getAccountingData();
|
||||
|
||||
test("get no account", async () => {
|
||||
const { model } = await createModelWithDataSource({ serverData });
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("test")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe("");
|
||||
});
|
||||
|
||||
test("get one account", async () => {
|
||||
const { model } = await createModelWithDataSource({ serverData });
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("income_other")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe("100105");
|
||||
});
|
||||
|
||||
test("get multiple accounts", async () => {
|
||||
const { model } = await createModelWithDataSource({ serverData });
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("income")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe("100104,200104");
|
||||
});
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import { stores } from "@odoo/o-spreadsheet";
|
||||
import { defineSpreadsheetModels } from "@spreadsheet/../tests/helpers/data";
|
||||
import { makeStore } from "@spreadsheet/../tests/helpers/stores";
|
||||
|
||||
describe.current.tags("headless");
|
||||
defineSpreadsheetModels();
|
||||
|
||||
const { CellComposerStore } = stores;
|
||||
|
||||
test("ODOO.ACCOUNT.GROUP type", async function () {
|
||||
const { store: composer } = await makeStore(CellComposerStore);
|
||||
|
||||
composer.startEdition("=ODOO.ACCOUNT.GROUP(");
|
||||
await animationFrame();
|
||||
const proposals = composer.autoCompleteProposals;
|
||||
expect(proposals.map((p) => p.text)).toEqual([
|
||||
'"asset_receivable"',
|
||||
'"asset_cash"',
|
||||
'"asset_current"',
|
||||
'"asset_non_current"',
|
||||
'"asset_prepayments"',
|
||||
'"asset_fixed"',
|
||||
'"liability_payable"',
|
||||
'"liability_credit_card"',
|
||||
'"liability_current"',
|
||||
'"liability_non_current"',
|
||||
'"equity"',
|
||||
'"equity_unaffected"',
|
||||
'"income"',
|
||||
'"income_other"',
|
||||
'"expense"',
|
||||
'"expense_depreciation"',
|
||||
'"expense_direct_cost"',
|
||||
'"off_balance"',
|
||||
]);
|
||||
composer.insertAutoCompleteValue(proposals[0].text);
|
||||
await animationFrame();
|
||||
expect(composer.currentContent).toBe('=ODOO.ACCOUNT.GROUP("asset_receivable"');
|
||||
expect(composer.isAutoCompleteDisplayed).toBe(false);
|
||||
});
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import { setCellContent } from "@spreadsheet/../tests/utils/commands";
|
||||
import {
|
||||
createModelWithDataSource,
|
||||
waitForDataSourcesLoaded,
|
||||
} from "@spreadsheet/../tests/utils/model";
|
||||
import { getCellValue } from "@spreadsheet/../tests/utils/getters";
|
||||
import { getAccountingData } from "../accounting_test_data";
|
||||
|
||||
let serverData;
|
||||
|
||||
function beforeEach() {
|
||||
serverData = getAccountingData();
|
||||
}
|
||||
|
||||
QUnit.module("spreadsheet_account > account groups", { beforeEach }, () => {
|
||||
QUnit.test("get no account", async (assert) => {
|
||||
const model = await createModelWithDataSource({ serverData });
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("test")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.equal(getCellValue(model, "A1"), "");
|
||||
});
|
||||
|
||||
QUnit.test("get one account", async (assert) => {
|
||||
const model = await createModelWithDataSource({ serverData });
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("income_other")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.equal(getCellValue(model, "A1"), "100105");
|
||||
});
|
||||
|
||||
QUnit.test("get multiple accounts", async (assert) => {
|
||||
const model = await createModelWithDataSource({ serverData });
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("income")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.equal(getCellValue(model, "A1"), "100104,200104");
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,422 @@
|
|||
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 { camelToSnakeObject } from "@spreadsheet/helpers/helpers";
|
||||
import {
|
||||
defineSpreadsheetAccountModels,
|
||||
getAccountingData,
|
||||
} from "@spreadsheet_account/../tests/accounting_test_data";
|
||||
import { parseAccountingDate } from "@spreadsheet_account/accounting_functions";
|
||||
import { makeServerError } from "@web/../tests/web_test_helpers";
|
||||
import { sprintf } from "@web/core/utils/strings";
|
||||
|
||||
import * as spreadsheet from "@odoo/o-spreadsheet";
|
||||
import { waitForDataLoaded } from "@spreadsheet/helpers/model";
|
||||
|
||||
describe.current.tags("headless");
|
||||
defineSpreadsheetAccountModels();
|
||||
|
||||
const { DEFAULT_LOCALE: locale } = spreadsheet.constants;
|
||||
|
||||
const serverData = getAccountingData();
|
||||
|
||||
test("Basic evaluation", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
expect.step("spreadsheet_fetch_debit_credit");
|
||||
return [{ debit: 42, credit: 16 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100", "2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", "2022")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe(16);
|
||||
expect(getCellValue(model, "A2")).toBe(42);
|
||||
expect(getCellValue(model, "A3")).toBe(26);
|
||||
expect.verifySteps(["spreadsheet_fetch_debit_credit"]);
|
||||
});
|
||||
|
||||
test("evaluation with reference to a month period", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
expect(args.args[0]).toEqual([
|
||||
{
|
||||
codes: ["100"],
|
||||
company_id: null,
|
||||
date_range: {
|
||||
month: 2,
|
||||
range_type: "month",
|
||||
year: 2022,
|
||||
},
|
||||
include_unposted: false,
|
||||
},
|
||||
]);
|
||||
expect.step("spreadsheet_fetch_debit_credit");
|
||||
return [{ debit: 42, credit: 16 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "B1", "02/2022");
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", B1)`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100", B1)`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", B1)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe(16);
|
||||
expect(getCellValue(model, "A2")).toBe(42);
|
||||
expect(getCellValue(model, "A3")).toBe(26);
|
||||
expect(getCellValue(model, "B1")).toBe(44593);
|
||||
expect.verifySteps(["spreadsheet_fetch_debit_credit"]);
|
||||
});
|
||||
|
||||
test("Functions are correctly formatted", async () => {
|
||||
const { model } = await createModelWithDataSource();
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100", "2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", "2022")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getEvaluatedCell(model, "A1").format).toBe("#,##0.00[$€]");
|
||||
expect(getEvaluatedCell(model, "A2").format).toBe("#,##0.00[$€]");
|
||||
expect(getEvaluatedCell(model, "A3").format).toBe("#,##0.00[$€]");
|
||||
});
|
||||
|
||||
test("Functions with a wrong company id is correctly in error", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_company_currency_for_spreadsheet") {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022", 0, 123456)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe("Currency not available for this company.");
|
||||
});
|
||||
|
||||
test("formula with invalid date", async () => {
|
||||
const { model } = await createModelWithDataSource();
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100",)`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100", 0)`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", -1)`);
|
||||
setCellContent(model, "A4", `=ODOO.BALANCE("100", "not a valid period")`);
|
||||
setCellContent(model, "A5", `=ODOO.BALANCE("100", 1900)`); // this should be ok
|
||||
setCellContent(model, "A6", `=ODOO.BALANCE("100", 1900, -1)`);
|
||||
setCellContent(model, "A7", `=ODOO.DEBIT("100", 1899)`);
|
||||
await waitForDataLoaded(model);
|
||||
const errorMessage = `'%s' is not a valid period. Supported formats are "21/12/2022", "Q1/2022", "12/2022", and "2022".`;
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe("0 is not a valid year.");
|
||||
expect(getEvaluatedCell(model, "A2").message).toBe("0 is not a valid year.");
|
||||
expect(getEvaluatedCell(model, "A3").message).toBe("-1 is not a valid year.");
|
||||
expect(getEvaluatedCell(model, "A4").message).toBe(sprintf(errorMessage, "not a valid period"));
|
||||
expect(getEvaluatedCell(model, "A5").value).toBe(0);
|
||||
expect(getEvaluatedCell(model, "A6").message).toBe("1899 is not a valid year.");
|
||||
expect(getEvaluatedCell(model, "A7").message).toBe("1899 is not a valid year.");
|
||||
});
|
||||
|
||||
test("Evaluation with multiple account codes", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
expect.step("spreadsheet_fetch_debit_credit");
|
||||
return [{ debit: 142, credit: 26 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100,200", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100,200", "2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100,200", "2022")`);
|
||||
|
||||
// with spaces
|
||||
setCellContent(model, "B1", `=ODOO.CREDIT("100 , 200", "2022")`);
|
||||
setCellContent(model, "B2", `=ODOO.DEBIT("100 , 200", "2022")`);
|
||||
setCellContent(model, "B3", `=ODOO.BALANCE("100 , 200", "2022")`);
|
||||
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe(26);
|
||||
expect(getCellValue(model, "A2")).toBe(142);
|
||||
expect(getCellValue(model, "A3")).toBe(116);
|
||||
|
||||
expect(getCellValue(model, "B1")).toBe(26);
|
||||
expect(getCellValue(model, "B2")).toBe(142);
|
||||
expect(getCellValue(model, "B3")).toBe(116);
|
||||
expect.verifySteps(["spreadsheet_fetch_debit_credit"]);
|
||||
});
|
||||
|
||||
test("Handle error evaluation", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
throw makeServerError({ description: "a nasty error" });
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022")`);
|
||||
await waitForDataLoaded(model);
|
||||
const cell = getEvaluatedCell(model, "A1");
|
||||
expect(cell.value).toBe("#ERROR");
|
||||
expect(cell.message).toBe("a nasty error");
|
||||
});
|
||||
|
||||
test("Server requests", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
const blobs = args.args[0];
|
||||
for (const blob of blobs) {
|
||||
expect.step(blob);
|
||||
}
|
||||
return new Array(blobs.length).fill({ credit: 0, debit: 0 });
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE("100", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.CREDIT("100", "01/2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.DEBIT("100","Q2/2022")`);
|
||||
setCellContent(model, "A4", `=ODOO.BALANCE("10", "2021")`);
|
||||
setCellContent(model, "A5", `=ODOO.CREDIT("10", "2022", -1)`); // same payload as A4: should only be called once
|
||||
setCellContent(model, "A6", `=ODOO.DEBIT("5", "2021", 0, 2)`);
|
||||
setCellContent(model, "A7", `=ODOO.DEBIT("5", "05/04/2021", 1)`);
|
||||
setCellContent(model, "A8", `=ODOO.BALANCE("5", "2022",,,FALSE)`);
|
||||
setCellContent(model, "A9", `=ODOO.BALANCE("100", "05/05/2022",,,TRUE)`);
|
||||
setCellContent(model, "A10", `=ODOO.BALANCE(33,2021,-2)`);
|
||||
await waitForDataLoaded(model);
|
||||
|
||||
expect.verifySteps([
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2022" }, locale),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "01/2022" }, locale),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "Q2/2022" }, locale),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2021" }, locale),
|
||||
codes: ["10"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2021" }, locale),
|
||||
codes: ["5"],
|
||||
companyId: 2,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "05/04/2022" }, locale),
|
||||
codes: ["5"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2022" }, locale),
|
||||
codes: ["5"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "05/05/2022" }, locale),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: true,
|
||||
}),
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2019" }, locale),
|
||||
codes: ["33"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("Server requests with multiple account codes", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
expect.step("spreadsheet_fetch_debit_credit");
|
||||
const blobs = args.args[0];
|
||||
for (const blob of blobs) {
|
||||
expect.step(blob);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE("100,200", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.CREDIT("100,200", "2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.DEBIT("100,200","2022")`);
|
||||
await waitForDataLoaded(model);
|
||||
|
||||
expect.verifySteps([
|
||||
"spreadsheet_fetch_debit_credit",
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2022" }, locale),
|
||||
codes: ["100", "200"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("account group formula as input to balance formula", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
serverData,
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
expect.step("spreadsheet_fetch_debit_credit");
|
||||
const blobs = args.args[0];
|
||||
for (const blob of blobs) {
|
||||
expect.step(blob);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("income")`);
|
||||
setCellContent(model, "A2", `=ODOO.BALANCE(A1, 2022)`);
|
||||
expect(getCellValue(model, "A1")).toBe("Loading...");
|
||||
expect(getCellValue(model, "A2")).toBe("Loading...");
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe("100104,200104");
|
||||
expect(getCellValue(model, "A2")).toBe(0);
|
||||
expect.verifySteps([
|
||||
"spreadsheet_fetch_debit_credit",
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2022" }, locale),
|
||||
codes: ["100104", "200104"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("two concurrent requests on different accounts", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
serverData,
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
expect.step("spreadsheet_fetch_debit_credit");
|
||||
const blobs = args.args[0];
|
||||
for (const blob of blobs) {
|
||||
expect.step(blob);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("income")`);
|
||||
setCellContent(model, "A2", `=ODOO.BALANCE(A1, 2022)`); // batched only when A1 resolves
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", 2022)`); // batched directly
|
||||
expect(getCellValue(model, "A1")).toBe("Loading...");
|
||||
expect(getCellValue(model, "A2")).toBe("Loading...");
|
||||
expect(getCellValue(model, "A3")).toBe("Loading...");
|
||||
// A lot happens within the next tick.
|
||||
// Because cells are evaluated given their order in the sheet,
|
||||
// A1's request is done first, meaning it's also resolved first, which add A2 to the next batch (synchronously)
|
||||
// Only then A3 is resolved. => A2 is batched while A3 is pending
|
||||
await waitForDataLoaded(model);
|
||||
expect(getCellValue(model, "A1")).toBe("100104,200104");
|
||||
expect(getCellValue(model, "A2")).toBe(0);
|
||||
expect(getCellValue(model, "A3")).toBe(0);
|
||||
expect.verifySteps([
|
||||
"spreadsheet_fetch_debit_credit",
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2022" }, locale),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
"spreadsheet_fetch_debit_credit",
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate({ value: "2022" }, locale),
|
||||
codes: ["100104", "200104"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("date with non-standard locale", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, { method, args }) {
|
||||
if (method === "spreadsheet_fetch_debit_credit") {
|
||||
expect.step("spreadsheet_fetch_debit_credit");
|
||||
expect(args).toEqual([
|
||||
[
|
||||
{
|
||||
codes: ["100"],
|
||||
company_id: null,
|
||||
date_range: {
|
||||
range_type: "day",
|
||||
year: 2002,
|
||||
month: 2,
|
||||
day: 1,
|
||||
},
|
||||
include_unposted: false,
|
||||
},
|
||||
],
|
||||
]);
|
||||
return [{ debit: 142, credit: 26 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
const myLocale = { ...locale, dateFormat: "d/mmm/yyyy" };
|
||||
model.dispatch("UPDATE_LOCALE", { locale: myLocale });
|
||||
setCellContent(model, "A1", "=DATE(2002, 2, 1)");
|
||||
setCellContent(model, "A2", "=ODOO.BALANCE(100, A1)");
|
||||
setCellContent(model, "A3", "=ODOO.CREDIT(100, A1)");
|
||||
setCellContent(model, "A4", "=ODOO.DEBIT(100, A1)");
|
||||
await waitForDataLoaded(model);
|
||||
expect(getEvaluatedCell(model, "A1").formattedValue).toBe("1/Feb/2002");
|
||||
expect(getCellValue(model, "A2")).toBe(116);
|
||||
expect(getCellValue(model, "A3")).toBe(26);
|
||||
expect(getCellValue(model, "A4")).toBe(142);
|
||||
expect.verifySteps(["spreadsheet_fetch_debit_credit"]);
|
||||
});
|
||||
|
||||
test("parseAccountingDate", () => {
|
||||
expect(parseAccountingDate({ value: "2022" }, locale)).toEqual({
|
||||
rangeType: "year",
|
||||
year: 2022,
|
||||
});
|
||||
expect(parseAccountingDate({ value: "11/10/2022" }, locale)).toEqual({
|
||||
rangeType: "day",
|
||||
year: 2022,
|
||||
month: 11,
|
||||
day: 10,
|
||||
});
|
||||
expect(parseAccountingDate({ value: "10/2022" }, locale)).toEqual({
|
||||
rangeType: "month",
|
||||
year: 2022,
|
||||
month: 10,
|
||||
});
|
||||
expect(parseAccountingDate({ value: "Q1/2022" }, locale)).toEqual({
|
||||
rangeType: "quarter",
|
||||
year: 2022,
|
||||
quarter: 1,
|
||||
});
|
||||
expect(parseAccountingDate({ value: "q4/2022" }, locale)).toEqual({
|
||||
rangeType: "quarter",
|
||||
year: 2022,
|
||||
quarter: 4,
|
||||
});
|
||||
// A number below 3000 is interpreted as a year.
|
||||
// It's interpreted as a regular spreadsheet date otherwise
|
||||
expect(parseAccountingDate({ value: "3005" }, locale)).toEqual({
|
||||
rangeType: "day",
|
||||
year: 1908,
|
||||
month: 3,
|
||||
day: 23,
|
||||
});
|
||||
});
|
||||
|
|
@ -1,381 +0,0 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import { setCellContent } from "@spreadsheet/../tests/utils/commands";
|
||||
import {
|
||||
createModelWithDataSource,
|
||||
waitForDataSourcesLoaded,
|
||||
} from "@spreadsheet/../tests/utils/model";
|
||||
import { parseAccountingDate } from "../../src/accounting_functions";
|
||||
import { getCellValue, getCell } from "@spreadsheet/../tests/utils/getters";
|
||||
import { getAccountingData } from "../accounting_test_data";
|
||||
import { camelToSnakeObject } from "@spreadsheet/helpers/helpers";
|
||||
import { sprintf } from "@web/core/utils/strings";
|
||||
|
||||
let serverData;
|
||||
|
||||
function beforeEach() {
|
||||
serverData = getAccountingData();
|
||||
}
|
||||
|
||||
QUnit.module("spreadsheet_account > Accounting", { beforeEach }, () => {
|
||||
QUnit.module("Formulas");
|
||||
QUnit.test("Basic evaluation", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
assert.step("spreadsheet_fetch_debit_credit");
|
||||
return [{ debit: 42, credit: 16 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100", "2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", "2022")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.equal(getCellValue(model, "A1"), 16);
|
||||
assert.equal(getCellValue(model, "A2"), 42);
|
||||
assert.equal(getCellValue(model, "A3"), 26);
|
||||
assert.verifySteps(["spreadsheet_fetch_debit_credit"]);
|
||||
});
|
||||
|
||||
QUnit.test("Functions are correctly formatted", async (assert) => {
|
||||
const model = await createModelWithDataSource();
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100", "2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", "2022")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.strictEqual(getCell(model, "A1").evaluated.format, "#,##0.00[$€]");
|
||||
assert.strictEqual(getCell(model, "A2").evaluated.format, "#,##0.00[$€]");
|
||||
assert.strictEqual(getCell(model, "A3").evaluated.format, "#,##0.00[$€]");
|
||||
});
|
||||
|
||||
QUnit.test("Functions with a wrong company id is correctly in error", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_company_currency_for_spreadsheet") {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022", 0, 123456)`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.strictEqual(
|
||||
getCell(model, "A1").evaluated.error.message,
|
||||
"Currency not available for this company."
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("formula with invalid date", async (assert) => {
|
||||
const model = await createModelWithDataSource();
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100",)`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100", 0)`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", -1)`);
|
||||
setCellContent(model, "A4", `=ODOO.BALANCE("100", "not a valid period")`);
|
||||
setCellContent(model, "A5", `=ODOO.BALANCE("100", 1900)`); // this should be ok
|
||||
setCellContent(model, "A6", `=ODOO.BALANCE("100", 1900, -1)`);
|
||||
setCellContent(model, "A7", `=ODOO.DEBIT("100", 1899)`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
const errorMessage = `'%s' is not a valid period. Supported formats are "21/12/2022", "Q1/2022", "12/2022", and "2022".`;
|
||||
assert.equal(getCell(model, "A1").evaluated.error.message, "0 is not a valid year.");
|
||||
assert.equal(getCell(model, "A2").evaluated.error.message, "0 is not a valid year.");
|
||||
assert.equal(getCell(model, "A3").evaluated.error.message, "-1 is not a valid year.");
|
||||
assert.equal(
|
||||
getCell(model, "A4").evaluated.error.message,
|
||||
sprintf(errorMessage, "not a valid period")
|
||||
);
|
||||
assert.equal(getCell(model, "A5").evaluated.value, 0);
|
||||
assert.equal(getCell(model, "A6").evaluated.error.message, "1899 is not a valid year.");
|
||||
assert.equal(getCell(model, "A7").evaluated.error.message, "1899 is not a valid year.");
|
||||
});
|
||||
|
||||
QUnit.test("Evaluation with multiple account codes", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
assert.step("spreadsheet_fetch_debit_credit");
|
||||
return [{ debit: 142, credit: 26 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100,200", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.DEBIT("100,200", "2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100,200", "2022")`);
|
||||
|
||||
// with spaces
|
||||
setCellContent(model, "B1", `=ODOO.CREDIT("100 , 200", "2022")`);
|
||||
setCellContent(model, "B2", `=ODOO.DEBIT("100 , 200", "2022")`);
|
||||
setCellContent(model, "B3", `=ODOO.BALANCE("100 , 200", "2022")`);
|
||||
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.equal(getCellValue(model, "A1"), 26);
|
||||
assert.equal(getCellValue(model, "A2"), 142);
|
||||
assert.equal(getCellValue(model, "A3"), 116);
|
||||
|
||||
assert.equal(getCellValue(model, "B1"), 26);
|
||||
assert.equal(getCellValue(model, "B2"), 142);
|
||||
assert.equal(getCellValue(model, "B3"), 116);
|
||||
assert.verifySteps(["spreadsheet_fetch_debit_credit"]);
|
||||
});
|
||||
|
||||
QUnit.test("Handle error evaluation", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
throw new Error("a nasty error");
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
const cell = getCell(model, "A1");
|
||||
assert.equal(cell.evaluated.value, "#ERROR");
|
||||
assert.equal(cell.evaluated.error.message, "a nasty error");
|
||||
});
|
||||
|
||||
QUnit.test("Server requests", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
const blobs = args.args[0];
|
||||
for (const blob of blobs) {
|
||||
assert.step(JSON.stringify(blob));
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE("100", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.CREDIT("100", "01/2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.DEBIT("100","Q2/2022")`);
|
||||
setCellContent(model, "A4", `=ODOO.BALANCE("10", "2021")`);
|
||||
setCellContent(model, "A5", `=ODOO.CREDIT("10", "2022", -1)`); // same payload as A4: should only be called once
|
||||
setCellContent(model, "A6", `=ODOO.DEBIT("5", "2021", 0, 2)`);
|
||||
setCellContent(model, "A7", `=ODOO.DEBIT("5", "05/04/2021", 1)`);
|
||||
setCellContent(model, "A8", `=ODOO.BALANCE("5", "2022",,,FALSE)`);
|
||||
setCellContent(model, "A9", `=ODOO.BALANCE("100", "05/05/2022",,,TRUE)`);
|
||||
setCellContent(model, "A10", `=ODOO.BALANCE(33,2021,-2)`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
|
||||
assert.verifySteps([
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2022"),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("01/2022"),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("Q2/2022"),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2021"),
|
||||
codes: ["10"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2021"),
|
||||
codes: ["5"],
|
||||
companyId: 2,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("05/04/2022"),
|
||||
codes: ["5"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2022"),
|
||||
codes: ["5"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("05/05/2022"),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: true,
|
||||
})
|
||||
),
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2019"),
|
||||
codes: ["33"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test("Server requests with multiple account codes", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
assert.step("spreadsheet_fetch_debit_credit");
|
||||
const blobs = args.args[0];
|
||||
for (const blob of blobs) {
|
||||
assert.step(JSON.stringify(blob));
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE("100,200", "2022")`);
|
||||
setCellContent(model, "A2", `=ODOO.CREDIT("100,200", "2022")`);
|
||||
setCellContent(model, "A3", `=ODOO.DEBIT("100,200","2022")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
|
||||
assert.verifySteps([
|
||||
"spreadsheet_fetch_debit_credit",
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2022"),
|
||||
codes: ["100", "200"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test("account group formula as input to balance formula", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
serverData,
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
assert.step("spreadsheet_fetch_debit_credit");
|
||||
const blobs = args.args[0];
|
||||
for (const blob of blobs) {
|
||||
assert.step(JSON.stringify(blob));
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("income")`);
|
||||
setCellContent(model, "A2", `=ODOO.BALANCE(A1, 2022)`);
|
||||
assert.equal(getCellValue(model, "A1"), "Loading...");
|
||||
assert.equal(getCellValue(model, "A2"), "Loading...");
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.equal(getCellValue(model, "A1"), "100104,200104");
|
||||
assert.equal(getCellValue(model, "A2"), 0);
|
||||
assert.verifySteps([
|
||||
"spreadsheet_fetch_debit_credit",
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2022"),
|
||||
codes: ["100104", "200104"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test("two concurrent requests on different accounts", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
serverData,
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_debit_credit") {
|
||||
assert.step("spreadsheet_fetch_debit_credit");
|
||||
const blobs = args.args[0];
|
||||
for (const blob of blobs) {
|
||||
assert.step(JSON.stringify(blob));
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.ACCOUNT.GROUP("income")`);
|
||||
setCellContent(model, "A2", `=ODOO.BALANCE(A1, 2022)`); // batched only when A1 resolves
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", 2022)`); // batched directly
|
||||
assert.equal(getCellValue(model, "A1"), "Loading...");
|
||||
assert.equal(getCellValue(model, "A2"), "Loading...");
|
||||
assert.equal(getCellValue(model, "A3"), "Loading...");
|
||||
// A lot happens within the next tick.
|
||||
// Because cells are evaluated given their order in the sheet,
|
||||
// A1's request is done first, meaning it's also resolved first, which add A2 to the next batch (synchronously)
|
||||
// Only then A3 is resolved. => A2 is batched while A3 is pending
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.equal(getCellValue(model, "A1"), "100104,200104");
|
||||
assert.equal(getCellValue(model, "A2"), 0);
|
||||
assert.equal(getCellValue(model, "A3"), 0);
|
||||
assert.verifySteps([
|
||||
"spreadsheet_fetch_debit_credit",
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2022"),
|
||||
codes: ["100"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
"spreadsheet_fetch_debit_credit",
|
||||
JSON.stringify(
|
||||
camelToSnakeObject({
|
||||
dateRange: parseAccountingDate("2022"),
|
||||
codes: ["100104", "200104"],
|
||||
companyId: null,
|
||||
includeUnposted: false,
|
||||
})
|
||||
),
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test("parseAccountingDate", (assert) => {
|
||||
assert.deepEqual(parseAccountingDate("2022"), {
|
||||
rangeType: "year",
|
||||
year: 2022,
|
||||
});
|
||||
assert.deepEqual(parseAccountingDate("11/10/2022"), {
|
||||
rangeType: "day",
|
||||
year: 2022,
|
||||
month: 11,
|
||||
day: 10,
|
||||
});
|
||||
assert.deepEqual(parseAccountingDate("10/2022"), {
|
||||
rangeType: "month",
|
||||
year: 2022,
|
||||
month: 10,
|
||||
});
|
||||
assert.deepEqual(parseAccountingDate("Q1/2022"), {
|
||||
rangeType: "quarter",
|
||||
year: 2022,
|
||||
quarter: 1,
|
||||
});
|
||||
assert.deepEqual(parseAccountingDate("q4/2022"), {
|
||||
rangeType: "quarter",
|
||||
year: 2022,
|
||||
quarter: 4,
|
||||
});
|
||||
// A number below 3000 is interpreted as a year.
|
||||
// It's interpreted as a regular spreadsheet date otherwise
|
||||
assert.deepEqual(parseAccountingDate("3005"), {
|
||||
rangeType: "day",
|
||||
year: 1908,
|
||||
month: 3,
|
||||
day: 23,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
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 { defineSpreadsheetAccountModels } from "@spreadsheet_account/../tests/accounting_test_data";
|
||||
import { waitForDataLoaded } from "@spreadsheet/helpers/model";
|
||||
|
||||
describe.current.tags("headless");
|
||||
defineSpreadsheetAccountModels();
|
||||
|
||||
test("Basic evaluation", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_balance_tag") {
|
||||
expect.step("spreadsheet_fetch_balance_tag");
|
||||
expect(args.args[0]).toEqual([
|
||||
{
|
||||
account_tag_ids: [10, 14],
|
||||
date_range: {
|
||||
range_type: "year",
|
||||
year: 2025,
|
||||
},
|
||||
company_id: 0,
|
||||
include_unposted: false,
|
||||
},
|
||||
]);
|
||||
return [{ balance: 100.0 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE.TAG("10, 14", 2025)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["spreadsheet_fetch_balance_tag"]);
|
||||
expect(getCellValue(model, "A1")).toBe(100.0);
|
||||
});
|
||||
|
||||
test("with wrong date format", async () => {
|
||||
const { model } = await createModelWithDataSource();
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE.TAG("10, 14", "This is not a valid date")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe(
|
||||
"'This is not a valid date' is not a valid period. Supported formats are \"21/12/2022\", \"Q1/2022\", \"12/2022\", and \"2022\"."
|
||||
);
|
||||
});
|
||||
|
||||
test("with no date", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_balance_tag") {
|
||||
expect.step("spreadsheet_fetch_balance_tag");
|
||||
expect(args.args[0]).toEqual([
|
||||
{
|
||||
account_tag_ids: [10, 14],
|
||||
date_range: {
|
||||
range_type: "year",
|
||||
year: new Date().getFullYear(),
|
||||
},
|
||||
company_id: 0,
|
||||
include_unposted: false,
|
||||
},
|
||||
]);
|
||||
return [{ balance: 100.0 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE.TAG("10, 14")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["spreadsheet_fetch_balance_tag"]);
|
||||
expect(getCellValue(model, "A1")).toBe(100.0);
|
||||
});
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
import { defineSpreadsheetModels } from "@spreadsheet/../tests/helpers/data";
|
||||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { setCellContent } from "@spreadsheet/../tests/helpers/commands";
|
||||
import { createModelWithDataSource } from "@spreadsheet/../tests/helpers/model";
|
||||
import { getEvaluatedCell } from "@spreadsheet/../tests/helpers/getters";
|
||||
import "@spreadsheet_account/index";
|
||||
|
||||
import * as spreadsheet from "@odoo/o-spreadsheet";
|
||||
import { waitForDataLoaded } from "@spreadsheet/helpers/model";
|
||||
|
||||
describe.current.tags("headless");
|
||||
defineSpreadsheetModels();
|
||||
|
||||
const { DEFAULT_LOCALE } = spreadsheet.constants;
|
||||
|
||||
test("Basic evaluation", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_fiscal_dates") {
|
||||
expect.step("get_fiscal_dates");
|
||||
expect(args.args).toEqual([
|
||||
[
|
||||
{
|
||||
date: "2020-11-11",
|
||||
company_id: null,
|
||||
},
|
||||
],
|
||||
]);
|
||||
return [{ start: "2020-01-01", end: "2020-12-31" }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("11/11/2020")`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["get_fiscal_dates"]);
|
||||
expect(getEvaluatedCell(model, "A1").formattedValue).toBe("1/1/2020");
|
||||
expect(getEvaluatedCell(model, "A2").formattedValue).toBe("12/31/2020");
|
||||
});
|
||||
|
||||
test("with a given company id", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_fiscal_dates") {
|
||||
expect.step("get_fiscal_dates");
|
||||
expect(args.args).toEqual([
|
||||
[
|
||||
{
|
||||
date: "2020-11-11",
|
||||
company_id: 1,
|
||||
},
|
||||
],
|
||||
]);
|
||||
return [{ start: "2020-01-01", end: "2020-12-31" }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("11/11/2020", 1)`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020", 1)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["get_fiscal_dates"]);
|
||||
expect(getEvaluatedCell(model, "A1").formattedValue).toBe("1/1/2020");
|
||||
expect(getEvaluatedCell(model, "A2").formattedValue).toBe("12/31/2020");
|
||||
});
|
||||
|
||||
test("with a wrong company id", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_fiscal_dates") {
|
||||
expect.step("get_fiscal_dates");
|
||||
expect(args.args).toEqual([
|
||||
[
|
||||
{
|
||||
date: "2020-11-11",
|
||||
company_id: 100,
|
||||
},
|
||||
],
|
||||
]);
|
||||
return [false];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("11/11/2020", 100)`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020", 100)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["get_fiscal_dates"]);
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe(
|
||||
"The company fiscal year could not be found."
|
||||
);
|
||||
expect(getEvaluatedCell(model, "A2").message).toBe(
|
||||
"The company fiscal year could not be found."
|
||||
);
|
||||
});
|
||||
|
||||
test("with wrong input arguments", async () => {
|
||||
const { model } = await createModelWithDataSource();
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("not a number")`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020", "not a number")`);
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe(
|
||||
"The function ODOO.FISCALYEAR.START expects a number value, but 'not a number' is a string, and cannot be coerced to a number."
|
||||
);
|
||||
expect(getEvaluatedCell(model, "A2").message).toBe(
|
||||
"The function ODOO.FISCALYEAR.END expects a number value, but 'not a number' is a string, and cannot be coerced to a number."
|
||||
);
|
||||
});
|
||||
|
||||
test("Date format is locale dependant", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_fiscal_dates") {
|
||||
return [{ start: "2020-01-01", end: "2020-12-31" }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("11/11/2020", 1)`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020", 1)`);
|
||||
await waitForDataLoaded(model);
|
||||
|
||||
expect(getEvaluatedCell(model, "A1").format).toBe("m/d/yyyy");
|
||||
expect(getEvaluatedCell(model, "A2").format).toBe("m/d/yyyy");
|
||||
|
||||
model.dispatch("UPDATE_LOCALE", { locale: { ...DEFAULT_LOCALE, dateFormat: "d/m/yyyy" } });
|
||||
|
||||
expect(getEvaluatedCell(model, "A1").format).toBe("d/m/yyyy");
|
||||
expect(getEvaluatedCell(model, "A2").format).toBe("d/m/yyyy");
|
||||
});
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
/** @odoo-module */
|
||||
import { setCellContent } from "@spreadsheet/../tests/utils/commands";
|
||||
import {
|
||||
createModelWithDataSource,
|
||||
waitForDataSourcesLoaded,
|
||||
} from "@spreadsheet/../tests/utils/model";
|
||||
import { getCell } from "@spreadsheet/../tests/utils/getters";
|
||||
import "@spreadsheet_account/index";
|
||||
|
||||
QUnit.module("spreadsheet_account > fiscal year", {}, () => {
|
||||
QUnit.test("Basic evaluation", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_fiscal_dates") {
|
||||
assert.step("get_fiscal_dates");
|
||||
assert.deepEqual(args.args, [
|
||||
[
|
||||
{
|
||||
date: "2020-11-11",
|
||||
company_id: null,
|
||||
},
|
||||
],
|
||||
]);
|
||||
return [{ start: "2020-01-01", end: "2020-12-31" }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("11/11/2020")`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020")`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.verifySteps(["get_fiscal_dates"]);
|
||||
assert.equal(getCell(model, "A1").formattedValue, "1/1/2020");
|
||||
assert.equal(getCell(model, "A2").formattedValue, "12/31/2020");
|
||||
});
|
||||
|
||||
QUnit.test("with a given company id", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_fiscal_dates") {
|
||||
assert.step("get_fiscal_dates");
|
||||
assert.deepEqual(args.args, [
|
||||
[
|
||||
{
|
||||
date: "2020-11-11",
|
||||
company_id: 1,
|
||||
},
|
||||
],
|
||||
]);
|
||||
return [{ start: "2020-01-01", end: "2020-12-31" }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("11/11/2020", 1)`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020", 1)`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.verifySteps(["get_fiscal_dates"]);
|
||||
assert.equal(getCell(model, "A1").formattedValue, "1/1/2020");
|
||||
assert.equal(getCell(model, "A2").formattedValue, "12/31/2020");
|
||||
});
|
||||
|
||||
QUnit.test("with a wrong company id", async (assert) => {
|
||||
const model = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "get_fiscal_dates") {
|
||||
assert.step("get_fiscal_dates");
|
||||
assert.deepEqual(args.args, [
|
||||
[
|
||||
{
|
||||
date: "2020-11-11",
|
||||
company_id: 100,
|
||||
},
|
||||
],
|
||||
]);
|
||||
return [false];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("11/11/2020", 100)`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020", 100)`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
assert.verifySteps(["get_fiscal_dates"]);
|
||||
assert.equal(
|
||||
getCell(model, "A1").evaluated.error.message,
|
||||
"The company fiscal year could not be found."
|
||||
);
|
||||
assert.equal(
|
||||
getCell(model, "A2").evaluated.error.message,
|
||||
"The company fiscal year could not be found."
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("with wrong input arguments", async (assert) => {
|
||||
const model = await createModelWithDataSource();
|
||||
setCellContent(model, "A1", `=ODOO.FISCALYEAR.START("not a number")`);
|
||||
setCellContent(model, "A2", `=ODOO.FISCALYEAR.END("11/11/2020", "not a number")`);
|
||||
assert.equal(
|
||||
getCell(model, "A1").evaluated.error.message,
|
||||
"The function ODOO.FISCALYEAR.START expects a number value, but 'not a number' is a string, and cannot be coerced to a number."
|
||||
);
|
||||
assert.equal(
|
||||
getCell(model, "A2").evaluated.error.message,
|
||||
"The function ODOO.FISCALYEAR.END expects a number value, but 'not a number' is a string, and cannot be coerced to a number."
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
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 { defineSpreadsheetAccountModels } from "@spreadsheet_account/../tests/accounting_test_data";
|
||||
import { waitForDataLoaded } from "@spreadsheet/helpers/model";
|
||||
|
||||
describe.current.tags("headless");
|
||||
defineSpreadsheetAccountModels();
|
||||
|
||||
test("Basic evaluation", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_partner_balance") {
|
||||
expect.step("spreadsheet_fetch_partner_balance");
|
||||
expect(args.args[0]).toEqual([
|
||||
{
|
||||
partner_ids: [14, 16],
|
||||
codes: ["112"],
|
||||
date_range: {
|
||||
range_type: "year",
|
||||
year: 2023,
|
||||
},
|
||||
company_id: 0,
|
||||
include_unposted: false,
|
||||
},
|
||||
]);
|
||||
return [{ balance: 26 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.PARTNER.BALANCE("14, 16", "112", 2023)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["spreadsheet_fetch_partner_balance"]);
|
||||
expect(getCellValue(model, "A1")).toBe(26);
|
||||
});
|
||||
|
||||
test("with wrong date format", async () => {
|
||||
const { model } = await createModelWithDataSource();
|
||||
setCellContent(
|
||||
model,
|
||||
"A1",
|
||||
`=ODOO.PARTNER.BALANCE("14, 16", "112", "This is not a valid date")`
|
||||
);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe(
|
||||
'\'This is not a valid date\' is not a valid period. Supported formats are "21/12/2022", "Q1/2022", "12/2022", and "2022".'
|
||||
);
|
||||
});
|
||||
|
||||
test("with no date", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_partner_balance") {
|
||||
expect.step("spreadsheet_fetch_partner_balance");
|
||||
expect(args.args[0]).toEqual([
|
||||
{
|
||||
partner_ids: [14, 16],
|
||||
codes: ["112"],
|
||||
date_range: {
|
||||
range_type: "year",
|
||||
year: new Date().getFullYear(),
|
||||
},
|
||||
company_id: 0,
|
||||
include_unposted: false,
|
||||
},
|
||||
]);
|
||||
return [{ balance: 26 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.PARTNER.BALANCE("14, 16", "112")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["spreadsheet_fetch_partner_balance"]);
|
||||
expect(getCellValue(model, "A1")).toBe(26);
|
||||
});
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
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 { defineSpreadsheetAccountModels } from "@spreadsheet_account/../tests/accounting_test_data";
|
||||
import { waitForDataLoaded } from "@spreadsheet/helpers/model";
|
||||
|
||||
describe.current.tags("headless");
|
||||
defineSpreadsheetAccountModels();
|
||||
|
||||
test("Basic evaluation", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_residual_amount") {
|
||||
expect.step("spreadsheet_fetch_residual_amount");
|
||||
expect(args.args[0]).toEqual([
|
||||
{
|
||||
codes: ["112"],
|
||||
date_range: {
|
||||
range_type: "year",
|
||||
year: 2023,
|
||||
},
|
||||
company_id: 0,
|
||||
include_unposted: false,
|
||||
},
|
||||
]);
|
||||
return [{ amount_residual: 111.11 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.RESIDUAL("112", 2023)`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["spreadsheet_fetch_residual_amount"]);
|
||||
expect(getCellValue(model, "A1")).toBe(111.11);
|
||||
});
|
||||
|
||||
test("with wrong date format", async () => {
|
||||
const { model } = await createModelWithDataSource();
|
||||
setCellContent(model, "A1", `=ODOO.RESIDUAL("112", "This is not a valid date")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect(getEvaluatedCell(model, "A1").message).toBe(
|
||||
'\'This is not a valid date\' is not a valid period. Supported formats are "21/12/2022", "Q1/2022", "12/2022", and "2022".'
|
||||
);
|
||||
});
|
||||
|
||||
test("with no date", async () => {
|
||||
const { model } = await createModelWithDataSource({
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_fetch_residual_amount") {
|
||||
expect.step("spreadsheet_fetch_residual_amount");
|
||||
expect(args.args[0]).toEqual([
|
||||
{
|
||||
codes: ["112"],
|
||||
date_range: {
|
||||
range_type: "year",
|
||||
year: new Date().getFullYear(),
|
||||
},
|
||||
company_id: 0,
|
||||
include_unposted: false,
|
||||
},
|
||||
]);
|
||||
return [{ amount_residual: 111.11 }];
|
||||
}
|
||||
},
|
||||
});
|
||||
setCellContent(model, "A1", `=ODOO.RESIDUAL("112")`);
|
||||
await waitForDataLoaded(model);
|
||||
expect.verifySteps(["spreadsheet_fetch_residual_amount"]);
|
||||
expect(getCellValue(model, "A1")).toBe(111.11);
|
||||
});
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { registries, constants } from "@odoo/o-spreadsheet";
|
||||
import { selectCell, setCellContent } from "@spreadsheet/../tests/helpers/commands";
|
||||
import { createModelWithDataSource } from "@spreadsheet/../tests/helpers/model";
|
||||
import { doMenuAction } from "@spreadsheet/../tests/helpers/ui";
|
||||
import { waitForDataLoaded } from "@spreadsheet/helpers/model";
|
||||
import {
|
||||
defineSpreadsheetAccountModels,
|
||||
getAccountingData,
|
||||
} from "@spreadsheet_account/../tests/accounting_test_data";
|
||||
import { mockService } from "@web/../tests/web_test_helpers";
|
||||
|
||||
describe.current.tags("headless");
|
||||
defineSpreadsheetAccountModels();
|
||||
|
||||
const { cellMenuRegistry } = registries;
|
||||
const { DEFAULT_LOCALE } = constants;
|
||||
|
||||
const serverData = getAccountingData();
|
||||
|
||||
test("Create drill down domain", async () => {
|
||||
const drillDownAction = {
|
||||
type: "ir.actions.act_window",
|
||||
res_model: "account.move.line",
|
||||
view_mode: "list",
|
||||
views: [[false, "list"]],
|
||||
target: "current",
|
||||
domain: [["account_id", "in", [1, 2]]],
|
||||
name: "my awesome action",
|
||||
};
|
||||
const fakeActionService = {
|
||||
doAction: async (action, options) => {
|
||||
expect.step("drill down action");
|
||||
expect(action).toEqual(drillDownAction);
|
||||
expect(options).toEqual({ newWindow: undefined });
|
||||
return true;
|
||||
},
|
||||
};
|
||||
mockService("action", fakeActionService);
|
||||
|
||||
const { model } = await createModelWithDataSource({
|
||||
serverData,
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_move_line_action") {
|
||||
expect(args.args).toEqual([
|
||||
{
|
||||
codes: ["100"],
|
||||
company_id: null,
|
||||
include_unposted: false,
|
||||
date_range: {
|
||||
range_type: "year",
|
||||
year: 2020,
|
||||
},
|
||||
},
|
||||
]);
|
||||
return drillDownAction;
|
||||
}
|
||||
},
|
||||
});
|
||||
const env = model.config.custom.env;
|
||||
env.model = model;
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE("100", 2020)`);
|
||||
setCellContent(model, "A2", `=ODOO.BALANCE("100", 0)`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", 2020, , , FALSE)`);
|
||||
setCellContent(model, "A4", `=ODOO.BALANCE("100", 2020, , , )`);
|
||||
// Does not affect non formula cells
|
||||
setCellContent(model, "A5", `5`);
|
||||
await waitForDataLoaded(model);
|
||||
selectCell(model, "A1");
|
||||
const root = cellMenuRegistry
|
||||
.getMenuItems()
|
||||
.find((item) => item.id === "move_lines_see_records");
|
||||
expect(root.isVisible(env)).toBe(true);
|
||||
await root.execute(env);
|
||||
expect.verifySteps(["drill down action"]);
|
||||
selectCell(model, "A2");
|
||||
expect(root.isVisible(env)).toBe(false);
|
||||
selectCell(model, "A3");
|
||||
expect(root.isVisible(env)).toBe(true);
|
||||
await root.execute(env);
|
||||
expect.verifySteps(["drill down action"]);
|
||||
selectCell(model, "A4");
|
||||
expect(root.isVisible(env)).toBe(true);
|
||||
await root.execute(env);
|
||||
expect.verifySteps(["drill down action"]);
|
||||
selectCell(model, "A5");
|
||||
expect(root.isVisible(env)).toBe(false);
|
||||
});
|
||||
|
||||
test("Create drill down domain when month date is a reference", async () => {
|
||||
mockService("action", { doAction: () => {} });
|
||||
const { model } = await createModelWithDataSource({
|
||||
serverData,
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_move_line_action") {
|
||||
expect.step("spreadsheet_move_line_action");
|
||||
expect(args.args).toEqual([
|
||||
{
|
||||
codes: ["100"],
|
||||
company_id: null,
|
||||
include_unposted: false,
|
||||
date_range: {
|
||||
month: 2,
|
||||
range_type: "month",
|
||||
year: 2024,
|
||||
},
|
||||
},
|
||||
]);
|
||||
return {};
|
||||
}
|
||||
},
|
||||
});
|
||||
const env = model.config.custom.env;
|
||||
env.model = model;
|
||||
setCellContent(model, "A1", "02/2024");
|
||||
setCellContent(model, "A2", '=ODOO.BALANCE("100", A1)');
|
||||
await waitForDataLoaded(model);
|
||||
selectCell(model, "A2");
|
||||
await doMenuAction(cellMenuRegistry, ["move_lines_see_records"], env);
|
||||
expect.verifySteps(["spreadsheet_move_line_action"]);
|
||||
});
|
||||
|
||||
test("Create drill down domain when date uses a non-standard locale", async () => {
|
||||
mockService("action", { doAction: () => {} });
|
||||
const { model } = await createModelWithDataSource({
|
||||
serverData,
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_move_line_action") {
|
||||
expect.step("spreadsheet_move_line_action");
|
||||
expect(args.args).toEqual([
|
||||
{
|
||||
codes: ["100"],
|
||||
company_id: null,
|
||||
include_unposted: false,
|
||||
date_range: {
|
||||
range_type: "day",
|
||||
year: 2002,
|
||||
month: 2,
|
||||
day: 1,
|
||||
},
|
||||
},
|
||||
]);
|
||||
return {};
|
||||
}
|
||||
},
|
||||
});
|
||||
const env = model.config.custom.env;
|
||||
env.model = model;
|
||||
const myLocale = { ...DEFAULT_LOCALE, dateFormat: "d/mmm/yyyy" };
|
||||
model.dispatch("UPDATE_LOCALE", { locale: myLocale });
|
||||
setCellContent(model, "A1", '=ODOO.BALANCE("100", DATE(2002, 2, 1))');
|
||||
await waitForDataLoaded(model);
|
||||
await doMenuAction(cellMenuRegistry, ["move_lines_see_records"], env);
|
||||
expect.verifySteps(["spreadsheet_move_line_action"]);
|
||||
});
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import { selectCell, setCellContent } from "@spreadsheet/../tests/utils/commands";
|
||||
import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
|
||||
import { getAccountingData } from "../accounting_test_data";
|
||||
import {
|
||||
createModelWithDataSource,
|
||||
waitForDataSourcesLoaded,
|
||||
} from "@spreadsheet/../tests/utils/model";
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
const { cellMenuRegistry } = spreadsheet.registries;
|
||||
|
||||
let serverData;
|
||||
|
||||
function beforeEach() {
|
||||
serverData = getAccountingData();
|
||||
}
|
||||
|
||||
QUnit.module("spreadsheet_account > Accounting Drill down", { beforeEach }, () => {
|
||||
QUnit.test("Create drill down domain", async (assert) => {
|
||||
const drillDownAction = {
|
||||
type: "ir.actions.act_window",
|
||||
res_model: "account.move.line",
|
||||
view_mode: "list",
|
||||
views: [[false, "list"]],
|
||||
target: "current",
|
||||
domain: [["account_id", "in", [1, 2]]],
|
||||
name: "my awesome action",
|
||||
};
|
||||
const fakeActionService = {
|
||||
name: "action",
|
||||
start() {
|
||||
return {
|
||||
async doAction(action, options) {
|
||||
assert.step("drill down action");
|
||||
assert.deepEqual(action, drillDownAction);
|
||||
assert.equal(options, undefined);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
registry.category("services").add("action", fakeActionService, { force: true });
|
||||
|
||||
const model = await createModelWithDataSource({
|
||||
serverData,
|
||||
mockRPC: async function (route, args) {
|
||||
if (args.method === "spreadsheet_move_line_action") {
|
||||
assert.deepEqual(args.args, [
|
||||
{
|
||||
codes: ["100"],
|
||||
company_id: null,
|
||||
include_unposted: false,
|
||||
date_range: {
|
||||
range_type: "year",
|
||||
year: 2020,
|
||||
},
|
||||
},
|
||||
]);
|
||||
return drillDownAction;
|
||||
}
|
||||
},
|
||||
});
|
||||
const env = model.config.evalContext.env;
|
||||
env.model = model;
|
||||
setCellContent(model, "A1", `=ODOO.BALANCE("100", 2020)`);
|
||||
setCellContent(model, "A2", `=ODOO.BALANCE("100", 0)`);
|
||||
setCellContent(model, "A3", `=ODOO.BALANCE("100", 2020, , , FALSE)`);
|
||||
setCellContent(model, "A4", `=ODOO.BALANCE("100", 2020, , , )`);
|
||||
await waitForDataSourcesLoaded(model);
|
||||
selectCell(model, "A1");
|
||||
const root = cellMenuRegistry.getAll().find((item) => item.id === "move_lines_see_records");
|
||||
assert.equal(root.isVisible(env), true);
|
||||
await root.action(env);
|
||||
assert.verifySteps(["drill down action"]);
|
||||
selectCell(model, "A2");
|
||||
assert.equal(root.isVisible(env), false);
|
||||
selectCell(model, "A3");
|
||||
assert.equal(root.isVisible(env), true);
|
||||
await root.action(env);
|
||||
assert.verifySteps(["drill down action"]);
|
||||
selectCell(model, "A4");
|
||||
assert.equal(root.isVisible(env), true);
|
||||
await root.action(env);
|
||||
assert.verifySteps(["drill down action"]);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue