diff --git a/helpdesk_mgmt_project/README.rst b/helpdesk_mgmt_project/README.rst index 4f9f2c2b1a..afd055b66a 100644 --- a/helpdesk_mgmt_project/README.rst +++ b/helpdesk_mgmt_project/README.rst @@ -2,7 +2,7 @@ Helpdesk Project ================ -.. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! @@ -29,7 +29,8 @@ Helpdesk Project |badge1| |badge2| |badge3| |badge4| |badge5| This module adds Project in Helpdesk. -We add to the project form view a ticket counter that redirects you to the helpdesk +We add to the project form view a ticket counter that redirects you to the helpdesk. +We reiterated on tickets the behavior already in place on tasks in Odoo. **Table of contents** @@ -81,6 +82,8 @@ Contributors * Rafa Morant +* XCG Consulting, part of `Orbeet `_ + Maintainers ~~~~~~~~~~~ diff --git a/helpdesk_mgmt_project/models/__init__.py b/helpdesk_mgmt_project/models/__init__.py index 6dc6335f76..6672b7d844 100644 --- a/helpdesk_mgmt_project/models/__init__.py +++ b/helpdesk_mgmt_project/models/__init__.py @@ -1,4 +1 @@ -from . import helpdesk_ticket -from . import helpdesk_ticket_team -from . import project -from . import project_task +from . import helpdesk_ticket, helpdesk_ticket_team, project, project_task diff --git a/helpdesk_mgmt_project/models/helpdesk_ticket.py b/helpdesk_mgmt_project/models/helpdesk_ticket.py index 217ac37fc2..579852ef92 100644 --- a/helpdesk_mgmt_project/models/helpdesk_ticket.py +++ b/helpdesk_mgmt_project/models/helpdesk_ticket.py @@ -5,7 +5,9 @@ class HelpdeskTicket(models.Model): _inherit = "helpdesk.ticket" - project_id = fields.Many2one(string="Project", comodel_name="project.project") + project_id = fields.Many2one( + "project.project", string="Project", tracking=True, check_company=True + ) task_id = fields.Many2one( string="Task", comodel_name="project.task", @@ -14,6 +16,34 @@ class HelpdeskTicket(models.Model): store=True, ) + @api.model + def _default_company_id(self): + if self._context.get("default_project_id"): + return ( + self.env["project.project"] + .browse(self._context["default_project_id"]) + .company_id + ) + return self.env.company + + # Override field + company_id = fields.Many2one( + "res.company", + string="Company", + compute="_compute_company_id", + store=True, + readonly=False, + required=True, + copy=True, + default=_default_company_id, + ) + + @api.depends("project_id.company_id") + def _compute_company_id(self): + for ticket in self: + if ticket.project_id: + ticket.company_id = ticket.project_id.company_id + @api.depends("project_id") def _compute_task_id(self): for record in self: diff --git a/helpdesk_mgmt_project/readme/CONTRIBUTORS.rst b/helpdesk_mgmt_project/readme/CONTRIBUTORS.rst index 557940de99..8c6677e86f 100644 --- a/helpdesk_mgmt_project/readme/CONTRIBUTORS.rst +++ b/helpdesk_mgmt_project/readme/CONTRIBUTORS.rst @@ -21,3 +21,5 @@ * `ALBA Software `_: * Rafa Morant + +* XCG Consulting, part of `Orbeet `_ diff --git a/helpdesk_mgmt_project/readme/DESCRIPTION.rst b/helpdesk_mgmt_project/readme/DESCRIPTION.rst index df9464e1bd..473dca0a02 100644 --- a/helpdesk_mgmt_project/readme/DESCRIPTION.rst +++ b/helpdesk_mgmt_project/readme/DESCRIPTION.rst @@ -1,2 +1,3 @@ This module adds Project in Helpdesk. -We add to the project form view a ticket counter that redirects you to the helpdesk +We add to the project form view a ticket counter that redirects you to the helpdesk. +We reiterated on tickets the behavior already in place on tasks in Odoo. diff --git a/helpdesk_mgmt_project/static/description/index.html b/helpdesk_mgmt_project/static/description/index.html index c3af621513..3428959bc3 100644 --- a/helpdesk_mgmt_project/static/description/index.html +++ b/helpdesk_mgmt_project/static/description/index.html @@ -1,12 +1,11 @@ - - - -Helpdesk Project - - - -
-

