Skip to content

Commit

Permalink
[IMP] helpdesk_mgmt_project: Multi-company compatibility
Browse files Browse the repository at this point in the history
Example of use case with helpdesk_mgmt_timesheet:

- Create a team with no company defined.
- Create a project A for company A.
- Create a project B for company A.
- [Company A] In the created team we define the project A.
- [Company B] In the created team we define project B
- [Company A] We create a ticket and assign the team, project A will be defined.
- [Company B] We create a ticket and assign the team, project B will be defined.

TT50251
  • Loading branch information
victoralmau committed Jul 24, 2024
1 parent 5c54bd0 commit d7c6620
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion helpdesk_mgmt_project/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Helpdesk Project",
"summary": "Add the option to select project in the tickets.",
"version": "16.0.2.1.0",
"version": "16.0.2.2.0",
"license": "AGPL-3",
"category": "After-Sales",
"author": "PuntSistemes S.L.U., " "Odoo Community Association (OCA)",
Expand Down
20 changes: 20 additions & 0 deletions helpdesk_mgmt_project/migrations/16.0.2.2.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
"""Set the default_project_id value in the project company."""
env.cr.execute(
"""
SELECT team.id, team.old_default_project_id, project.company_id
FROM helpdesk_ticket_team AS team
JOIN project_project AS project ON team.old_default_project_id = project.id
WHERE team.old_default_project_id IS NOT NULL
"""
)
for team_id, old_default_project_id, company_id in env.cr.fetchall():
team = env["helpdesk.ticket.team"].with_company(company_id).browse(team_id)
team.write({"default_project_id": old_default_project_id})
23 changes: 23 additions & 0 deletions helpdesk_mgmt_project/migrations/16.0.2.2.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
"""Create a column with the old data and we fill it in."""
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE helpdesk_ticket_team
ADD COLUMN IF NOT EXISTS old_default_project_id INTEGER DEFAULT 0;
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE helpdesk_ticket_team
SET old_default_project_id = default_project_id
""",
)
5 changes: 4 additions & 1 deletion helpdesk_mgmt_project/models/helpdesk_ticket_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ class HelpdeskTeam(models.Model):
_inherit = "helpdesk.ticket.team"

default_project_id = fields.Many2one(
"project.project", string="Project", readonly=False
comodel_name="project.project",
string="Project",
readonly=False,
company_dependent=True,
)

0 comments on commit d7c6620

Please sign in to comment.