[IMP] todo: add conversion form for todo->task

This commit:
- Restrict the actions available in To-do to the static ones (archive,
unarchive, delete, duplicate)
- Add a action to convert todo to task

The conversion form, available through the action menu, allows to convert a
to-do/a private task (task with no project) to a task linked to a
project by setting:
- a project
- assignees
- project tags

This conversion form is only available in the form view of to-dos.

To be improved:
- Better management of the information displayed in the chatter when
setting followers to a to-do

task-3085077

Co-authored-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
Hugo Carlier (Huca)
2023-05-15 09:01:27 +02:00
co-authored by Xavier Bol
parent 3e9512b57c
commit 0a59f37e7d
8 changed files with 162 additions and 4 deletions
+11
View File
@@ -19,3 +19,14 @@ class Task(models.Model):
else:
vals['name'] = _('Untitled to-do')
return super().create(vals_list)
def action_convert_to_task(self):
self.ensure_one()
self.company_id = self.project_id.company_id
return {
'view_mode': 'form',
'res_model': 'project.task',
'res_id': self.id,
'type': 'ir.actions.act_window',
'target': 'main',
}
+3
View File
@@ -21,6 +21,9 @@
flex: 1;
}
}
.o_widget_todo_archived > .ribbon {
margin-top: 0px;
}
}
.o_field_html .note-editable {
border: none !important;
@@ -0,0 +1,20 @@
/** @odoo-module **/
import { onMounted } from "@odoo/owl";
import { FormController } from "@web/views/form/form_controller";
export class TodoConversionFormController extends FormController {
/**
* Allows to autofocus the first element of the conversion form
*
* @override
* @private
*/
setup() {
super.setup();
onMounted(() => {
const firstConversionInput = document.querySelector('div.o_todo_conversion_form_view input');
firstConversionInput.focus();
});
}
}
@@ -0,0 +1,12 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { formView } from "@web/views/form/form_view";
import { TodoConversionFormController } from "./todo_conversion_form_controller";
export const todoConversionFormView = {
...formView,
Controller: TodoConversionFormController,
};
registry.category("views").add("todo_conversion_form", todoConversionFormView);
@@ -2,13 +2,50 @@
import { FormController } from "@web/views/form/form_controller";
import { TodoEditableBreadcrumbName } from "@todo/components/todo_editable_breadcrumb_name/todo_editable_breadcrumb_name";
import { onWillStart } from "@odoo/owl";
/**
* The FormController is overridden to be able to manage the edition of the name of a to-do directly
* in the breadcrumb.
*/
export class TodoFormController extends FormController {}
export class TodoFormController extends FormController {
static template = "todo.TodoFormView";
Object.assign(TodoFormController.components, { TodoEditableBreadcrumbName });
TodoFormController.template = 'todo.TodoFormView';
setup() {
super.setup();
onWillStart(async () => {
this.projectAccess = await this.user.hasGroup("project.group_project_user");
});
}
get actionMenuItems() {
const actionToKeep = ["archive", "unarchive", "duplicate", "delete"];
const menuItems = super.actionMenuItems;
const filteredActions =
menuItems.action?.filter((action) => actionToKeep.includes(action.key)) || [];
if (this.projectAccess) {
filteredActions.push({
description: this.env._t("Convert to Task"),
callback: () => {
this.model.actionService.doAction(
"todo.project_task_action_convert_todo_to_task",
{
props: {
resId: this.model.root.resId,
},
}
);
},
});
}
menuItems.action = filteredActions;
menuItems.print = [];
return menuItems;
}
}
Object.assign(TodoFormController.components, {
TodoEditableBreadcrumbName,
});
@@ -0,0 +1,15 @@
/** @odoo-module */
import { ListController } from "@web/views/list/list_controller";
export class TodoListController extends ListController {
get actionMenuItems() {
this.archiveEnabled = true;
const actionToKeep = ["archive", "unarchive", "duplicate", "delete"];
const menuItems = super.actionMenuItems;
const filteredActions = menuItems.action?.filter(action => actionToKeep.includes(action.key)) || [];
menuItems.action = filteredActions;
menuItems.print = [];
return menuItems;
}
}
@@ -0,0 +1,12 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { listView } from "@web/views/list/list_view";
import { TodoListController } from "./todo_list_controller";
export const todoListView = {
...listView,
Controller: TodoListController,
};
registry.category("views").add("todo_list", todoListView);
+49 -1
View File
@@ -80,7 +80,7 @@
default_group_by="personal_stage_type_ids"
editable="bottom"
multi_edit="1"
sample="1">
js_class="todo_list">
<field name="name"/>
<field name="user_ids" optional="show" widget="many2many_avatar_user" options="{'no_quick_create': True}"/>
<field name="tag_ids" optional="show" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}"/>
@@ -146,6 +146,40 @@
</field>
</record>
<!-- Todo conversion form (used by an action added in TodoFormView (contoller) -->
<record id="project_task_view_todo_conversion_form" model="ir.ui.view">
<field name="model">project.task</field>
<field name="name">project.task.view.todo.conversion.form</field>
<field name="priority">999</field>
<field name="arch" type="xml">
<form string="Convert to Task"
js_class="todo_conversion_form">
<sheet>
<group>
<field name="project_id"
domain="[('company_id', 'in', context.get('allowed_company_ids'))]"
required="1"
placeholder="Select an existing project"
default_focus="1"/>
<field name="user_ids"
class="o_task_user_field"
options="{'no_open': True, 'no_quick_create': True}"
widget="many2many_avatar_user"
domain="[('share', '=', False), ('active', '=', True)]"/>
<field name="tag_ids" widget="many2many_tags"
options="{'color_field': 'color', 'no_create_edit': True}"
context="{'project_id': project_id}"
placeholder="Choose tags from the selected project"/>
</group>
</sheet>
<footer>
<button name="action_convert_to_task" string="Convert to Task" type="object" class="btn-primary"/>
<button string="Discard" special="cancel"/>
</footer>
</form>
</field>
</record>
<!-- Todo Activity -->
<record id="project_task_view_todo_activity" model="ir.ui.view">
<field name="name">project.task.view.todo.activity</field>
@@ -242,4 +276,18 @@
<field name="act_window_id" ref="project_task_action_todo"/>
</record>
<!-- Conversion actions-->
<record id="project_task_action_convert_todo_to_task" model="ir.actions.act_window">
<field name="name">Convert to Task</field>
<field name="res_model">project.task</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record model="ir.actions.act_window.view" id="project_task_action_convert_todo_to_task_form_view">
<field name="view_mode">form</field>
<field name="view_id" ref="project_task_view_todo_conversion_form"/>
<field name="act_window_id" ref="project_task_action_convert_todo_to_task"/>
</record>
</odoo>