-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
37 lines (28 loc) · 1.25 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
36
37
# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
from . import models
from openerp.api import Environment
from openerp import SUPERUSER_ID
new_field_code_added = False
def create_code_equal_to_id(cr):
cr.execute("SELECT column_name FROM information_schema.columns "
"WHERE table_name = 'crm_claim' AND column_name = 'code'")
if not cr.fetchone():
cr.execute('ALTER TABLE crm_claim '
'ADD COLUMN code character varying;')
cr.execute('UPDATE crm_claim '
'SET code = id;')
global new_field_code_added
new_field_code_added = True
def assign_old_sequences(cr, registry):
if not new_field_code_added:
# the field was already existing before the installation of the addon
return
with Environment.manage():
env = Environment(cr, SUPERUSER_ID, {})
sequence_model = env['ir.sequence']
claims = env['crm.claim'].search([], order="id")
for claim in claims:
claim.code = sequence_model.next_by_code('crm.claim')