forked from camptocamp/project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
35 lines (30 loc) · 1.24 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
34
35
# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
from . import models
from openerp import 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.
"""
task_obj = registry['project.task']
sequence_obj = registry['ir.sequence']
task_ids = task_obj.search(cr, SUPERUSER_ID, [], order="id")
for task_id in task_ids:
cr.execute('UPDATE project_task '
'SET code = \'%s\' '
'WHERE id = %d;' %
(sequence_obj.get(cr, SUPERUSER_ID, 'project.task'),
task_id))