[IMP] project_todo: add a create to-do command on the command palette

This task will add a new command on the command palette, which will
allow the user to create a to-do and schedule an activity for it.

The command will open a new wizard to create a to-do.

task-3330177

closes odoo/odoo#125644

Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
dise
2023-08-24 18:36:48 +02:00
parent 60009bccc9
commit 723ea29937
9 changed files with 123 additions and 0 deletions
+1
View File
@@ -1,5 +1,6 @@
from . import controllers
from . import models
from . import wizard
def _todo_uninstall(env):
# The record rule project.task_visibility_rule needs to apply to all rights and not just read after uninstallation
+1
View File
@@ -18,6 +18,7 @@
'data/todo_template.xml',
'views/project_task_views.xml',
'views/project_todo_menus.xml',
'wizard/mail_activity_todo_create.xml',
],
'installable': True,
'application': True,
@@ -2,3 +2,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_project_task_type_user,project.task.type.user,project.model_project_task_type,base.group_user,1,1,1,1
access_task_on_partner,project.task on partners,project.model_project_task,base.group_user,1,1,1,1
access_project_tags_user,project.project_tags_user,project.model_project_tags,base.group_user,1,1,1,1
access_mail_activity_todo_create,mail.activity.todo.create,model_mail_activity_todo_create,base.group_user,1,1,1,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_project_task_type_user project.task.type.user project.model_project_task_type base.group_user 1 1 1 1
3 access_task_on_partner project.task on partners project.model_project_task base.group_user 1 1 1 1
4 access_project_tags_user project.project_tags_user project.model_project_tags base.group_user 1 1 1 1
5 access_mail_activity_todo_create mail.activity.todo.create model_mail_activity_todo_create base.group_user 1 1 1 0
@@ -0,0 +1,14 @@
/** @odoo-module **/
import { onMounted } from "@odoo/owl";
import { FormController } from "@web/views/form/form_controller";
export class TodoActivityWizardController extends FormController {
setup() {
super.setup();
onMounted(() => {
const firstInput = document.querySelector('div.o_field_widget input');
firstInput.focus();
});
}
}
@@ -0,0 +1,12 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { formView } from "@web/views/form/form_view";
import { TodoActivityWizardController } from "./todo_activity_wizard_controller";
export const todoActivityWizardView = {
...formView,
Controller: TodoActivityWizardController,
};
registry.category("views").add("todo_activity_wizard", todoActivityWizardView);
@@ -5,13 +5,21 @@ import { onExternalClick } from "@mail/utils/common/hooks";
import { ActivityMenu } from "@mail/core/web/activity_menu";
import { useEffect, useRef, useState } from "@odoo/owl";
import { DateTimeInput } from "@web/core/datetime/datetime_input";
import { FormViewDialog } from "@web/views/view_dialogs/form_view_dialog";
import { useCommand } from "@web/core/commands/command_hook";
import { useService } from "@web/core/utils/hooks";
import { patch } from "@web/core/utils/patch";
import { registry } from "@web/core/registry";
// Add a to-do category for the command palette
registry.category("command_categories").add("to-do", {}, { sequence: 105 });
patch(ActivityMenu.prototype, {
setup() {
super.setup(...arguments);
this.rpc = useService("rpc");
this.orm = useService("orm");
this.dialogService = useService("dialog");
this.state = useState({ addingTodo: false });
this.todoInputRef = useRef("todoInput");
this.addingTodoDate = false;
@@ -33,6 +41,18 @@ patch(ActivityMenu.prototype, {
}
this.state.addingTodo = false;
});
useCommand(
_t("Add a To-Do"),
() => {
document.body.click(); // hack to close command palette
this.createActivityTodo();
},
{
category: "to-do",
hotkey: "alt+l",
global: true,
}
);
},
sortActivityGroups() {
@@ -53,6 +73,19 @@ patch(ActivityMenu.prototype, {
}
},
async createActivityTodo() {
const wizard = await this.orm.call("mail.activity.todo.create", "create", [{
"user_id": this.userId,
}]);
this.dialogService.add(FormViewDialog, {
title: "Add a To-Do",
resModel: "mail.activity.todo.create",
resId: wizard,
preventCreate: true,
size: "md",
});
},
async saveTodo() {
const { DateTime } = luxon;
const urlRegExp = /http(s)?:\/\/(www\.)?[a-zA-Z0-9@:%_+~#=~#?&/=\-;!.]{3,2000}/g;
+3
View File
@@ -0,0 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import mail_activity_todo_create
@@ -0,0 +1,37 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
class MailActivityTodoCreate(models.TransientModel):
_name = 'mail.activity.todo.create'
_description = 'Create activity and todo at the same time'
summary = fields.Char()
date_deadline = fields.Date('Due Date', index=True, required=True, default=fields.Date.context_today)
user_id = fields.Many2one('res.users', 'Assigned to', default=lambda self: self.env.user, required=True, readonly=True)
note = fields.Html(sanitize_style=True)
def create_todo_activity(self):
todo = self.env['project.task'].create({
'name': self.summary,
'description': self.note,
'date_deadline': self.date_deadline,
'user_ids': self.user_id.ids,
})
self.env['mail.activity'].create({
'res_model_id': self.env['ir.model']._get('project.task').id,
'res_id': todo.id,
'summary': self.summary,
'user_id': self.user_id.id,
'date_deadline': self.date_deadline,
'activity_type_id': self.env['mail.activity']._default_activity_type_for_model('project.task').id,
})
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'type': 'success',
'message': _("Your to-do has been successfully added to your pipeline."),
},
}
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<odoo>
<record id="mail_activity_todo_create_popup" model="ir.ui.view">
<field name="name">mail.activity.todo.create.popup</field>
<field name="model">mail.activity.todo.create</field>
<field name="arch" type="xml">
<form js_class="todo_activity_wizard">
<group>
<field name="summary" placeholder="Reminder to..." required="1"/>
<field name="date_deadline"/>
<field name="user_id" widget="many2one_avatar_user" options="{'no_open': 1}"/>
</group>
<field name="note" class="oe-bordered-editor" placeholder="Add details about your to-do..."/>
<footer>
<button class="btn btn-primary" type="object" name="create_todo_activity" close="1">Add To-Do</button>
<button class="btn btn-secondary" special="cancel" close="1">Discard</button>
</footer>
</form>
</field>
</record>
</odoo>