Initial commit: Hr packages

This commit is contained in:
Ernad Husremovic 2025-08-29 15:20:50 +02:00
commit 62531cd146
2820 changed files with 1432848 additions and 0 deletions

View file

@ -0,0 +1,130 @@
/** @odoo-module */
import { registry } from "@web/core/registry";
import { session } from "@web/session";
import { companyService } from "@web/webclient/company_service";
import { patchWithCleanup } from "@web/../tests/helpers/utils";
import { setupViewRegistries } from "@web/../tests/views/helpers";
export const getServerData = () => JSON.parse(JSON.stringify({
models: {
'account.analytic.line': {
fields: {
project_id: { string: "Project", type: "many2one", relation: "project.project" },
task_id: { string: "Task", type: "many2one", relation: "project.task" },
unit_amount: { string: "Unit Amount", type: "integer" },
},
records: [
{ id: 1, project_id: 1, task_id: 3, unit_amount: 1 },
{ id: 2, project_id: 1, task_id: false, unit_amount: 1 },
{ id: 3, project_id: false, task_id: false, unit_amount: 1 },
],
},
'project.project': {
fields: {
name: { string: "Name", type: "string" },
},
records: [
{ id: 1, name: "Project 1" },
],
},
'project.task': {
fields: {
name: { string: "Name", type: "string" },
project_id: { string: "Project", type: "many2one", relation: "project.project" },
},
records: [
{ id: 1, name: "Task 1\u00A0AdditionalInfo", project_id: 1 },
{ id: 2, name: "Task 2\u00A0AdditionalInfo", project_id: 1 },
{ id: 3, name: "Task 3\u00A0AdditionalInfo", project_id: 1 },
],
},
},
views: {
"account.analytic.line,false,form": `
<form>
<field name="project_id"/>
<field name="task_id"/>
<field name="unit_amount"/>
</form>
`,
"account.analytic.line,false,list": `
<tree editable="bottom">
<field name="project_id"/>
<field name="task_id"/>
<field name="unit_amount"/>
</tree>
`,
},
}));
export function updateArch(serverData, fieldNameWidgetNameMapping = {}, fieldNameContextMapping = {}) {
for (const viewKey in serverData.views) {
for (const [fieldName, widgetName] of Object.entries(fieldNameWidgetNameMapping)) {
serverData.views[viewKey] = serverData.views[viewKey].replace(
`name="${fieldName}"`,
`name="${fieldName}" widget="${widgetName}"`
);
}
for (const [fieldName, context] of Object.entries(fieldNameContextMapping)) {
serverData.views[viewKey] = serverData.views[viewKey].replace(
`name="${fieldName}"`,
`name="${fieldName}" context="${context}"`
);
}
}
}
export function addFieldsInArch(serverData, fields, beforeField) {
let fieldsArch = "";
for (const field of fields) {
fieldsArch += `<field name="${field}"/>
`;
}
for (const viewKey in serverData.views) {
serverData.views[viewKey] = serverData.views[viewKey].replace(
`<field name="${beforeField}"`,
`${fieldsArch}<field name="${beforeField}"`
);
}
}
export function setupTestEnv() {
setupViewRegistries();
patchWithCleanup(session, {
user_companies: {
current_company: 1,
allowed_companies: {
1: {
id: 1,
name: 'Company',
timesheet_uom_id: 1,
timesheet_uom_factor: 1,
},
},
},
user_context: {
allowed_company_ids: [1],
},
uom_ids: {
1: {
id: 1,
name: 'hour',
rounding: 0.01,
timesheet_widget: 'float_time',
},
2: {
id: 2,
name: 'day',
rounding: 0.01,
timesheet_widget: 'float_toggle',
},
},
});
const serviceRegistry = registry.category("services");
serviceRegistry.add("company", companyService, { force: true });
}

View file

