[IMP] web,hr_timesheet: convert timesheet_uom service and components in OWL
Before this commit, a service called `timesheet_uom` is created to add in the legacy registry, the right component to use when `timesheet_uom` is searched in the registry because it depends on the UoM set on the current company. This commit converts all the widgets in which be used in the `timesheet_uom` registry and also adapt the service to use the session instead of the legacy one. task-2944742 closes odoo/odoo#98380 Related: odoo/upgrade#3787 Related: odoo/enterprise#30565 Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
/** @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
@@ -0,0 +1,6 @@
|
||||
/** @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
@@ -0,0 +1,10 @@
|
||||
/** @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;
|
||||
}
|
||||
}
|
||||
@@ -178,7 +178,7 @@ const timesheetUomService = {
|
||||
return timesheetUomInfo;
|
||||
},
|
||||
};
|
||||
registry.category("services").add("timesheet_uom", timesheetUomService);
|
||||
registry.category("services").add("legacy_timesheet_uom", timesheetUomService);
|
||||
|
||||
return {
|
||||
FieldTimesheetFactor,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/** @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;
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
/** @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";
|
||||
|
||||
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 {
|
||||
TimesheetUoMField = fieldRegistry.get(timesheetUomWidget.widget) || TimesheetFloatFactorField;
|
||||
}
|
||||
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("timesheet_uom")) {
|
||||
if (!serviceRegistry.contains("legacy_timesheet_uom")) {
|
||||
// Remove dependency on legacy_session since we're patching the session directly
|
||||
serviceRegistry.add("timesheet_uom", Object.assign({}, timesheetUomService, { dependencies: [] }));
|
||||
serviceRegistry.add("legacy_timesheet_uom", Object.assign({}, timesheetUomService, { dependencies: [] }));
|
||||
}
|
||||
await makeTestEnv(); // Start services
|
||||
};
|
||||
|
||||
@@ -5,11 +5,15 @@ import { FloatField } from "../float/float_field";
|
||||
|
||||
const { Component } = owl;
|
||||
export class FloatFactorField extends Component {
|
||||
get factor() {
|
||||
return this.props.factor;
|
||||
}
|
||||
|
||||
get floatFieldProps() {
|
||||
const result = {
|
||||
...this.props,
|
||||
value: this.props.value * this.props.factor,
|
||||
update: (value) => this.props.update(value / this.props.factor),
|
||||
value: this.props.value * this.factor,
|
||||
update: (value) => this.props.update(value / this.factor),
|
||||
};
|
||||
delete result.factor;
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user