Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions project_ux/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ def _compute_display_name(self):
if task.project_id.show_task_id and task.id and task.display_name:
task.display_name = f"{task.display_name} (#{task.id})"

def onchange(self, values, field_names, fields_spec):
result = super().onchange(values, field_names, fields_spec)
# In the quick-create (My Tasks, project kanban) the "Task Title" input
# is bound to display_name and is only inversed into `name` on save.
# Because this module makes display_name depend on project_id (to append
# the task id), changing the project recomputes display_name from the
# still-empty `name`, blanking the title the user just typed. Restore the
# typed value in the onchange result so it survives the project change.
typed_title = values.get("display_name")
if (
"project_id" in (field_names or [])
and typed_title
and not values.get("name")
and not result.get("value", {}).get("display_name")
):
result.setdefault("value", {})["display_name"] = typed_title
return result

@api.model
def _search_display_name(self, operator, value):
domain = super()._search_display_name(operator, value)
Expand Down
1 change: 1 addition & 0 deletions project_ux/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import test_project_task
from . import test_project_task_type
from . import test_project_project
28 changes: 28 additions & 0 deletions project_ux/tests/test_project_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from odoo.tests.common import TransactionCase


class TestProjectProject(TransactionCase):
def setUp(self):
super().setUp()
self.Project = self.env["project.project"]

def test_create_project_modal_button_opens_form(self):
"""The "Create project" button of the New modal must open the project
form (via the standard get_formview_action), not the task pipeline
(action_view_tasks).
"""
view = self.env.ref("project.project_project_view_form_simplified_footer")
combined_arch = view.get_combined_arch()
self.assertIn('name="get_formview_action"', combined_arch)
self.assertNotIn('name="action_view_tasks"', combined_arch)

def test_get_formview_action_lands_on_project_form(self):
"""get_formview_action opens the created project's own form."""
project = self.Project.create({"name": "New Project"})

action = project.get_formview_action()

self.assertEqual(action["res_model"], "project.project")
self.assertEqual(action["res_id"], project.id)
self.assertEqual(action["target"], "current")
self.assertTrue(any(view_type == "form" for __, view_type in action["views"]))
22 changes: 22 additions & 0 deletions project_ux/tests/test_project_task.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from odoo.tests import Form
from odoo.tests.common import TransactionCase


Expand Down Expand Up @@ -94,3 +95,24 @@ def test_name_search_does_not_find_task_by_id_when_disabled_on_project(self):
result_ids = [task_id for task_id, __ in self.Task.name_search(str(self.test_task.id), limit=20)]

self.assertNotIn(self.test_task.id, result_ids)

def _check_quick_create_keeps_title(self, title):
"""Quick-create binds the "Task Title" to display_name (not name).
Selecting/changing the project must not wipe a title already typed.
"""
with Form(self.Task, view="project.quick_create_task_form") as task_form:
task_form.display_name = title
task_form.project_id = self.test_project
self.assertEqual(task_form.display_name, title)
task = task_form.record
self.assertEqual(task.name, title)
self.assertEqual(task.project_id, self.test_project)

def test_quick_create_keeps_title_when_selecting_project(self):
self._check_quick_create_keeps_title("My Title")

def test_quick_create_keeps_title_when_project_shows_task_id(self):
# The title must survive the project onchange even though display_name
# depends on project_id.show_task_id.
self.test_project.show_task_id = True
self._check_quick_create_keeps_title("Another Title")
15 changes: 15 additions & 0 deletions project_ux/views/project_project_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@
</field>
</record>

<!-- After creating a project from the "New" modal, open the project form
(so the user can finish configuring it) instead of redirecting to the
task pipeline / Kanban stages configuration. get_formview_action is the
standard base method that opens a record's own form view. -->
<record id="project_project_view_form_simplified_footer" model="ir.ui.view">
<field name="name">project.project.view.form.simplified.open.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.project_project_view_form_simplified_footer"/>
<field name="arch" type="xml">
<xpath expr="//footer/button[@name='action_view_tasks']" position="attributes">
<attribute name="name">get_formview_action</attribute>
</xpath>
</field>
</record>

</odoo>
Loading