@ -0,0 +1,196 @@
odoo.define("hr_timesheet.timesheet_uom_tests_env", function (require) {
"use strict";
const session = require('web.session');
const { createView } = require("web.test_utils");
const ListView = require('web.ListView');
const { timesheetUomService } = require('hr_timesheet.timesheet_uom');
const { makeTestEnv } = require("@web/../tests/helpers/mock_env");
const { registry } = require("@web/core/registry");
/**
* Sets the timesheet related widgets testing environment up.
*/
function SetupTimesheetUOMWidgetsTestEnvironment () {
this.allowedCompanies = {
1: {
id: 1,
name: 'Company 1',
timesheet_uom_id: 1,
timesheet_uom_factor: 1,
},
2: {
id: 2,
name: 'Company 2',
timesheet_uom_id: 2,
timesheet_uom_factor: 0.125,
},
3: {
id: 3,
name: 'Company 3',
timesheet_uom_id: 2,
timesheet_uom_factor: 0.125,
},
};
this.uomIds = {
1: {
id: 1,
name: 'hour',
rounding: 0.01,
timesheet_widget: 'float_time',
},
2: {
id: 2,
name: 'day',
rounding: 0.01,
timesheet_widget: 'float_toggle',
},
};
this.singleCompanyHourUOMUser = {
allowed_company_ids: [this.allowedCompanies[1].id],
};
this.singleCompanyDayUOMUser = {
allowed_company_ids: [this.allowedCompanies[2].id],
};
this.multiCompanyHourUOMUser = {
allowed_company_ids: [
this.allowedCompanies[1].id,
this.allowedCompanies[3].id,
],
};
this.multiCompanyDayUOMUser = {
allowed_company_ids: [
this.allowedCompanies[3].id,
this.allowedCompanies[1].id,
],
};
this.session = {
uid: 0, // In order to avoid bbqState and cookies to be taken into account in AbstractWebClient.
user_companies: {
current_company: 1,
allowed_companies: this.allowedCompanies,
},
user_context: this.singleCompanyHourUOMUser,
uom_ids: this.uomIds,
};
this.data = {
'account.analytic.line': {
fields: {
project_id: {
string: "Project",
type: "many2one",
relation: "project.project",
},
task_id: {
string:"Task",
type: "many2one",
relation: "project.task",
},
date: {
string: "Date",
type: "date",
},
unit_amount: {
string: "Unit Amount",
type: "float",
},
},
records: [
{
id: 1,
project_id: 1,
task_id: 1,
date: "2021-01-12",
unit_amount: 8,
},
],
},
'project.project': {
fields: {
name: {
string: "Project Name",
type: "char",
},
},
records: [
{
id: 1,
display_name: "P1",
},
],
},
'project.task': {
fields: {
name: {
string: "Task Name",
type: "char",
},
project_id: {
string: "Project",
type: "many2one",
relation: "project.project",
},
},
records: [
{
id: 1,
display_name: "T1",
project_id: 1,
},
],
},
};
this.patchSessionAndStartServices = async function (sessionToApply, doNotUseEnvSession = false) {
/*
Adds the timesheet_uom to the fieldRegistry by setting the session and
starting the timesheet_uom service which registers the widget in the registry.
*/
session.user_companies = Object.assign(
{ },
!doNotUseEnvSession && this.session.user_companies || { },
sessionToApply && sessionToApply.user_companies);
if (Object.keys(session.user_companies).length === 0) {
delete session.user_companies;
}
session.user_context = Object.assign(
{ },
!doNotUseEnvSession && this.session.user_context || { },
sessionToApply && sessionToApply.user_context);
session.uom_ids = Object.assign(
{ },
!doNotUseEnvSession && this.session.uom_ids || { },
sessionToApply && sessionToApply.uom_ids);
if (!doNotUseEnvSession && 'uid' in this.session) {
session.uid = this.session.uid;
}
if (sessionToApply && 'uid' in sessionToApply) {
session.uid = sessionToApply.uid;
}
const serviceRegistry = registry.category("services");
if (!serviceRegistry.contains("timesheet_uom")) {
// Remove dependency on legacy_session since we're patching the session directly
serviceRegistry.add("timesheet_uom", Object.assign({}, timesheetUomService, { dependencies: [] }));
}
await makeTestEnv(); // Start services
};
this.createView = async function (options) {
const sessionToApply = options && options.session || { };
await this.patchSessionAndStartServices(sessionToApply);
return await createView(Object.assign(
{
View: ListView,
data: this.data,
model: 'account.analytic.line',
arch: `
<tree>
<field name="unit_amount" widget="timesheet_uom"/>
</tree>`,
},
options || { },
));
};
};
return SetupTimesheetUOMWidgetsTestEnvironment;
});

