forked from OCA/project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
33 lines (29 loc) · 1.12 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
# Copyright 2016 Tecnativa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from odoo import api, SUPERUSER_ID
def create_code_equal_to_id(cr):
"""
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;')
def assign_old_sequences(cr, registry):
"""
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('UPDATE project_task '
'SET code = %s '
'WHERE id = %s;',
(sequence_obj.next_by_code('project.task'), task_id, ))