[REF] hr_timesheet: convert kanban and list views to owl
Tests adaptations will come in a following PR, but the current focus is set on owl conversion. task-2936932 closes odoo/odoo#101208 X-original-commit: 22c8e0ec8cd0ffc6a14302fc548bb5fffc5c4e11 Related: odoo/enterprise#31820 Signed-off-by: Xavier <xbo@odoo.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { Many2OneField } from "@web/views/fields/many2one/many2one_field";
|
||||
|
||||
|
||||
class TaskWithHours extends Many2OneField {
|
||||
|
||||
setup() {
|
||||
super.setup();
|
||||
const activeActions = this.state.activeActions;
|
||||
activeActions.canCreate = activeActions.canCreate && this.canCreate;
|
||||
activeActions.canQuickCreate = activeActions.canQuickCreate || this.canCreate;
|
||||
activeActions.canCreateEdit = activeActions.canCreate;
|
||||
}
|
||||
|
||||
get canCreate() {
|
||||
return Boolean(this.context.default_project_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
get displayName() {
|
||||
const displayName = super.displayName;
|
||||
return displayName ? displayName.split('\u00A0')[0] : displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
get context() {
|
||||
return {...super.context, hr_timesheet_display_remaining_hours: true};
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
get Many2XAutocompleteProps() {
|
||||
const props = super.Many2XAutocompleteProps;
|
||||
if (!this.canCreate) {
|
||||
props.quickCreate = null;
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registry.category("fields").add("task_with_hours", TaskWithHours);
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { FloatFactorField } from "@web/views/fields/float_factor/float_factor_field";
|
||||
import { TimesheetUOMMultiCompanyMixin } from "../../mixins/timesheet_uom_multi_company_mixin";
|
||||
|
||||
export class TimesheetFloatFactorField extends TimesheetUOMMultiCompanyMixin(FloatFactorField) {
|
||||
get factor() {
|
||||
return this.currentCompanyTimesheetUOMFactor || super.factor;
|
||||
}
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { FloatTimeField } from '@web/views/fields/float_time/float_time_field';
|
||||
import { TimesheetUOMMultiCompanyMixin } from '../../mixins/timesheet_uom_multi_company_mixin';
|
||||
|
||||
export class TimesheetFloatTimeField extends TimesheetUOMMultiCompanyMixin(FloatTimeField) {}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { FloatToggleField } from '@web/views/fields/float_toggle/float_toggle_field';
|
||||
import { TimesheetUOMMultiCompanyMixin } from '../../mixins/timesheet_uom_multi_company_mixin';
|
||||
|
||||
export class TimesheetFloatToggleField extends TimesheetUOMMultiCompanyMixin(FloatToggleField) {
|
||||
get factor() {
|
||||
return this.currentCompanyTimesheetUOMFactor || super.factor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { session } from "@web/session";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { FloatFactorField } from "@web/views/fields/float_factor/float_factor_field";
|
||||
import { FloatToggleField } from "@web/views/fields/float_toggle/float_toggle_field";
|
||||
import { FloatTimeField } from "@web/views/fields/float_time/float_time_field";
|
||||
import { standardFieldProps } from "@web/views/fields/standard_field_props";
|
||||
|
||||
const { Component } = owl;
|
||||
|
||||
|
||||
export class TimesheetUOM extends Component {
|
||||
|
||||
setup() {
|
||||
this.companyService = useService("company");
|
||||
}
|
||||
|
||||
get timesheetUOMId() {
|
||||
return this.companyService.currentCompany.timesheet_uom_id;
|
||||
}
|
||||
|
||||
get timesheetWidget() {
|
||||
let timesheet_widget = "float_factor";
|
||||
if (this.timesheetUOMId in session.uom_ids) {
|
||||
timesheet_widget = session.uom_ids[this.timesheetUOMId].timesheet_widget;
|
||||
}
|
||||
return timesheet_widget;
|
||||
}
|
||||
|
||||
get timesheetComponent() {
|
||||
return registry.category("fields").get(this.timesheetWidget, FloatFactorField);
|
||||
}
|
||||
|
||||
get timesheetComponentProps() {
|
||||
const factorDependantComponents = ["float_toggle", "float_factor"];
|
||||
return factorDependantComponents.includes(this.timesheetWidget) ? this.FactorCompanyDependentProps : this.props;
|
||||
}
|
||||
|
||||
get FactorCompanyDependentProps() {
|
||||
const factor = this.companyService.currentCompany.timesheet_uom_factor || this.props.factor;
|
||||
return { ...this.props, factor };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TimesheetUOM.props = {
|
||||
...standardFieldProps,
|
||||
};
|
||||
|
||||
TimesheetUOM.template = "hr_timesheet.TimesheetUOM";
|
||||
|
||||
TimesheetUOM.components = { FloatFactorField, FloatToggleField, FloatTimeField };
|
||||
|
||||
registry.category("fields").add("timesheet_uom", TimesheetUOM);
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<templates>
|
||||
|
||||
<t t-name="hr_timesheet.TimesheetUOM" owl="1">
|
||||
<t t-component="timesheetComponent" t-props="timesheetComponentProps"/>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
@@ -178,7 +178,7 @@ const timesheetUomService = {
|
||||
return timesheetUomInfo;
|
||||
},
|
||||
};
|
||||
registry.category("services").add("legacy_timesheet_uom", timesheetUomService);
|
||||
registry.category("services").add("timesheet_uom", timesheetUomService);
|
||||
|
||||
return {
|
||||
FieldTimesheetFactor,
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
|
||||
const { onWillStart } = owl;
|
||||
|
||||
export const TimesheetUOMMultiCompanyMixin = (component) => class extends component {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.companyService = useService('company');
|
||||
onWillStart(() => {
|
||||
this.currentCompanyTimesheetUOMFactor = this.companyService.currentCompany.timesheet_uom_factor || 1;
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,59 +0,0 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { session } from "@web/session";
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
import { TimesheetFloatFactorField } from "../components/timesheet_float_factor/timesheet_float_factor_field";
|
||||
import { TimesheetFloatTimeField } from "../components/timesheet_float_time/timesheet_float_time_field";
|
||||
import { TimesheetFloatToggleField } from "../components/timesheet_float_toggle/timesheet_float_toggle";
|
||||
import {FloatFactorField} from "@web/views/fields/float_factor/float_factor_field";
|
||||
|
||||
export const timesheetUomService = {
|
||||
dependencies: ["company"],
|
||||
start(env, { company }) {
|
||||
const timesheetUomWidget = { widget: "float_factor" };
|
||||
if (company.allowedCompanyIds.length) {
|
||||
const currentCompanyTimesheetUOMId = company.currentCompany.timesheet_uom_id || false;
|
||||
if (currentCompanyTimesheetUOMId) {
|
||||
timesheetUomWidget.widget = session.uom_ids[currentCompanyTimesheetUOMId].timesheet_widget;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binding depending on Company Preference
|
||||
*
|
||||
* determine which widget will be the timesheet one.
|
||||
* Simply match the 'timesheet_uom' widget key with the correct
|
||||
* implementation (float_time, float_toggle, ...). The default
|
||||
* value will be 'float_factor'.
|
||||
**/
|
||||
const fieldRegistry = registry.category("fields");
|
||||
|
||||
let TimesheetUoMField = null;
|
||||
|
||||
if (timesheetUomWidget.widget === "float_toggle") {
|
||||
TimesheetUoMField = TimesheetFloatToggleField;
|
||||
} else if (timesheetUomWidget.widget === "float_time") {
|
||||
TimesheetUoMField = TimesheetFloatTimeField;
|
||||
} else {
|
||||
let fieldRegistryWidget = fieldRegistry.get(timesheetUomWidget.widget);
|
||||
if (fieldRegistryWidget === FloatFactorField) {
|
||||
fieldRegistryWidget = TimesheetFloatFactorField;
|
||||
}
|
||||
TimesheetUoMField = fieldRegistryWidget;
|
||||
}
|
||||
fieldRegistry.add("timesheet_uom", TimesheetUoMField);
|
||||
|
||||
// widget timesheet_uom_no_toggle is the same as timesheet_uom but without toggle.
|
||||
// We can modify easly huge amount of days.
|
||||
let TimesheetUoMWithoutToggleField = TimesheetUoMField;
|
||||
if (timesheetUomWidget.widget === "float_toggle") {
|
||||
TimesheetUoMWithoutToggleField = TimesheetFloatFactorField;
|
||||
}
|
||||
fieldRegistry.add("timesheet_uom_no_toggle", TimesheetUoMWithoutToggleField);
|
||||
|
||||
return timesheetUomWidget.widget;
|
||||
},
|
||||
};
|
||||
|
||||
registry.category("services").add("timesheet_uom", timesheetUomService);
|
||||
@@ -167,9 +167,9 @@ function SetupTimesheetUOMWidgetsTestEnvironment () {
|
||||
session.uid = sessionToApply.uid;
|
||||
}
|
||||
const serviceRegistry = registry.category("services");
|
||||
if (!serviceRegistry.contains("legacy_timesheet_uom")) {
|
||||
if (!serviceRegistry.contains("timesheet_uom")) {
|
||||
// Remove dependency on legacy_session since we're patching the session directly
|
||||
serviceRegistry.add("legacy_timesheet_uom", Object.assign({}, timesheetUomService, { dependencies: [] }));
|
||||
serviceRegistry.add("timesheet_uom", Object.assign({}, timesheetUomService, { dependencies: [] }));
|
||||
}
|
||||
await makeTestEnv(); // Start services
|
||||
};
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { registry } from "@web/core/registry";
|
||||
import { session } from "@web/session";
|
||||
import { companyService } from "@web/webclient/company_service";
|
||||
import { timesheetUomService } from "../src/services/timesheet_uom_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";
|
||||
@@ -36,7 +35,6 @@ QUnit.module("Timesheet UOM Widgets", (hooks) => {
|
||||
},
|
||||
};
|
||||
serviceRegistry.add("ui", uiService);
|
||||
serviceRegistry.add("timesheet_uom", timesheetUomService);
|
||||
serviceRegistry.add("company", companyService, { force: true });
|
||||
patchWithCleanup(session, {
|
||||
user_companies: {
|
||||
|
||||
@@ -198,7 +198,8 @@ export function formatFloatTime(value, options = {}) {
|
||||
value = Math.abs(value);
|
||||
}
|
||||
let hour = Math.floor(value);
|
||||
// This ensures that we do not have float issues while still considering that 59s is 00:00.
|
||||
// Although looking quite overkill, the following line ensures that we do
|
||||
// not have float issues while still considering that 59s is 00:00.
|
||||
let min = Math.floor(Math.round((value % 1) * 100) / 100 * 60);
|
||||
if (min === 60) {
|
||||
min = 0;
|
||||
|
||||
Reference in New Issue
Block a user