View file

@ -0,0 +1,140 @@
odoo.define("hr_timesheet.timesheet_uom_tests", function (require) {
"use strict";
const session = require('web.session');
const SetupTimesheetUOMWidgetsTestEnvironment = require('hr_timesheet.timesheet_uom_tests_env');
const fieldUtils = require('web.field_utils');
const TimesheetUOM = require('hr_timesheet.timesheet_uom');
QUnit.module('Timesheet UOM Widgets', function (hooks) {
let env;
let sessionUserCompaniesBackup;
let sessionUserContextBackup;
let sessionUOMIdsBackup;
let sessionUIDBackup;
hooks.beforeEach(async function (assert) {
env = new SetupTimesheetUOMWidgetsTestEnvironment();
// Backups session parts that this testing module will alter in order to restore it at the end.
sessionUserCompaniesBackup = session.user_companies || false;
sessionUserContextBackup = session.user_context || false;
sessionUOMIdsBackup = session.uom_ids || false;
sessionUIDBackup = session.uid || false;
});
hooks.afterEach(async function (assert) {
// Restores the session
const sessionToApply = Object.assign(
{ },
sessionUserCompaniesBackup && {
user_companies: sessionUserCompaniesBackup,
} || { },
sessionUserContextBackup && {
user_context: sessionUserContextBackup,
} || { },
sessionUOMIdsBackup && {
uom_ids: sessionUOMIdsBackup,
} || { },
sessionUIDBackup && {
uid: sessionUIDBackup,
} || { });
await env.patchSessionAndStartServices(sessionToApply, true);
});
QUnit.module('timesheet_uom', function (hooks) {
QUnit.module('fieldRegistry', function (hooks) {
let FieldTimesheetTimeBackup;
let FieldTimesheetToggleBackup;
hooks.beforeEach(function (assert) {
// Backups the FieldTimesheetTime widget as it will be altered in this testing module
// in order to to ease testing.
FieldTimesheetTimeBackup = TimesheetUOM.FieldTimesheetTime;
TimesheetUOM.FieldTimesheetTime.include({
_render: function () {
const $widgetIdentification = $('<div>').addClass('i_am_a_timesheet_time_widget');
this.$el.append($widgetIdentification);
},
});
FieldTimesheetToggleBackup = TimesheetUOM.FieldTimesheetToggle;
TimesheetUOM.FieldTimesheetToggle.include({
_render: function () {
const $widgetIdentification = $('<div>').addClass('i_am_a_timesheet_toggle_widget');
this.$el.append($widgetIdentification);
},
});
});
hooks.afterEach(async function (hooks) {
// Restores the widgets and trigger reload in FieldRegistry.
TimesheetUOM.FieldTimesheetTime = FieldTimesheetTimeBackup;
TimesheetUOM.FieldTimesheetToggle = FieldTimesheetToggleBackup;
await env.patchSessionAndStartServices({ }, true);
});
QUnit.test('the timesheet_uom widget added to the fieldRegistry is company related', async function (assert) {
assert.expect(2);
let view = await env.createView();
assert.ok(view.$('.i_am_a_timesheet_time_widget').length, 'FieldTimesheetTime is rendered when company uom is hour');
view.destroy();
let option = {
session: {
user_context: env.singleCompanyDayUOMUser,
},
};
view = await env.createView(option);
assert.ok(view.$('.i_am_a_timesheet_toggle_widget').length, 'FieldTimesheetToggle is rendered when company uom is day');
view.destroy();
});
QUnit.test('the timesheet_uom widget added to the fieldRegistry in a multi company environment is the current company', async function (assert) {
assert.expect(2);
let option = {
session: {
user_context: env.multiCompanyHourUOMUser,
},
};
let view = await env.createView(option);
assert.ok(view.$('.i_am_a_timesheet_time_widget').length, 'FieldTimesheetTime is rendered when current company uom is hour');
view.destroy();
option = {
session: {
user_context: env.multiCompanyDayUOMUser,
},
};
view = await env.createView(option);
assert.ok(view.$('.i_am_a_timesheet_toggle_widget').length, 'FieldTimesheetToggle is rendered when current company uom is day');
view.destroy();
});
});
QUnit.module('timesheet_uom_factor', function (hooks) {
QUnit.test('the timesheet_uom_factor usage in formatters and parsers is company related', async function (assert) {
assert.expect(4);
await env.patchSessionAndStartServices();
assert.strictEqual(fieldUtils.format.timesheet_uom(1), '01:00', 'The format is taking the timesheet_uom_factor into account');
assert.strictEqual(fieldUtils.parse.timesheet_uom('01:00'), 1, 'The parsing is taking the timesheet_uom_factor into account');
const sessionToApply = {
user_context: env.singleCompanyDayUOMUser,
};
await env.patchSessionAndStartServices(sessionToApply);
assert.strictEqual(fieldUtils.format.timesheet_uom(8), '1.00', 'The format is taking the timesheet_uom_factor into account');
assert.strictEqual(fieldUtils.parse.timesheet_uom('1.00'), 8, 'The parsing is taking the timesheet_uom_factor into account');
});
QUnit.test('the timesheet_uom_factor taken into account in a multi company environment is the current company', async function (assert) {
assert.expect(4);
let sessionToApply = {
user_context: env.multiCompanyHourUOMUser,
};
await env.patchSessionAndStartServices(sessionToApply);
assert.strictEqual(fieldUtils.format.timesheet_uom(1), '01:00', 'The format is taking the timesheet_uom_factor into account');
assert.strictEqual(fieldUtils.parse.timesheet_uom('01:00'), 1, 'The parsing is taking the timesheet_uom_factor into account');
sessionToApply.user_context = env.singleCompanyDayUOMUser;
await env.patchSessionAndStartServices(sessionToApply);
assert.strictEqual(fieldUtils.format.timesheet_uom(8), '1.00', 'The format is taking the timesheet_uom_factor into account');
assert.strictEqual(fieldUtils.parse.timesheet_uom('1.00'), 8, 'The parsing is taking the timesheet_uom_factor into account');
});
});
});
});
});

View file

@ -0,0 +1,125 @@
/** @odoo-module */
import { registry } from "@web/core/registry";
import { session } from "@web/session";
import { companyService } from "@web/webclient/company_service";
import { uiService } from "@web/core/ui/ui_service";
import { makeView, setupViewRegistries} from "@web/../tests/views/helpers";
import { click, getFixture, patchWithCleanup } from "@web/../tests/helpers/utils";
const serviceRegistry = registry.category("services");
QUnit.module("Timesheet UOM Widgets", (hooks) => {
let serverData;
let target;
hooks.beforeEach(async function (assert) {
setupViewRegistries();
target = getFixture();
serverData = {
models: {
'account.analytic.line': {
fields: {
unit_amount: { string: "Unit Amount", type: "float" },
},
records: [
{ id: 1, unit_amount: 8 }
],
},
},
views: {
"account.analytic.line,false,list": `
<tree>
<field name="unit_amount" widget="timesheet_uom"/>
</tree>
`,
},
};
serviceRegistry.add("ui", uiService);
serviceRegistry.add("company", companyService, { force: true });
patchWithCleanup(session, {
user_companies: {
current_company: 1,
allowed_companies: {
1: {
id: 1,
name: 'Company',
timesheet_uom_id: 2,
timesheet_uom_factor: 0.125,
},
},
},
user_context: {
allowed_company_ids: [1],
},
uom_ids: {
1: {
id: 1,
name: 'hour',
rounding: 0.01,
timesheet_widget: 'float_time',
},
2: {
id: 2,
name: 'day',
rounding: 0.01,
timesheet_widget: 'float_toggle',
},
}
});
});
QUnit.module("TimesheetFloatToggleField");
QUnit.test("factor is applied in TimesheetFloatToggleField", async function (assert) {
await makeView({
serverData,
type: "list",
resModel: "account.analytic.line",
});
assert.containsOnce(target, 'div[name="unit_amount"]:contains("1")', "TimesheetFloatToggleField should take `timesheet_uom_factor` into account");
});
QUnit.test("ranges are working properly in TimesheetFloatToggleField", async function (assert) {
serverData.models["account.analytic.line"].records[0].unit_amount = 1;
serverData.views["account.analytic.line,false,list"] = serverData.views["account.analytic.line,false,list"].replace('<tree', '<tree editable="bottom"')
await makeView({
serverData,
type: "list",
resModel: "account.analytic.line",
});
// Enter edit mode
await click(target, 'div[name="unit_amount"]');
await click(target, 'div[name="unit_amount"] .o_field_float_toggle');
assert.containsOnce(target, 'div[name="unit_amount"]:contains("0.00")', "ranges are working properly in TimesheetFloatToggleField");
await click(target, 'div[name="unit_amount"] .o_field_float_toggle');
assert.containsOnce(target, 'div[name="unit_amount"]:contains("0.50")', "ranges are working properly in TimesheetFloatToggleField");
await click(target, 'div[name="unit_amount"] .o_field_float_toggle');
assert.containsOnce(target, 'div[name="unit_amount"]:contains("1.00")', "ranges are working properly in TimesheetFloatToggleField");
});
QUnit.module("TimesheetFloatTimeField");
QUnit.test("factor is applied in TimesheetFloatTimeField", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], {timesheet_uom_id: 1});
await makeView({
serverData,
type: "list",
resModel: "account.analytic.line",
});
assert.containsOnce(target, 'div[name="unit_amount"]:contains("08:00")', "TimesheetFloatTimeField should not take `timesheet_uom_factor` into account");
});
QUnit.module("TimesheetFloatFactorField");
QUnit.test("factor is applied in TimesheetFloatFactorField", async function (assert) {
patchWithCleanup(session.uom_ids[2], {timesheet_widget: 'float_factor'});
await makeView({
serverData,
type: "list",
resModel: "account.analytic.line",
});
assert.containsOnce(target, 'div[name="unit_amount"]:contains("1")', "TimesheetFloatFactorField should take `timesheet_uom_factor` into account");
});
});

