forked from OCA/project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.py
More file actions
35 lines (30 loc) · 1.17 KB
/
hooks.py
File metadata and controls
35 lines (30 loc) · 1.17 KB
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 -*-
# Copyright 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID
from odoo.api import Environment
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_issue '
'ADD COLUMN issue_code character varying;')
cr.execute('UPDATE project_issue '
'SET issue_code = id;')
def assign_old_sequences(cr, pool):
"""
This post-init-hook will update all existing issue assigning them the
corresponding sequence code.
"""
env = Environment(cr, SUPERUSER_ID, dict())
issue_obj = env['project.issue']
sequence_obj = env['ir.sequence']
issues = issue_obj.search([], order="id")
for issue_id in issues.ids:
issue_code = sequence_obj.next_by_code('project.issue')
cr.execute('UPDATE project_issue '
'SET issue_code = %s '
'WHERE id = %s;',
(issue_code, issue_id, ))