diff --git a/addons/hr_timesheet/static/src/components/task_with_hours/task_with_hours.js b/addons/hr_timesheet/static/src/components/task_with_hours/task_with_hours.js index 22e1464d48b..ba82247cede 100644 --- a/addons/hr_timesheet/static/src/components/task_with_hours/task_with_hours.js +++ b/addons/hr_timesheet/static/src/components/task_with_hours/task_with_hours.js @@ -6,14 +6,6 @@ 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); } @@ -44,6 +36,16 @@ class TaskWithHours extends Many2OneField { return props; } + /** + * @override + */ + computeActiveActions(props) { + super.computeActiveActions(props); + const activeActions = this.state.activeActions; + activeActions.create = activeActions.create && this.canCreate; + activeActions.createEdit = activeActions.create; + } + } registry.category("fields").add("task_with_hours", TaskWithHours); diff --git a/addons/hr_timesheet/static/tests/hr_timesheet_common_tests.js b/addons/hr_timesheet/static/tests/hr_timesheet_common_tests.js new file mode 100644 index 00000000000..2973e580364 --- /dev/null +++ b/addons/hr_timesheet/static/tests/hr_timesheet_common_tests.js @@ -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": ` +
+ `, + "account.analytic.line,false,list": ` +