View file

@ -0,0 +1,67 @@
/** @odoo-module */
import { makeView } from "@web/../tests/views/helpers";
import { click, clickDropdown, editInput, getFixture } from "@web/../tests/helpers/utils";
import { getServerData, updateArch, setupTestEnv } from "./hr_timesheet_common_tests";
QUnit.module("hr_timesheet", (hooks) => {
let target;
let serverData;
hooks.beforeEach(async function (assert) {
setupTestEnv();
serverData = getServerData();
updateArch(
serverData,
{ task_id: "task_with_hours" },
{ task_id: "{ 'default_project_id': project_id }" });
target = getFixture();
});
QUnit.module("task_with_hours");
async function _testCreateAndEdit(target, visible, assert) {
await click(target, ".o_list_many2one[name=task_id]");
await click(target, ".o_list_many2one[name=task_id] input");
await editInput(target, ".o_list_many2one[name=task_id] input", "NonExistingTask");
await click(target, ".o_list_many2one[name=task_id] input");
await clickDropdown(target, "task_id");
const testFunction = visible ? assert.containsOnce : assert.containsNone;
testFunction(target, '.o_list_many2one[name=task_id] .dropdown ul li:contains("Create and edit...")');
}
QUnit.test("quick create is enabled when project_id is set", async function (assert) {
await makeView({
serverData,
type: "list",
resModel: "account.analytic.line",
});
const secondRow = target.querySelector(".o_list_table .o_data_row:nth-of-type(2)");
await _testCreateAndEdit(secondRow, true, assert);
});
QUnit.test("quick create is no enabled when project_id is not set", async function (assert) {
await makeView({
serverData,
type: "list",
resModel: "account.analytic.line",
});
const thirdRow = target.querySelector(".o_list_table .o_data_row:nth-of-type(3)");
await _testCreateAndEdit(thirdRow, false, assert);
});
QUnit.test("the text of the task includes hours in the drop down but not in the line", async function (assert) {
await makeView({
serverData,
type: "list",
resModel: "account.analytic.line",
});
const firstRow = target.querySelector(".o_list_table .o_data_row:first-of-type");
assert.containsNone(firstRow, '.o_list_many2one[name=task_id]:contains("AdditionalInfo")');
await click(firstRow, ".o_list_many2one[name=task_id]");
await clickDropdown(firstRow, "task_id");
assert.containsN(firstRow, '.o_list_many2one[name=task_id] .dropdown ul li:contains("AdditionalInfo")', 3);
});
});

