-
-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] project_task_code: Migration to 17.0
- Loading branch information
Nedas Żilinskas
committed
Oct 22, 2024
1 parent
f2723dc
commit 680712a
Showing
6 changed files
with
26 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
# Copyright 2016 Tecnativa <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import SUPERUSER_ID, api | ||
|
||
|
||
def pre_init_hook(cr): | ||
def pre_init_hook(env): | ||
""" | ||
With this pre-init-hook we want to avoid error when creating the UNIQUE | ||
code constraint when the module is installed and before the post-init-hook | ||
is launched. | ||
""" | ||
cr.execute("ALTER TABLE project_task ADD COLUMN code character varying;") | ||
cr.execute("UPDATE project_task SET code = id;") | ||
env.cr.execute("ALTER TABLE project_task ADD COLUMN code character varying;") | ||
env.cr.execute("UPDATE project_task SET code = id;") | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
def post_init_hook(env): | ||
""" | ||
This post-init-hook will update all existing task assigning them the | ||
corresponding sequence code. | ||
""" | ||
env = api.Environment(cr, SUPERUSER_ID, dict()) | ||
task_obj = env["project.task"] | ||
sequence_obj = env["ir.sequence"] | ||
tasks = task_obj.search([], order="id") | ||
for task_id in tasks.ids: | ||
cr.execute( | ||
env.cr.execute( | ||
"UPDATE project_task SET code = %s WHERE id = %s;", | ||
( | ||
sequence_obj.next_by_code("project.task"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
- Saran Lim. \<<[email protected]>\> | ||
- Tharathip Chaweewongphan \<<[email protected]>\> | ||
- Ruchir Shukla \<<[email protected]>\> | ||
- Nedas Žilinskas \<<[email protected]>\> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters