account
This commit is contained in:
@@ -0,0 +1,356 @@
|
||||
import { expect, resize, test } from "@odoo/hoot";
|
||||
import { advanceTime } from "@odoo/hoot-mock";
|
||||
|
||||
import {
|
||||
click,
|
||||
contains,
|
||||
mailModels,
|
||||
} from "@mail/../tests/mail_test_helpers";
|
||||
|
||||
import {
|
||||
defineModels,
|
||||
getService,
|
||||
mountWithCleanup,
|
||||
onRpc,
|
||||
patchWithCleanup,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
import { WebClient } from "@web/webclient/webclient";
|
||||
import { download } from "@web/core/network/download";
|
||||
|
||||
// Due to dependency with mail module, we have to define their models for our tests.
|
||||
defineModels(mailModels);
|
||||
|
||||
const getOptionMockResponse = {
|
||||
"companies": [],
|
||||
"variants_source_id": 14,
|
||||
"has_inactive_variants": false,
|
||||
"available_variants": [],
|
||||
"selected_variant_id": 14,
|
||||
"sections_source_id": 14,
|
||||
"sections": [],
|
||||
"has_inactive_sections": false,
|
||||
"report_id": 14,
|
||||
"date": {
|
||||
"string": "2025",
|
||||
"period_type": "year",
|
||||
"date_from": "2025-01-01",
|
||||
"date_to": "2025-12-31",
|
||||
"default_opening_date": "this_year"
|
||||
},
|
||||
"filter_date": {
|
||||
"filters": {
|
||||
"month": {
|
||||
"key": "month",
|
||||
"start_day": 1,
|
||||
"start_month": 1,
|
||||
"months_per_period": 1,
|
||||
},
|
||||
"quarter": {
|
||||
"key": "quarter",
|
||||
"start_day": 1,
|
||||
"start_month": 1,
|
||||
"months_per_period": 3,
|
||||
},
|
||||
"year": {
|
||||
"key": "year",
|
||||
"start_day": 1,
|
||||
"start_month": 1,
|
||||
"months_per_period": 12,
|
||||
},
|
||||
}
|
||||
},
|
||||
"available_horizontal_groups": [],
|
||||
"selected_horizontal_group_id": null,
|
||||
"account_type": [],
|
||||
"all_entries": false,
|
||||
"aml_ir_filters": [],
|
||||
"buttons": [],
|
||||
"export_mode": null,
|
||||
"hide_0_lines": false,
|
||||
"multi_currency": false,
|
||||
"partner": false,
|
||||
"partner_categories": [],
|
||||
"selected_partner_ids": [],
|
||||
"partner_ids": [],
|
||||
"selected_partner_categories": [],
|
||||
"unreconciled": false,
|
||||
"rounding_unit": "decimals",
|
||||
"rounding_unit_names": {
|
||||
"decimals": ".$",
|
||||
},
|
||||
"search_bar": false,
|
||||
"unfold_all": false,
|
||||
"unfolded_lines": [],
|
||||
"column_headers": [],
|
||||
"columns": [
|
||||
{
|
||||
"name": "A column",
|
||||
"column_group_index": 0,
|
||||
"expression_label": "a_column",
|
||||
"sortable": false,
|
||||
"figure_type": "string",
|
||||
"blank_if_zero": false,
|
||||
"style": ""
|
||||
},
|
||||
],
|
||||
"column_groups": {0: {"forced_options": {}, "forced_domain": []}
|
||||
},
|
||||
"custom_display_config": {},
|
||||
"filters": {},
|
||||
"user_groups": {},
|
||||
};
|
||||
|
||||
const getReportInformationMockResponse = {
|
||||
"caret_options": {},
|
||||
"column_headers_render_data": {"level_colspan": [1], "level_repetitions": [1], "custom_subheaders": []},
|
||||
"column_groups_totals": {0: {}},
|
||||
"context": {},
|
||||
"annotations": {},
|
||||
"lines": [
|
||||
{
|
||||
"id": "~account.report~14|~res.partner~1",
|
||||
"name": "A partner",
|
||||
"columns": [
|
||||
{
|
||||
"auditable": false,
|
||||
"blank_if_zero": false,
|
||||
"column_group_index": 0,
|
||||
"currency": null,
|
||||
"currency_symbol": "",
|
||||
"digits": 1,
|
||||
"expression_label": "a_column",
|
||||
"figure_type": "string",
|
||||
"green_on_positive": false,
|
||||
"has_sublines": false,
|
||||
"is_zero": false,
|
||||
"name": "",
|
||||
"no_format": null,
|
||||
"report_line_id": null,
|
||||
"sortable": false
|
||||
},
|
||||
],
|
||||
"level": 1,
|
||||
"trust": "normal",
|
||||
"unfoldable": true,
|
||||
"unfolded": false,
|
||||
"expand_function": "some_expand_function"
|
||||
},
|
||||
],
|
||||
"warnings": {},
|
||||
"report": { "company_name": "YourCompany", "company_country_code": "US", "company_currency_symbol": "$", "name": "A report", "root_report_id": "account.report()"}
|
||||
};
|
||||
|
||||
const getExpandedLinesMockResponse = [
|
||||
{
|
||||
"id": "~account.report~14|~res.partner~1|0~account.move.line~1",
|
||||
"parent_id": "~account.report~14|~res.partner~1",
|
||||
"name": "first move line",
|
||||
"columns": [
|
||||
{
|
||||
"auditable": false,
|
||||
"blank_if_zero": false,
|
||||
"column_group_index": 0,
|
||||
"currency": null,
|
||||
"currency_symbol": "$",
|
||||
"digits": 1,
|
||||
"expression_label": "a_column",
|
||||
"figure_type": "string",
|
||||
"green_on_positive": false,
|
||||
"has_sublines": false,
|
||||
"is_zero": false,
|
||||
"name": "first value",
|
||||
"no_format": "first value",
|
||||
"report_line_id": null,
|
||||
"sortable": false
|
||||
},
|
||||
],
|
||||
"level": 3
|
||||
},
|
||||
{
|
||||
"id": "~account.report~14|~res.partner~1|0~account.move.line~11",
|
||||
"parent_id": "~account.report~14|~res.partner~1",
|
||||
"name": "second move line",
|
||||
"columns": [
|
||||
{
|
||||
"auditable": false,
|
||||
"blank_if_zero": false,
|
||||
"column_group_index": 0,
|
||||
"currency": null,
|
||||
"currency_symbol": "$",
|
||||
"digits": 1,
|
||||
"expression_label": "a_column",
|
||||
"figure_type": "string",
|
||||
"green_on_positive": false,
|
||||
"has_sublines": false,
|
||||
"is_zero": false,
|
||||
"name": "second value",
|
||||
"no_format": "second value",
|
||||
"report_line_id": null,
|
||||
"sortable": false
|
||||
},
|
||||
],
|
||||
"level": 3
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
test("Test unfold loaded line", async() => {
|
||||
async function mockRpcReport({ method, model }) {
|
||||
if (model === 'account.report') {
|
||||
if (method === 'get_options') {
|
||||
return getOptionMockResponse;
|
||||
}
|
||||
if (method === 'get_report_information') {
|
||||
return getReportInformationMockResponse;
|
||||
}
|
||||
if (method === 'get_expanded_lines') {
|
||||
mockRpcReport.getExpandedLineCallCount = (mockRpcReport.getExpandedLineCallCount || 0) + 1;
|
||||
return getExpandedLinesMockResponse;
|
||||
}
|
||||
if (method === "get_annotations_from_client") {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
onRpc(mockRpcReport);
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
await getService("action").doAction({
|
||||
type: "ir.actions.client",
|
||||
tag: "account_report",
|
||||
params: {},
|
||||
})
|
||||
|
||||
await click(".btn_foldable");
|
||||
await contains(".unfolded", { count: 1 });
|
||||
await click(".btn_foldable");
|
||||
await contains(".unfolded", { count: 0 });
|
||||
await click(".btn_foldable");
|
||||
await contains(".unfolded", { count: 1 });
|
||||
|
||||
// Only one call to get_expanded_lines, as we unfolded/folded/unfolded the same line
|
||||
expect(mockRpcReport.getExpandedLineCallCount).toEqual(1);
|
||||
});
|
||||
|
||||
test("can execute account report download actions", async function () {
|
||||
patchWithCleanup(download, {
|
||||
_download: async ({ url, data }) => {
|
||||
expect.step(url);
|
||||
expect(data).toEqual(
|
||||
{
|
||||
model: "some_model",
|
||||
options: {
|
||||
someOption: true,
|
||||
},
|
||||
output_format: "pdf",
|
||||
},
|
||||
{ message: "should give the correct data" }
|
||||
);
|
||||
return Promise.resolve();
|
||||
},
|
||||
});
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
await getService("action").doAction({
|
||||
data: {
|
||||
model: "some_model",
|
||||
options: {
|
||||
someOption: true,
|
||||
},
|
||||
output_format: "pdf",
|
||||
},
|
||||
type: "ir_actions_account_report_download",
|
||||
});
|
||||
|
||||
expect.verifySteps(["/account_reports"]);
|
||||
});
|
||||
|
||||
test("make sure the virtual grid is somewhat working", async () => {
|
||||
async function mockRpcReport({ method, model }) {
|
||||
if (model === 'account.report') {
|
||||
if (method === 'get_options') {
|
||||
return getOptionMockResponse;
|
||||
}
|
||||
if (method === 'get_report_information') {
|
||||
return getReportInformationMockResponse;
|
||||
}
|
||||
if (method === 'get_expanded_lines') {
|
||||
// duplicate the lines 100 times to get 200 lines so the scrolling has some effect.
|
||||
return getExpandedLinesMockResponse.flatMap(line => {
|
||||
const copies = [];
|
||||
for (let i = 0; i < 100; i++) {
|
||||
copies.push({
|
||||
...line,
|
||||
id: line.id + "_" + i,
|
||||
name: line.name + " " + i,
|
||||
});
|
||||
}
|
||||
return copies;
|
||||
});
|
||||
}
|
||||
if (method === "get_annotations_from_client") {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
onRpc(mockRpcReport);
|
||||
|
||||
await mountWithCleanup(WebClient);
|
||||
await getService("action").doAction({
|
||||
type: "ir.actions.client",
|
||||
tag: "account_report",
|
||||
params: {},
|
||||
});
|
||||
|
||||
await click(".btn_foldable");
|
||||
await contains(".unfolded", { count: 1 });
|
||||
expect(document.querySelectorAll('tr[data-id="line"]').length).toBeLessThan(100, { message: "should not have rendered all the lines of the report" });
|
||||
expect(':nth-child(1 of tr:not(.o_hidden)[data-id="line"])').toHaveText("A partner");
|
||||
await contains(':nth-child(2 of tr:not(.o_hidden)[data-id="line"])');
|
||||
|
||||
// prevent the window size to be the height of the table.
|
||||
await resize({ height: 800 });
|
||||
// wait for the resize event to fire, and the virtual grid to recompute (500 should be enough as it takes ~50ms in reality)
|
||||
await advanceTime(500, { animationFrame: true });
|
||||
|
||||
let scrollContainer = document.querySelector(".o_account_report_scroll_container");
|
||||
if ((await getService("ui")).isSmall) {
|
||||
// On mobile, the scroll container changes since the layout change.
|
||||
scrollContainer = document.querySelector(".account_report");
|
||||
}
|
||||
const tbody = scrollContainer.querySelector("tbody");
|
||||
const topSpacer = tbody.querySelector("tr:first-child");
|
||||
const bottomSpacer = tbody.querySelector("tr:last-child");
|
||||
const getSpacerHeight = (el) => parseFloat(el.style.height) || 0;
|
||||
|
||||
expect(getSpacerHeight(topSpacer)).toBe(0, { message: "top spacer should be 0 at scroll top" });
|
||||
expect(getSpacerHeight(bottomSpacer)).toBeGreaterThan(0, { message: "bottom spacer should account for unrendered lines below" });
|
||||
|
||||
scrollContainer.scrollTop = document.querySelector(':nth-last-child(1 of tr:not(.o_hidden)[data-id="line"])').offsetTop;
|
||||
await advanceTime(500, { animationFrame: true });
|
||||
expect(':nth-child(1 of tr:not(.o_hidden)[data-id="line"])').not.toHaveText("A partner");
|
||||
expect(':nth-last-child(1 of tr:not(.o_hidden)[data-id="line"])').not.toHaveText("second move line 99 second value");
|
||||
|
||||
scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
||||
await advanceTime(500, { animationFrame: true });
|
||||
expect(':nth-last-child(1 of tr:not(.o_hidden)[data-id="line"])').toHaveText("second move line 99 second value");
|
||||
|
||||
expect(getSpacerHeight(topSpacer)).toBeGreaterThan(0, { message: "top spacer should account for unrendered lines above" });
|
||||
expect(getSpacerHeight(bottomSpacer)).toBe(0, { message: "bottom spacer should be 0 at scroll bottom" });
|
||||
|
||||
// Record the DOM rows at the bottom to verify they are reused (not recreated) when scrolling back up.
|
||||
const rowsAtBottom = [...document.querySelectorAll('tr[data-id="line"]')];
|
||||
|
||||
scrollContainer.scrollTop = 0;
|
||||
await advanceTime(500, { animationFrame: true });
|
||||
expect(':nth-child(1 of tr:not(.o_hidden)[data-id="line"])').toHaveText("A partner");
|
||||
expect(':nth-last-child(1 of tr:not(.o_hidden)[data-id="line"])').not.toHaveText("second move line 99 second value");
|
||||
|
||||
// The virtual grid reuses existing DOM rows rather than destroying and recreating them.
|
||||
const rowsAtTop = [...document.querySelectorAll('tr[data-id="line"]')];
|
||||
expect(rowsAtTop.length).toBe(rowsAtBottom.length, { message: "scrolling should not create or destroy DOM rows" });
|
||||
const rowsAtTopSet = new Set(rowsAtTop);
|
||||
for (const row of rowsAtBottom) {
|
||||
expect(rowsAtTopSet.has(row)).toBe(true, { message: "every DOM row from the bottom should still be present at the top" });
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,650 @@
|
||||
import { expect, test } from "@odoo/hoot";
|
||||
import { waitFor } from "@odoo/hoot-dom";
|
||||
import {
|
||||
contains,
|
||||
defineModels,
|
||||
fields,
|
||||
models,
|
||||
mountView,
|
||||
onRpc,
|
||||
sortableDrag,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
|
||||
|
||||
class Report extends models.Model {
|
||||
_name = "report";
|
||||
|
||||
line_ids = fields.One2many({ relation: "report_lines", relation_field: "report_id" });
|
||||
|
||||
_records = [
|
||||
{
|
||||
id: 1,
|
||||
line_ids: [1, 2, 3, 4, 5],
|
||||
},
|
||||
];
|
||||
_views = {
|
||||
form: /* xml */ `
|
||||
<form>
|
||||
<field class="w-100" name="line_ids" widget="account_report_lines_list_x2many">
|
||||
<list>
|
||||
<field name="id" column_invisible="1"/>
|
||||
<field name="sequence" column_invisible="1"/>
|
||||
<field name="parent_id" column_invisible="1"/>
|
||||
<field name="hierarchy_level" column_invisible="1"/>
|
||||
<field name="name"/>
|
||||
<field name="code" optional="hide"/>
|
||||
<field name="foldability" optional="hide"/>
|
||||
</list>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
};
|
||||
}
|
||||
class ReportLines extends models.Model {
|
||||
_name = "report_lines";
|
||||
|
||||
report_id = fields.Many2one({ relation: "report", string: "Report ID" });
|
||||
sequence = fields.Integer();
|
||||
parent_id = fields.Many2one({ relation: "report_lines", relation_field: "id" });
|
||||
hierarchy_level = fields.Integer();
|
||||
name = fields.Char();
|
||||
code = fields.Char();
|
||||
foldability = fields.Selection({
|
||||
selection: [
|
||||
["always_unfolded", "Always unfolded"],
|
||||
["foldable", "Foldable"],
|
||||
["never_unfolded", "Never unfolded"],
|
||||
],
|
||||
});
|
||||
|
||||
_records = [
|
||||
{
|
||||
id: 1,
|
||||
parent_id: false,
|
||||
hierarchy_level: 1,
|
||||
name: "Root without children",
|
||||
code: "RWOC",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
parent_id: false,
|
||||
hierarchy_level: 0,
|
||||
name: "Root with children",
|
||||
code: "RC",
|
||||
foldability: "always_unfolded",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
parent_id: 2,
|
||||
hierarchy_level: 3,
|
||||
name: "Child #1",
|
||||
code: "C1",
|
||||
foldability: "always_unfolded",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
parent_id: 3,
|
||||
hierarchy_level: 5,
|
||||
name: "Grandchild",
|
||||
code: "GC",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
parent_id: 2,
|
||||
hierarchy_level: 3,
|
||||
name: "Child #2",
|
||||
code: "C2",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
];
|
||||
|
||||
_views = {
|
||||
form: `<form><field name="name"/></form>`,
|
||||
};
|
||||
}
|
||||
defineModels([Report, ReportLines]);
|
||||
defineMailModels();
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Structure
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
test("have correct descendants count", async () => {
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
expect(
|
||||
".account_report_lines_list_x2many li[data-descendants_count='0'] span:contains('Root without children')"
|
||||
).toHaveCount(1);
|
||||
expect(
|
||||
".account_report_lines_list_x2many li[data-descendants_count='3'] span:contains('Root with children')"
|
||||
).toHaveCount(1);
|
||||
expect(
|
||||
".account_report_lines_list_x2many li[data-descendants_count='1'] span:contains('Child #1')"
|
||||
).toHaveCount(1);
|
||||
expect(
|
||||
".account_report_lines_list_x2many li[data-descendants_count='0'] span:contains('Grandchild')"
|
||||
).toHaveCount(1);
|
||||
expect(
|
||||
".account_report_lines_list_x2many li[data-descendants_count='0'] span:contains('Child #2')"
|
||||
).toHaveCount(1);
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Create
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
test("can create a line", async () => {
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
await contains(".account_report_lines_list_x2many li:last-of-type a").click();
|
||||
await waitFor(".o_dialog");
|
||||
|
||||
await contains("div[name='name'] input").edit("Created line");
|
||||
await contains(".o_dialog .o_form_button_save").click();
|
||||
|
||||
await waitFor(".account_report_lines_list_x2many li span:contains('Created line')");
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Edit
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
test("can edit a line", async () => {
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
await contains(".account_report_lines_list_x2many li[data-record_id='1'] .column").click();
|
||||
await waitFor(".o_dialog");
|
||||
|
||||
await contains("div[name='name'] input").edit("Line without children (edited)");
|
||||
await contains(".o_dialog .o_form_button_save").click();
|
||||
|
||||
await waitFor(
|
||||
".account_report_lines_list_x2many li span:contains('Line without children (edited)')"
|
||||
);
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Delete
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
test("can delete a root", async () => {
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
await contains(
|
||||
".account_report_lines_list_x2many li[data-record_id='1'] > div > .trash"
|
||||
).click();
|
||||
|
||||
expect(
|
||||
".account_report_lines_list_x2many li span:contains('Root without children')"
|
||||
).toHaveCount(0);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Root with children')").toHaveCount(
|
||||
1
|
||||
);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Child #1')").toHaveCount(1);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Grandchild')").toHaveCount(1);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Child #2')").toHaveCount(1);
|
||||
});
|
||||
|
||||
test("can delete a root with children", async () => {
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
await contains(
|
||||
".account_report_lines_list_x2many li[data-record_id='2'] > div > .trash"
|
||||
).click();
|
||||
|
||||
// Confirmation dialog "This line and all its children will be deleted. Are you sure you want to proceed?"
|
||||
await waitFor(".o_dialog");
|
||||
await contains(".o_dialog .btn-primary").click();
|
||||
|
||||
expect(
|
||||
".account_report_lines_list_x2many li span:contains('Root without children')"
|
||||
).toHaveCount(1);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Root with children')").toHaveCount(
|
||||
0
|
||||
);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Child #1')").toHaveCount(0);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Grandchild')").toHaveCount(0);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Child #2')").toHaveCount(0);
|
||||
});
|
||||
|
||||
test("can delete a last child", async () => {
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
await contains(
|
||||
".account_report_lines_list_x2many li[data-record_id='4'] > div > .trash"
|
||||
).click();
|
||||
|
||||
expect(
|
||||
".account_report_lines_list_x2many li span:contains('Root without children')"
|
||||
).toHaveCount(1);
|
||||
expect(
|
||||
".account_report_lines_list_x2many li[data-descendants_count='2'] span:contains('Root with children')"
|
||||
).toHaveCount(1);
|
||||
expect(
|
||||
".account_report_lines_list_x2many li[data-descendants_count='0'] span:contains('Child #1')"
|
||||
).toHaveCount(1);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Grandchild')").toHaveCount(0);
|
||||
expect(".account_report_lines_list_x2many li span:contains('Child #2')").toHaveCount(1);
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Drag and drop
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
test("can move a root down", async () => {
|
||||
Report._records[0].line_ids = [1, 2, 3, 4];
|
||||
ReportLines._records = [
|
||||
{
|
||||
id: 1,
|
||||
parent_id: false,
|
||||
hierarchy_level: 1,
|
||||
name: "dragged",
|
||||
code: "D",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
parent_id: false,
|
||||
hierarchy_level: 1,
|
||||
name: "noChild",
|
||||
code: "N",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
parent_id: false,
|
||||
hierarchy_level: 0,
|
||||
name: "parent",
|
||||
code: "P",
|
||||
foldability: "always_unfolded",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
parent_id: 3,
|
||||
hierarchy_level: 3,
|
||||
name: "child",
|
||||
code: "C",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
];
|
||||
|
||||
onRpc("report", "web_save", (args) => {
|
||||
expect.step("web_save");
|
||||
const lineIds = args.args[1].line_ids;
|
||||
|
||||
// Parents
|
||||
expect(lineIds[0][2].parent_id).toBe(3);
|
||||
|
||||
// Hierarchy levels
|
||||
expect(lineIds[0][2].hierarchy_level).toBe(3);
|
||||
|
||||
// Sequences
|
||||
expect(lineIds[0][2].sequence).toBe(4);
|
||||
expect(lineIds[1][2].sequence).toBe(1);
|
||||
expect(lineIds[2][2].sequence).toBe(2);
|
||||
expect(lineIds[3][2].sequence).toBe(3);
|
||||
});
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
const { drop, moveUnder } = await sortableDrag("li[data-record_id='1']");
|
||||
|
||||
await moveUnder("li[data-record_id='2']");
|
||||
await moveUnder("li[data-record_id='4']");
|
||||
await drop();
|
||||
|
||||
await contains(".o_form_button_save").click();
|
||||
expect.verifySteps(["web_save"]);
|
||||
});
|
||||
|
||||
test("can move a root up", async () => {
|
||||
Report._records[0].line_ids = [1, 2, 3, 4];
|
||||
ReportLines._records = [
|
||||
{
|
||||
id: 1,
|
||||
parent_id: false,
|
||||
hierarchy_level: 0,
|
||||
name: "parent",
|
||||
code: "P",
|
||||
foldability: "always_unfolded",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
parent_id: 1,
|
||||
hierarchy_level: 3,
|
||||
name: "child",
|
||||
code: "C",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
parent_id: false,
|
||||
hierarchy_level: 1,
|
||||
name: "noChild",
|
||||
code: "N",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
parent_id: false,
|
||||
hierarchy_level: 1,
|
||||
name: "dragged",
|
||||
code: "D",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
];
|
||||
|
||||
onRpc("report", "web_save", (args) => {
|
||||
expect.step("web_save");
|
||||
const lineIds = args.args[1].line_ids;
|
||||
|
||||
// Parents
|
||||
expect(lineIds[0][2].parent_id).toBe(1);
|
||||
|
||||
// Hierarchy levels
|
||||
expect(lineIds[0][2].hierarchy_level).toBe(3);
|
||||
|
||||
// Sequences
|
||||
expect(lineIds[0][2].sequence).toBe(2);
|
||||
expect(lineIds[1][2].sequence).toBe(1);
|
||||
expect(lineIds[2][2].sequence).toBe(3);
|
||||
expect(lineIds[3][2].sequence).toBe(4);
|
||||
});
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
const { drop, moveAbove } = await sortableDrag("li[data-record_id='4']");
|
||||
|
||||
await moveAbove("li[data-record_id='3']");
|
||||
await moveAbove("li[data-record_id='2']");
|
||||
await drop();
|
||||
|
||||
await contains(".o_form_button_save").click();
|
||||
expect.verifySteps(["web_save"]);
|
||||
});
|
||||
|
||||
test("can move a child down", async () => {
|
||||
Report._records[0].line_ids = [1, 2, 3, 4];
|
||||
ReportLines._records = [
|
||||
{
|
||||
id: 1,
|
||||
parent_id: false,
|
||||
hierarchy_level: 0,
|
||||
name: "parent",
|
||||
code: "P",
|
||||
foldability: "always_unfolded",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
parent_id: 1,
|
||||
hierarchy_level: 3,
|
||||
name: "dragged",
|
||||
code: "D",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
parent_id: 1,
|
||||
hierarchy_level: 3,
|
||||
name: "child",
|
||||
code: "C",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
parent_id: false,
|
||||
hierarchy_level: 1,
|
||||
name: "noChild",
|
||||
code: "N",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
];
|
||||
|
||||
onRpc("report", "web_save", (args) => {
|
||||
expect.step("web_save");
|
||||
const lineIds = args.args[1].line_ids;
|
||||
|
||||
// Parents
|
||||
expect(lineIds[0][2].parent_id).toBe(false);
|
||||
|
||||
// Hierarchy levels
|
||||
expect(lineIds[0][2].hierarchy_level).toBe(1);
|
||||
|
||||
// Sequences
|
||||
expect(lineIds[0][2].sequence).toBe(4);
|
||||
expect(lineIds[1][2].sequence).toBe(1);
|
||||
expect(lineIds[2][2].sequence).toBe(2);
|
||||
expect(lineIds[3][2].sequence).toBe(3);
|
||||
});
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
const { drop, moveUnder } = await sortableDrag("li[data-record_id='2']");
|
||||
|
||||
await moveUnder("li[data-record_id='3']");
|
||||
await moveUnder("li[data-record_id='4']");
|
||||
await drop();
|
||||
|
||||
await contains(".o_form_button_save").click();
|
||||
expect.verifySteps(["web_save"]);
|
||||
});
|
||||
|
||||
test("can move a child up", async () => {
|
||||
Report._records[0].line_ids = [1, 2, 3];
|
||||
ReportLines._records = [
|
||||
{
|
||||
id: 1,
|
||||
parent_id: false,
|
||||
hierarchy_level: 0,
|
||||
name: "parent",
|
||||
code: "P",
|
||||
foldability: "always_unfolded",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
parent_id: 1,
|
||||
hierarchy_level: 3,
|
||||
name: "child",
|
||||
code: "C",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
parent_id: 1,
|
||||
hierarchy_level: 3,
|
||||
name: "dragged",
|
||||
code: "D",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
];
|
||||
|
||||
onRpc("report", "web_save", (args) => {
|
||||
expect.step("web_save");
|
||||
const lineIds = args.args[1].line_ids;
|
||||
|
||||
// Parents
|
||||
expect(lineIds[0][2].parent_id).toBe(false);
|
||||
|
||||
// Hierarchy levels
|
||||
expect(lineIds[0][2].hierarchy_level).toBe(1);
|
||||
|
||||
// Sequences
|
||||
expect(lineIds[0][2].sequence).toBe(1);
|
||||
expect(lineIds[1][2].sequence).toBe(2);
|
||||
expect(lineIds[2][2].sequence).toBe(3);
|
||||
});
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
const { drop, moveAbove } = await sortableDrag("li[data-record_id='3']");
|
||||
|
||||
await moveAbove("li[data-record_id='2']");
|
||||
await moveAbove("li[data-record_id='1']");
|
||||
await drop();
|
||||
|
||||
await contains(".o_form_button_save").click();
|
||||
expect.verifySteps(["web_save"]);
|
||||
});
|
||||
|
||||
test("can move a new root into a child", async () => {
|
||||
Report._records[0].line_ids = [1, 2, 3];
|
||||
ReportLines._records = [
|
||||
{
|
||||
id: 1,
|
||||
parent_id: false,
|
||||
hierarchy_level: 0,
|
||||
name: "parent",
|
||||
code: "P",
|
||||
foldability: "always_unfolded",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
parent_id: 1,
|
||||
hierarchy_level: 3,
|
||||
name: "child",
|
||||
code: "C",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
parent_id: false,
|
||||
hierarchy_level: 1,
|
||||
name: "noChild",
|
||||
code: "N",
|
||||
foldability: "never_unfolded",
|
||||
},
|
||||
];
|
||||
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
await contains(".account_report_lines_list_x2many li:last-of-type a").click();
|
||||
await contains("div[name='name'] input").edit("dragged");
|
||||
await contains(".o_dialog .o_form_button_save").click();
|
||||
|
||||
const { drop, moveAbove } = await sortableDrag("li[data-record_id='4']");
|
||||
|
||||
await moveAbove("li[data-record_id='3']");
|
||||
await moveAbove("li[data-record_id='2']");
|
||||
await drop();
|
||||
|
||||
// Only assert web_save for the main form view, not for the dialog
|
||||
onRpc("report", "web_save", (args) => {
|
||||
expect.step("web_save");
|
||||
const lineIds = args.args[1].line_ids;
|
||||
|
||||
// Parents
|
||||
expect(lineIds[0][2].parent_id).toBe(1);
|
||||
|
||||
// Hierarchy levels
|
||||
expect(lineIds[0][2].hierarchy_level).toBe(3);
|
||||
|
||||
// Sequences
|
||||
expect(lineIds[0][2].sequence).toBe(2);
|
||||
expect(lineIds[1][2].sequence).toBe(1);
|
||||
expect(lineIds[2][2].sequence).toBe(3);
|
||||
expect(lineIds[3][2].sequence).toBe(4);
|
||||
});
|
||||
|
||||
await contains(".o_form_button_save").click();
|
||||
expect.verifySteps(["web_save"]);
|
||||
});
|
||||
|
||||
test("can move a child into a new root", async () => {
|
||||
Report._records[0].line_ids = [];
|
||||
ReportLines._records = [];
|
||||
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
|
||||
await contains(".account_report_lines_list_x2many li:last-of-type a").click();
|
||||
await contains("div[name='name'] input").edit("parent");
|
||||
await contains(".o_dialog .o_form_button_save").click();
|
||||
|
||||
await contains(".account_report_lines_list_x2many li:last-of-type a").click();
|
||||
await contains("div[name='name'] input").edit("dragged");
|
||||
await contains(".o_dialog .o_form_button_save").click();
|
||||
|
||||
const { drop } = await contains("li[data-record_id='2']").drag();
|
||||
await drop("li[data-record_id='2']", { position: "right", relative: true });
|
||||
|
||||
// Only assert web_save for the main form view, not for the dialog
|
||||
onRpc("report", "web_save", (args) => {
|
||||
expect.step("web_save");
|
||||
const lineIds = args.args[1].line_ids;
|
||||
|
||||
// Parents
|
||||
expect(lineIds[0][2].parent_id).toBe(1);
|
||||
|
||||
// Hierarchy levels
|
||||
expect(lineIds[0][2].hierarchy_level).toBe(3);
|
||||
|
||||
// Sequences
|
||||
expect(lineIds[0][2].sequence).toBe(2);
|
||||
expect(lineIds[1][2].sequence).toBe(1);
|
||||
});
|
||||
|
||||
await contains(".o_form_button_save").click();
|
||||
expect.verifySteps(["web_save"]);
|
||||
});
|
||||
|
||||
test.tags("desktop");
|
||||
test("can display and hide 'Code' column when toggled in optional fields", async () => {
|
||||
await mountView({
|
||||
type: "form",
|
||||
resId: 1,
|
||||
resModel: "report",
|
||||
});
|
||||
// Ensure `code` column is hidden by default
|
||||
expect(".account_report_lines_list_x2many span.fw-bold.fixed:contains('Code')").toHaveCount(0);
|
||||
|
||||
// simulate toggling the `code` field to make it visible
|
||||
await contains(".o-dropdown.dropdown-toggle").click();
|
||||
await contains("input[name='code']").click();
|
||||
|
||||
// Check that the column is now visible
|
||||
expect(".account_report_lines_list_x2many span.fw-bold.fixed:contains('Code')").toHaveCount(1);
|
||||
|
||||
// Toggle it back to hide and verify
|
||||
await contains("input[name='code']").click();
|
||||
expect(".account_report_lines_list_x2many span.fw-bold.fixed:contains('Code')").toHaveCount(0);
|
||||
});
|
||||
@@ -0,0 +1,285 @@
|
||||
import { AccountReportFilters } from "@account_reports/components/account_report/filters/filters";
|
||||
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
|
||||
import { expect, test } from "@odoo/hoot";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import { Component, Plugin, providePlugins, proxy, signal, usePlugin, xml } from "@odoo/owl";
|
||||
import { contains, mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
|
||||
// Due to dependency with mail module, we have to define their models for our tests.
|
||||
defineMailModels();
|
||||
|
||||
test("can change the date filter by editing textually", async () => {
|
||||
const date = proxy({
|
||||
period_type: "month",
|
||||
date_to: "2019-03-31",
|
||||
date_from: "2019-03-01",
|
||||
});
|
||||
|
||||
class AccountReportController extends Plugin {
|
||||
filters = { show_period_comparison: false };
|
||||
userGroups = {};
|
||||
cachedUserGroups = {};
|
||||
cachedFilterOptions = () => ({
|
||||
available_horizontal_groups: [],
|
||||
available_variants: [],
|
||||
companies: [],
|
||||
date: date,
|
||||
filter_date: {
|
||||
range_mode: true,
|
||||
filters: {
|
||||
month: {
|
||||
key: "month",
|
||||
start_day: 1,
|
||||
start_month: 1,
|
||||
months_per_period: 1,
|
||||
},
|
||||
quarter: {
|
||||
key: "quarter",
|
||||
start_day: 1,
|
||||
start_month: 1,
|
||||
months_per_period: 3,
|
||||
},
|
||||
year: {
|
||||
key: "year",
|
||||
start_day: 1,
|
||||
start_month: 1,
|
||||
months_per_period: 12,
|
||||
custom_ranges: [
|
||||
["2022-01-01", "2022-06-30", "FY 2022_1"],
|
||||
["2022-07-01", "2022-12-31", "FY 2022_2"],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
rounding_unit: "decimals",
|
||||
rounding_unit_names: {
|
||||
decimals: ".$",
|
||||
},
|
||||
});
|
||||
reload = (optionPath, newOptions) => {
|
||||
expect.step(`reload ${optionPath} to ${newOptions}`);
|
||||
};
|
||||
updateOption = (option, value) => {
|
||||
if (option === "date") {
|
||||
expect.step(
|
||||
`update option ${option} -> period_type: ${value.period_type} date_from: ${value.date_from} date_to: ${value.date_to}`
|
||||
);
|
||||
|
||||
date.period_type = value.period_type;
|
||||
date.date_from = value.date_from;
|
||||
date.date_to = value.date_to;
|
||||
}
|
||||
};
|
||||
getCacheKey = (sectionsSourceId, reportId) => `${sectionsSourceId}_${reportId}`;
|
||||
loadingCallNumberByCacheKey = new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, name) {
|
||||
return name in target ? target[name] : 0;
|
||||
},
|
||||
set(target, name, newValue) {
|
||||
target[name] = newValue;
|
||||
return true;
|
||||
},
|
||||
}
|
||||
);
|
||||
revision = 0;
|
||||
template = () => "account_reports.AccountReportFiltersCustomizable";
|
||||
component = () => AccountReportFilters;
|
||||
}
|
||||
|
||||
class AccountReportTestWrapper extends Component {
|
||||
static template = xml`<AccountReportFilters/>`;
|
||||
static components = { AccountReportFilters };
|
||||
|
||||
setup() {
|
||||
providePlugins([AccountReportController]);
|
||||
}
|
||||
}
|
||||
|
||||
await mountWithCleanup(AccountReportTestWrapper);
|
||||
// Default date = 2019-03-11
|
||||
|
||||
// Open Date Filter dropdown
|
||||
await contains("#filter_date > button.o-dropdown").click();
|
||||
|
||||
// Click the Month input when selected
|
||||
await contains(".date_filter_month.selected .input_current_date").click();
|
||||
// Edit the month by changing the text (+14 months)
|
||||
await contains(".date_filter_month .input_current_date:not([readonly])").edit("May 2020", {
|
||||
confirm: "tab",
|
||||
});
|
||||
// Click the Month input when selected
|
||||
await contains(".date_filter_month.selected .input_current_date").click();
|
||||
// Edit the month by changing the text (-10 months)
|
||||
await contains(".date_filter_month .input_current_date:not([readonly])").edit("May 2018", {
|
||||
confirm: "tab",
|
||||
});
|
||||
// Click the Month input when selected
|
||||
await contains(".date_filter_month.selected .input_current_date").click();
|
||||
// Edit the month by changing the text to something invalid
|
||||
await contains(".date_filter_month .input_current_date:not([readonly])").edit("Invalid Month", {
|
||||
confirm: "tab",
|
||||
});
|
||||
|
||||
// Select the Quarter filter
|
||||
await contains(".date_filter_quarter").click();
|
||||
|
||||
// Click the Quarter input when selected
|
||||
await contains(".date_filter_quarter.selected .input_current_date").click();
|
||||
// Edit the quarter by changing the text (+5 quarters)
|
||||
await contains(".date_filter_quarter .input_current_date:not([readonly])").edit(
|
||||
"Apr - Jun 2020",
|
||||
{ confirm: "tab" }
|
||||
);
|
||||
// Click the Quarter input when selected
|
||||
await contains(".date_filter_quarter.selected .input_current_date").click();
|
||||
// Edit the quarter by changing the text (-3 quarters)
|
||||
await contains(".date_filter_quarter .input_current_date:not([readonly])").edit(
|
||||
"Apr - Jun 2018",
|
||||
{ confirm: "tab" }
|
||||
);
|
||||
// Click the Quarter input when selected
|
||||
await contains(".date_filter_quarter.selected .input_current_date").click();
|
||||
// Edit the quarter by changing the text (invalid quarter, -4 quarters)
|
||||
await contains(".date_filter_quarter .input_current_date:not([readonly])").edit(
|
||||
"Random - Feb 2018",
|
||||
{ confirm: "tab" }
|
||||
);
|
||||
// Click the Quarter input when selected
|
||||
await contains(".date_filter_quarter.selected .input_current_date").click();
|
||||
// Edit the quarter by changing the text to something invalid
|
||||
await contains(".date_filter_quarter .input_current_date:not([readonly])").edit(
|
||||
"Invalid Quarter",
|
||||
{ confirm: "tab" }
|
||||
);
|
||||
|
||||
// Select the Year filter
|
||||
await contains(".date_filter_year").click();
|
||||
|
||||
// Click the Year input when selected
|
||||
await contains(".date_filter_year.selected .input_current_date").click();
|
||||
// Edit the year by changing the text (+2 years)
|
||||
await contains(".date_filter_year .input_current_date:not([readonly])").edit("2021", {
|
||||
confirm: "tab",
|
||||
});
|
||||
// Click the Year input when selected
|
||||
await contains(".date_filter_year.selected .input_current_date").click();
|
||||
// Edit the year by changing the text (-1 year)
|
||||
await contains(".date_filter_year .input_current_date:not([readonly])").edit("2018", {
|
||||
confirm: "tab",
|
||||
});
|
||||
// Click the Year input when selected
|
||||
await contains(".date_filter_year.selected .input_current_date").click();
|
||||
// Edit the year by changing the text to something invalid
|
||||
await contains(".date_filter_year .input_current_date:not([readonly])").edit("Invalid Year", {
|
||||
confirm: "tab",
|
||||
});
|
||||
|
||||
// Check for custom ranges
|
||||
|
||||
// Click the Year input when selected
|
||||
await contains(".date_filter_year.selected .input_current_date").click();
|
||||
// Edit the year by changing the text to something invalid
|
||||
await contains(".date_filter_year .input_current_date:not([readonly])").edit("FY 2022_1");
|
||||
// Click the Year input when selected
|
||||
await contains(".date_filter_year.selected .input_current_date").click();
|
||||
// Edit the year by changing the text to something invalid
|
||||
await contains(".date_filter_year .input_current_date:not([readonly])").edit("FY 2022_2");
|
||||
|
||||
expect.verifySteps([
|
||||
// Set the period to May 2020
|
||||
"update option date -> period_type: month date_from: 2020-05-01 date_to: 2020-05-31",
|
||||
|
||||
// Set the period to May 2018
|
||||
"update option date -> period_type: month date_from: 2018-05-01 date_to: 2018-05-31",
|
||||
|
||||
// Keep the month the same after entering an invalid value
|
||||
|
||||
// Switch to Quarter
|
||||
"update option date -> period_type: quarter date_from: 2019-01-01 date_to: 2019-03-31",
|
||||
|
||||
// Set the quarter to +5 quarters
|
||||
"update option date -> period_type: quarter date_from: 2020-04-01 date_to: 2020-06-30",
|
||||
|
||||
// Set the quarter to -3 quarters
|
||||
"update option date -> period_type: quarter date_from: 2018-04-01 date_to: 2018-06-30",
|
||||
|
||||
// Set the quarter to -4 quarters
|
||||
"update option date -> period_type: quarter date_from: 2018-01-01 date_to: 2018-03-31",
|
||||
|
||||
// Keep the quarter the same after entering an invalid value
|
||||
|
||||
// Switch to Year
|
||||
"update option date -> period_type: year date_from: 2019-01-01 date_to: 2019-12-31",
|
||||
|
||||
// // Set the year to +2 years
|
||||
"update option date -> period_type: year date_from: 2021-01-01 date_to: 2021-12-31",
|
||||
|
||||
// // Set the year to -1 year
|
||||
"update option date -> period_type: year date_from: 2018-01-01 date_to: 2018-12-31",
|
||||
|
||||
// Keep the year the same after entering an invalid value
|
||||
|
||||
//Custom range FY 2022_1
|
||||
"update option date -> period_type: year date_from: 2022-01-01 date_to: 2022-06-30",
|
||||
//Custom range FY 2022_2
|
||||
"update option date -> period_type: year date_from: 2022-07-01 date_to: 2022-12-31",
|
||||
]);
|
||||
});
|
||||
|
||||
test("date filter is reset when the report changes", async () => {
|
||||
const filterOptions = {
|
||||
report_id: 1,
|
||||
available_horizontal_groups: [],
|
||||
available_variants: [],
|
||||
date: {
|
||||
period_type: "month",
|
||||
date_to: "2026-06-30",
|
||||
date_from: "2026-06-01",
|
||||
},
|
||||
filter_date: {
|
||||
range_mode: false,
|
||||
filters: {
|
||||
month: { key: "month", start_day: 1, start_month: 1, months_per_period: 1 },
|
||||
},
|
||||
},
|
||||
rounding_unit: "decimals",
|
||||
rounding_unit_names: { decimals: ".$" },
|
||||
};
|
||||
|
||||
class AccountReportController extends Plugin {
|
||||
filters = { show_period_comparison: false };
|
||||
cachedUserGroups = {};
|
||||
cachedFilterOptions = signal(proxy(filterOptions));
|
||||
reload = () => {};
|
||||
updateOption = () => {};
|
||||
getCacheKey = () => "key";
|
||||
loadingCallNumberByCacheKey = {};
|
||||
|
||||
template = () => "account_reports.AccountReportFiltersCustomizable";
|
||||
component = () => AccountReportFilters;
|
||||
}
|
||||
|
||||
class AccountReportTestWrapper extends Component {
|
||||
static template = xml`<AccountReportFilters/>`;
|
||||
static components = { AccountReportFilters };
|
||||
|
||||
setup() {
|
||||
providePlugins([AccountReportController]);
|
||||
this.controller = usePlugin(AccountReportController);
|
||||
}
|
||||
}
|
||||
const filters = await mountWithCleanup(AccountReportTestWrapper);
|
||||
|
||||
// Move report 1 date filter March 2024 -> April 2024.
|
||||
await contains("#filter_date > button.o-dropdown").click();
|
||||
expect(".date_filter_month .input_current_date").toHaveValue("June 2026");
|
||||
await contains(".date_filter_month .btn_next_date").click();
|
||||
expect(".date_filter_month .input_current_date").toHaveValue("July 2026");
|
||||
|
||||
// Switching to another report must reset the date filter to that report's date.
|
||||
filters.controller.cachedFilterOptions().report_id = 2;
|
||||
await animationFrame();
|
||||
expect(".date_filter_month .input_current_date").toHaveValue("June 2026");
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
import { expect, test } from "@odoo/hoot";
|
||||
import { click, press } from "@odoo/hoot-dom";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import { Component, Plugin, providePlugins, signal, xml, useProps } from "@odoo/owl";
|
||||
import { mountWithCleanup, defineModels } from "@web/../tests/web_test_helpers";
|
||||
import { mailModels } from "@mail/../tests/mail_test_helpers";
|
||||
|
||||
import { AccountReportLineCellEditable } from "@account_reports/components/account_report/line_cell_editable/line_cell_editable";
|
||||
|
||||
// Due to dependency with mail module, we have to define their models for our tests.
|
||||
defineModels(mailModels);
|
||||
|
||||
class AccountReportController extends Plugin {
|
||||
options = {};
|
||||
scheduleClassUpdate = () => {};
|
||||
}
|
||||
|
||||
class AccountReportLineCellEditableTestWrapper extends Component {
|
||||
static template = xml`<AccountReportLineCellEditable t-props="this.props"/>`;
|
||||
static components = { AccountReportLineCellEditable };
|
||||
|
||||
props = useProps([ "cell", "line", "cellIndex" ]);
|
||||
setup() {
|
||||
providePlugins([AccountReportController]);
|
||||
}
|
||||
}
|
||||
|
||||
test("can unformat a value when focus and format when blur", async () => {
|
||||
await mountWithCleanup(AccountReportLineCellEditableTestWrapper, {
|
||||
props: {
|
||||
cell: {
|
||||
name: signal("5,702.22"),
|
||||
no_format: signal(5702.22),
|
||||
edit_popup_data: signal("{}"),
|
||||
figure_type: signal("float"),
|
||||
},
|
||||
cellIndex: 0,
|
||||
line: {},
|
||||
},
|
||||
});
|
||||
|
||||
expect(".o_input").toHaveValue("5,702.22");
|
||||
await click("[data-icon='edit']");
|
||||
await animationFrame();
|
||||
expect(".o_input").toHaveValue("5702.22");
|
||||
await press("Enter");
|
||||
await animationFrame();
|
||||
expect(".o_input").toHaveValue("5,702.22");
|
||||
});
|
||||
|
||||
test("can display boolean value", async () => {
|
||||
await mountWithCleanup(AccountReportLineCellEditableTestWrapper, {
|
||||
props: {
|
||||
cell: {
|
||||
name: signal("No"),
|
||||
no_format: signal(0),
|
||||
edit_popup_data: signal("{}"),
|
||||
figure_type: signal("boolean"),
|
||||
},
|
||||
cellIndex: 0,
|
||||
line: {},
|
||||
},
|
||||
});
|
||||
expect(".o_input").toHaveValue("No");
|
||||
});
|
||||
|
||||
test("can display a date value", async () => {
|
||||
await mountWithCleanup(AccountReportLineCellEditableTestWrapper, {
|
||||
props: {
|
||||
cell: {
|
||||
name: signal("2026-02-12T00:00:00.000+01:00"),
|
||||
no_format: signal("2026-02-12T00:00:00.000+01:00"),
|
||||
edit_popup_data: signal("{}"),
|
||||
figure_type: signal("date"),
|
||||
},
|
||||
cellIndex: 0,
|
||||
line: {},
|
||||
},
|
||||
});
|
||||
expect(".o_input").toHaveValue("02/12/2026");
|
||||
});
|
||||
|
||||
test("can display a datetime value in UTC", async () => {
|
||||
await mountWithCleanup(AccountReportLineCellEditableTestWrapper, {
|
||||
props: {
|
||||
cell: {
|
||||
name: signal("2026-02-12T10:00:00.000Z"),
|
||||
no_format: signal("2026-02-12T10:00:00.000Z"),
|
||||
edit_popup_data: signal("{}"),
|
||||
figure_type: signal("datetime"),
|
||||
},
|
||||
cellIndex: 0,
|
||||
line: {},
|
||||
},
|
||||
});
|
||||
expect(".o_input").toHaveValue("02/12/2026 10:00:00");
|
||||
});
|
||||
|
||||
test("can display a datetime value in UTC +1 and datetime in UTC +1", async () => {
|
||||
AccountReportController.prototype.context = { tz: "Europe/Brussels" };
|
||||
await mountWithCleanup(AccountReportLineCellEditableTestWrapper, {
|
||||
props: {
|
||||
cell: {
|
||||
name: signal("2026-02-12T10:00:00.000+01:00"),
|
||||
no_format: signal("2026-02-12T10:00:00.000+01:00"),
|
||||
edit_popup_data: signal("{}"),
|
||||
figure_type: signal("datetime"),
|
||||
},
|
||||
cellIndex: 0,
|
||||
line: {},
|
||||
},
|
||||
});
|
||||
expect(".o_input").toHaveValue("02/12/2026 10:00:00");
|
||||
});
|
||||
|
||||
test("can display a datetime value in UTC +1 but datetime in UTC", async () => {
|
||||
AccountReportController.prototype.context = { tz: "Europe/Brussels" };
|
||||
await mountWithCleanup(AccountReportLineCellEditableTestWrapper, {
|
||||
props: {
|
||||
cell: {
|
||||
name: signal("2026-02-12T10:00:00.000Z"),
|
||||
no_format: signal("2026-02-12T10:00:00.000Z"),
|
||||
edit_popup_data: signal("{}"),
|
||||
figure_type: signal("datetime"),
|
||||
},
|
||||
cellIndex: 0,
|
||||
line: {},
|
||||
},
|
||||
});
|
||||
expect(".o_input").toHaveValue("02/12/2026 11:00:00");
|
||||
});
|
||||
@@ -0,0 +1,162 @@
|
||||
import { expect, test } from "@odoo/hoot";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import { Component, Plugin, providePlugins, useProps, xml } from "@odoo/owl";
|
||||
import { defineModels, mountWithCleanup } from "@web/../tests/web_test_helpers";
|
||||
import { mailModels } from "@mail/../tests/mail_test_helpers";
|
||||
|
||||
import { AccountReportSearchBar } from "@account_reports/components/account_report/search_bar/search_bar";
|
||||
|
||||
defineModels(mailModels);
|
||||
|
||||
async function typeSearch(text) {
|
||||
const input = document.querySelector(".o_searchview_input");
|
||||
input.value = text;
|
||||
input.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
||||
await animationFrame();
|
||||
}
|
||||
|
||||
function makeControllerWrapper(lines) {
|
||||
class AccountReportController extends Plugin {
|
||||
reportLoadingPromise = Promise.resolve();
|
||||
lines = lines;
|
||||
updateOption(key, value) { expect.step(`updateOption:${key}:${value}`); }
|
||||
deleteOption(key) { expect.step(`deleteOption:${key}`); }
|
||||
invalidateVisibleLines() { expect.step("invalidateVisibleLines"); }
|
||||
}
|
||||
|
||||
class SearchBarWrapper extends Component {
|
||||
static template = xml`<AccountReportSearchBar t-props="this.props"/>`;
|
||||
static components = { AccountReportSearchBar };
|
||||
props = useProps();
|
||||
setup() {
|
||||
providePlugins([AccountReportController]);
|
||||
}
|
||||
}
|
||||
return SearchBarWrapper;
|
||||
}
|
||||
|
||||
test("non-matching lines get search_match set to false", async () => {
|
||||
const lines = [
|
||||
{ id: "~account.report~0|~account.report.line~1", name: "Revenue", level: 0 },
|
||||
{ id: "~account.report~0|~account.report.line~2", name: "Expenses", level: 0 },
|
||||
];
|
||||
await mountWithCleanup(makeControllerWrapper(lines));
|
||||
await typeSearch("revenue");
|
||||
|
||||
expect(lines[0].search_match).toBe(true);
|
||||
expect(lines[1].search_match).toBe(false);
|
||||
expect.verifySteps(["updateOption:filter_search_bar:revenue", "invalidateVisibleLines"]);
|
||||
});
|
||||
|
||||
test("search is case-insensitive", async () => {
|
||||
const lines = [
|
||||
{ id: "~account.report~0|~account.report.line~1", name: "Revenue", level: 0 },
|
||||
{ id: "~account.report~0|~account.report.line~2", name: "Expenses", level: 0 },
|
||||
];
|
||||
await mountWithCleanup(makeControllerWrapper(lines));
|
||||
await typeSearch("REVENUE");
|
||||
|
||||
expect(lines[0].search_match).toBe(true);
|
||||
expect(lines[1].search_match).toBe(false);
|
||||
expect.verifySteps(["updateOption:filter_search_bar:REVENUE", "invalidateVisibleLines"]);
|
||||
});
|
||||
|
||||
test("partial query matches substrings in line names", async () => {
|
||||
const lines = [
|
||||
{ id: "~account.report~0|~account.report.line~1", name: "Product Sales", level: 0 },
|
||||
{ id: "~account.report~0|~account.report.line~2", name: "Service Revenue", level: 0 },
|
||||
{ id: "~account.report~0|~account.report.line~3", name: "Expenses", level: 0 },
|
||||
];
|
||||
await mountWithCleanup(makeControllerWrapper(lines));
|
||||
await typeSearch("Sales");
|
||||
|
||||
expect(lines[0].search_match).toBe(true);
|
||||
expect(lines[1].search_match).toBe(false);
|
||||
expect(lines[2].search_match).toBe(false);
|
||||
expect.verifySteps(["updateOption:filter_search_bar:Sales", "invalidateVisibleLines"]);
|
||||
});
|
||||
|
||||
test("empty query sets all lines as matching and removes filter option", async () => {
|
||||
const lines = [
|
||||
{ id: "~account.report~0|~account.report.line~1", name: "Revenue", level: 0 },
|
||||
{ id: "~account.report~0|~account.report.line~2", name: "Expenses", level: 0 },
|
||||
];
|
||||
await mountWithCleanup(makeControllerWrapper(lines));
|
||||
|
||||
// Apply a non-empty search first to put some lines in a non-matching state.
|
||||
await typeSearch("revenue");
|
||||
expect(lines[0].search_match).toBe(true);
|
||||
expect(lines[1].search_match).toBe(false);
|
||||
|
||||
// Clearing the input resets every line to visible.
|
||||
await typeSearch("");
|
||||
|
||||
expect(lines[0].search_match).toBe(true);
|
||||
expect(lines[1].search_match).toBe(true);
|
||||
expect.verifySteps([
|
||||
"updateOption:filter_search_bar:revenue",
|
||||
"invalidateVisibleLines",
|
||||
"deleteOption:filter_search_bar",
|
||||
"invalidateVisibleLines",
|
||||
]);
|
||||
});
|
||||
|
||||
test("child match makes ancestor lines visible", async () => {
|
||||
const lines = [
|
||||
{ id: "~account.report~0|~account.report.line~1", name: "Parent", level: 0 },
|
||||
{ id: '~account.report~0|~account.report.line~1|{"groupby": "fake"}~res.fake~1', name: "Child Match", level: 1 },
|
||||
{ id: "~account.report~0|~account.report.line~2", name: "Unrelated", level: 0 },
|
||||
];
|
||||
await mountWithCleanup(makeControllerWrapper(lines));
|
||||
await typeSearch("child");
|
||||
|
||||
expect(lines[0].search_match).toBe(true); // Parent becomes visible
|
||||
expect(lines[1].search_match).toBe(true); // Matched line
|
||||
expect(lines[2].search_match).toBe(false); // Unrelated top-level sibling
|
||||
expect.verifySteps(["updateOption:filter_search_bar:child", "invalidateVisibleLines"]);
|
||||
});
|
||||
|
||||
test("parent match makes all descendant lines visible", async () => {
|
||||
const lines = [
|
||||
{ id: "~account.report~0|~account.report.line~1", name: "Parent Match", level: 0 },
|
||||
{ id: '~account.report~0|~account.report.line~1|{"groupby": "fake"}~res.fake~1', name: "Child", level: 1 },
|
||||
{ id: '~account.report~0|~account.report.line~1|{"groupby": "fake"}~res.fake~1|{"groupby": "fake2"}~res.fake2~1', name: "Grandchild", level: 2 },
|
||||
{ id: "~account.report~0|~account.report.line~2", name: "Sibling", level: 0 },
|
||||
];
|
||||
await mountWithCleanup(makeControllerWrapper(lines));
|
||||
await typeSearch("parent");
|
||||
|
||||
expect(lines[0].search_match).toBe(true); // Matched line
|
||||
expect(lines[1].search_match).toBe(true); // Child carried down
|
||||
expect(lines[2].search_match).toBe(true); // Grandchild carried down
|
||||
expect(lines[3].search_match).toBe(false); // Same-level sibling stops propagation
|
||||
expect.verifySteps(["updateOption:filter_search_bar:parent", "invalidateVisibleLines"]);
|
||||
});
|
||||
|
||||
test("sibling of matched line does not inherit search_match", async () => {
|
||||
const lines = [
|
||||
{ id: "~account.report~0|~account.report.line~1", name: "Parent", level: 0 },
|
||||
{ id: '~account.report~0|~account.report.line~1|{"groupby": "fake"}~res.fake~1', name: "Matching Child", level: 1 },
|
||||
{ id: '~account.report~0|~account.report.line~1|{"groupby": "fake"}~res.fake~2', name: "Other Child", level: 1 },
|
||||
];
|
||||
await mountWithCleanup(makeControllerWrapper(lines));
|
||||
await typeSearch("matching");
|
||||
|
||||
expect(lines[0].search_match).toBe(true); // Parent becomes visible
|
||||
expect(lines[1].search_match).toBe(true); // Matched child
|
||||
expect(lines[2].search_match).toBe(false); // Sibling at same level not matched
|
||||
expect.verifySteps(["updateOption:filter_search_bar:matching", "invalidateVisibleLines"]);
|
||||
});
|
||||
|
||||
test("initialQuery prop triggers search on mount", async () => {
|
||||
const lines = [
|
||||
{ id: "~account.report~0|~account.report.line~1", name: "Revenue", level: 0 },
|
||||
{ id: "~account.report~0|~account.report.line~2", name: "Expenses", level: 0 },
|
||||
];
|
||||
await mountWithCleanup(makeControllerWrapper(lines), { props: { initialQuery: "revenue" } });
|
||||
await animationFrame();
|
||||
|
||||
expect(lines[0].search_match).toBe(true);
|
||||
expect(lines[1].search_match).toBe(false);
|
||||
expect.verifySteps(["updateOption:filter_search_bar:revenue", "invalidateVisibleLines"]);
|
||||
});
|
||||
Reference in New Issue
Block a user