Helpdesk Project

- - +<<<<<<< HEAD

Beta License: AGPL-3 OCA/helpdesk Translate me on Weblate Try me on Runboat

This module adds Project in Helpdesk. We add to the project form view a ticket counter that redirects you to the helpdesk

@@ -444,4 +556,188 @@

Maintainers

+======= +

+ Beta + License: AGPL-3 + OCA/helpdesk + Translate me on Weblate + Try me on Runboat +

+

+ This module adds Project in Helpdesk. We add to the project form view a ticket + counter that redirects you to the helpdesk +

+

Table of contents

+
+ +
+
+

Bug Tracker

+

+ Bugs are tracked on + GitHub Issues. In case of trouble, please check there if your issue has already been + reported. If you spotted it first, help us to smash it by providing a detailed + and welcomed + feedback. +

+

+ Do not contact contributors directly about support or help with technical + issues. +

+
+
+

Credits

+
+

Authors

+
    +
  • PuntSistemes S.L.U.
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ Odoo Community Association +

+ OCA, or the Odoo Community Association, is a nonprofit organization whose + mission is to support the collaborative development of Odoo features and + promote its widespread use. +

+

+ This module is part of the + OCA/helpdesk + project on GitHub. +

+

+ You are welcome to contribute. To learn how please visit + https://odoo-community.org/page/Contribute. +

+
+
+ + +>>>>>>> c9d815f8 ([IMP] helpdesk_mgmt_project: Set by default the company as the project one in tickets) diff --git a/helpdesk_mgmt_project/tests/test_helpdesk_ticket.py b/helpdesk_mgmt_project/tests/test_helpdesk_ticket.py index a51c8c6777..61d58711b7 100644 --- a/helpdesk_mgmt_project/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt_project/tests/test_helpdesk_ticket.py @@ -8,6 +8,8 @@ def setUpClass(cls): Ticket = cls.env["helpdesk.ticket"] Project = cls.env["project.project"] Task = cls.env["project.task"] + Company = cls.env["res.company"] + cls.company = Company.create({"name": "Test Last Company"}) cls.ticket = cls.ticket_a_unassigned cls.ticket2 = Ticket.create({"name": "Test 2", "description": "Ticket test2"}) cls.project1 = Project.create({"name": "Test Helpdesk-Project 1"}) @@ -80,3 +82,47 @@ def test_helpdesk_ticket_counts(self): 1, "Helpdesk Ticket: Task have one realted tickets.", ) + + def test_helpdesk_ticket_default_company(self): + self.env.user.groups_id += self.env.ref("project.group_project_manager") + new_project = self.env["project.project"].create( + { + "name": "Test Helpdesk-Project Different Company", + "company_id": self.company.id, + } + ) + ctx = {"default_project_id": new_project.id} + ticket3 = ( + self.env["helpdesk.ticket"] + .with_context(**ctx) + .create( + { + "name": "Test 3", + "description": "Ticket test3", + } + ) + ) + + self.assertEqual( + ticket3.project_id.name, + "Test Helpdesk-Project Different Company", + "Helpdesk Ticket: Ticket takes the project value defined in the context.", + ) + + self.assertTrue( + self.ticket.company_id == self.ticket2.company_id == self.env.company, + "Helpdesk Ticket: Tickets not created from a project take 'YourCompany' " + "as the default company by default.", + ) + + self.assertFalse( + ticket3.company_id.name == "YourCompany", + "Helpdesk Ticket: Ticket created from a project does not take the company " + "value set as default.", + ) + + self.assertEqual( + ticket3.company_id, + new_project.company_id, + "Helpdesk Ticket: Ticket defaults to the company of the project.", + ) diff --git a/helpdesk_mgmt_project/views/helpdesk_ticket_view.xml b/helpdesk_mgmt_project/views/helpdesk_ticket_view.xml index 8a698537ff..2a9d293342 100644 --- a/helpdesk_mgmt_project/views/helpdesk_ticket_view.xml +++ b/helpdesk_mgmt_project/views/helpdesk_ticket_view.xml @@ -33,6 +33,11 @@ +