View file

@ -0,0 +1,76 @@
/** @odoo-module **/
import { companyService } from "@web/webclient/company_service";
import { getGraphRenderer } from "@web/../tests/views/graph_view_tests";
import { makeView } from "@web/../tests/views/helpers";
import { patchWithCleanup } from "@web/../tests/helpers/utils";
import { session } from "@web/session";
import { registry } from "@web/core/registry";
import { setupControlPanelServiceRegistry } from "@web/../tests/search/helpers";
const serviceRegistry = registry.category("services");
QUnit.module('hr_timesheet', function (hooks) {
let serverData;
hooks.beforeEach(() => {
serverData = {
models: {
'account.analytic.line': {
fields: {
unit_amount: { string: "Unit Amount", type: "float", group_operator: "sum", store: true },
},
records: [
{ id: 1, unit_amount: 8 }
],
},
},
views: {
// unit_amount is used as group_by and measure
"account.analytic.line,false,graph": `
<graph>
<field name="unit_amount"/>
<field name="unit_amount" type="measure"/>
</graph>
`,
}
}
setupControlPanelServiceRegistry();
serviceRegistry.add("company", companyService, { force: true });
});
QUnit.module("hr_timesheet_graphview");
QUnit.test('the timesheet graph view data are not multiplied by a factor that is company related (factor = 1)', async function (assert) {
assert.expect(1);
patchWithCleanup(session.user_companies.allowed_companies[1], {
timesheet_uom_factor: 1,
});
const graph = await makeView({
serverData,
resModel: "account.analytic.line",
type: "hr_timesheet_graphview",
});
const renderedData = getGraphRenderer(graph).chart.data.datasets[0].data;
assert.deepEqual(renderedData, [8], 'The timesheet graph view is taking the timesheet_uom_factor into account (factor === 1)');
});
QUnit.test('the timesheet graph view data are multiplied by a factor that is company related (factor !== 1)', async function (assert) {
assert.expect(1);
patchWithCleanup(session.user_companies.allowed_companies[1], {
timesheet_uom_factor: 0.125,
});
const graph = await makeView({
serverData,
resModel: "account.analytic.line",
type: "hr_timesheet_graphview",
});
const renderedData = getGraphRenderer(graph).chart.data.datasets[0].data;
assert.deepEqual(renderedData, [1], 'The timesheet graph view is taking the timesheet_uom_factor into account (factor !== 1)');
});
});

View file

