Skip to content

Commit

Permalink
Merge pull request #27 from Tecnativa/10.0-queue-end_migration_ou
Browse files Browse the repository at this point in the history
[FIX] queue_job: Complete migration script
  • Loading branch information
StefanRijnhart committed Jul 2, 2018
2 parents 198d08a + 0f449ff commit c7a836f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
29 changes: 29 additions & 0 deletions queue_job/migrations/10.0.1.0.0/end-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, SUPERUSER_ID


def migrate(cr, version):
"""Now that everything has been loaded, compute the value of
channel_method_name.
"""
if not version:
return
env = api.Environment(cr, SUPERUSER_ID, {})
QueueJob = env['queue.job']
groups = QueueJob.read_groups(
[], ['model_name', 'method_name'], ['model_name', 'method_name'],
lazy=False,
)
for group in groups:
if group['model_name'] not in env:
continue
model = env[group['model_name']]
method = getattr(model, group['method_name'], False)
QueueJob.search(group['__domain']).write({
'channel_method_name': '<%s>.%s' % (
method.im_class._name, method.__name__,
),
})
11 changes: 10 additions & 1 deletion queue_job/migrations/10.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Tecnativa - Vicent Cubells
# Copyright 2017-2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, SUPERUSER_ID


def migrate(cr, version):
if not version:
Expand All @@ -25,5 +28,11 @@ def migrate(cr, version):
'queue_job.group_queue_job_manager',)
],
)
# Pre-create column for avoiding the computation over non loaded models
env = api.Environment(cr, SUPERUSER_ID, {})
openupgrade.add_fields(env, [
('channel_method_name', 'queue.job', 'queue_job', 'char', False,
'queue_job'),
])
except ImportError:
pass
raise Exception("You need openupgradelib for performing the migration")

0 comments on commit c7a836f

Please sign in to comment.