@ -0,0 +1,86 @@
/** @odoo-module */
import { session } from "@web/session";
import { makeView } from "@web/../tests/views/helpers";
import { getFixture, patchWithCleanup } from "@web/../tests/helpers/utils";
import { getServerData, updateArch, setupTestEnv } from "./hr_timesheet_common_tests";
QUnit.module("hr_timesheet", (hooks) => {
let target;
let serverData;
hooks.beforeEach(async function (assert) {
setupTestEnv();
serverData = getServerData();
updateArch(serverData, { unit_amount: "timesheet_uom_no_toggle" });
target = getFixture();
});
QUnit.module("timesheet_uom_no_toggle");
QUnit.test("FloatTimeField is used when current company uom uses float_time widget", async function (assert) {
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.equal(unitAmountInput.value, "01:00", "unit_amount is displayed as time");
});
QUnit.test("FloatTimeField is not dependent of timesheet_uom_factor of the current company when current company uom uses float_time widget", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_factor: 2 });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.equal(unitAmountInput.value, "01:00", "timesheet_uom_factor is not taken into account");
});
QUnit.test("FloatToggleField is not used when current company uom uses float_toggle widget, FloatFactorField is used instead", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_id: 2 });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
assert.containsNone(target, 'div[name="unit_amount"] .o_field_float_toggle', "unit_amount is not displayed as float toggle");
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.containsOnce(target, 'div[name="unit_amount"] input[inputmode="decimal"]', "unit_amount is displayed as float");
assert.equal(unitAmountInput.value, "1.00", "unit_amount is not displayed as float and not as time");
});
QUnit.test("FloatFactorField is used when the current_company uom is not part of the session uom", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_id: 'dummy' });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.containsOnce(target, 'div[name="unit_amount"] input[inputmode="decimal"]', "unit_amount is displayed as float");
assert.equal(unitAmountInput.value, "1.00", "unit_amount is not displayed as float and not as time");
assert.containsNone(target, 'div[name="unit_amount"].o_field_float_toggle', "unit_amount is not displayed as float toggle");
});
QUnit.test("FloatFactorField is dependent of timesheet_uom_factor of the current company when current company uom uses float_toggle widget", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_id: 'dummy', timesheet_uom_factor: 2 });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.equal(unitAmountInput.value, "2.00", "timesheet_uom_factor is taken into account");
});
});

View file

@ -0,0 +1,94 @@
/** @odoo-module */
import { session } from "@web/session";
import { makeView } from "@web/../tests/views/helpers";
import { getFixture, patchWithCleanup } from "@web/../tests/helpers/utils";
import { getServerData, updateArch, setupTestEnv } from "./hr_timesheet_common_tests";
QUnit.module("hr_timesheet", (hooks) => {
let target;
let serverData;
hooks.beforeEach(async function (assert) {
setupTestEnv();
serverData = getServerData();
updateArch(serverData, { unit_amount: "timesheet_uom" });
target = getFixture();
});
QUnit.module("timesheet_uom");
QUnit.test("FloatTimeField is used when current company uom uses float_time widget", async function (assert) {
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.equal(unitAmountInput.value, "01:00", "unit_amount is displayed as time");
});
QUnit.test("FloatTimeField is not dependent of timesheet_uom_factor of the current company when current company uom uses float_time widget", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_factor: 2 });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.equal(unitAmountInput.value, "01:00", "timesheet_uom_factor is not taken into account");
});
QUnit.test("FloatToggleField is used when current company uom uses float_toggle widget", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_id: 2 });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
assert.containsOnce(target, 'div[name="unit_amount"] .o_field_float_toggle', "unit_amount is displayed as float toggle");
});
QUnit.test("FloatToggleField is dependent of timesheet_uom_factor of the current company when current company uom uses float_toggle widget", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_id: 2, timesheet_uom_factor: 2 });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
assert.containsOnce(target, 'div[name="unit_amount"] .o_field_float_toggle:contains("2.00")', "timesheet_uom_factor is taken into account");
});
QUnit.test("FloatFactorField is used when the current_company uom is not part of the session uom", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_id: 'dummy' });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.containsOnce(target, 'div[name="unit_amount"] input[inputmode="decimal"]', "unit_amount is displayed as float");
assert.equal(unitAmountInput.value, "1.00", "unit_amount is not displayed as float and not as time");
assert.containsNone(target, 'div[name="unit_amount"].o_field_float_toggle', "unit_amount is not displayed as float toggle");
});
QUnit.test("FloatFactorField is dependent of timesheet_uom_factor of the current company when current company uom uses float_toggle widget", async function (assert) {
patchWithCleanup(session.user_companies.allowed_companies[1], { timesheet_uom_id: 'dummy', timesheet_uom_factor: 2 });
await makeView({
serverData,
type: "form",
resModel: "account.analytic.line",
resId: 1,
});
const unitAmountInput = target.querySelector('div[name="unit_amount"] input');
assert.equal(unitAmountInput.value, "2.00", "timesheet_uom_factor is taken into account");
});
});