1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# This module Copyright (C) 2012 OpenUpgrade community
6
# https://launchpad.net/~openupgrade-committers
9
# Therp BV <http://therp.nl>
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU Affero General Public License as
13
# published by the Free Software Foundation, either version 3 of the
14
# License, or (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU Affero General Public License for more details.
21
# You should have received a copy of the GNU Affero General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
##############################################################################
27
from osv import osv, fields
30
from openerp.openupgrade import openupgrade_tools
32
from openupgrade import openupgrade_tools
34
class generate_records_wizard(osv.osv_memory):
35
_name = 'openupgrade.generate.records.wizard'
36
_description = 'OpenUpgrade Generate Records Wizard'
38
'state': fields.selection([('init', 'init'), ('ready', 'ready')], 'State'),
41
'state': lambda *a: 'init',
44
def generate(self, cr, uid, ids, context=None):
46
Main wizard step. Make sure that all modules are up-to-date,
47
then reinitialize all installed modules.
48
Equivalent of running the server with '-d <database> --init all'
50
The goal of this is to fill the records table.
52
TODO: update module list and versions, then update all modules?
54
# Truncate the records table
55
if (openupgrade_tools.table_exists(cr, 'openupgrade_attribute') and
56
openupgrade_tools.table_exists(cr, 'openupgrade_record')):
58
'TRUNCATE openupgrade_attribute, openupgrade_record;'
61
# Need to get all modules in state 'installed'
62
module_obj = self.pool.get('ir.module.module')
63
module_ids = module_obj.search(
64
cr, uid, [('state', 'in', ['to install', 'to upgrade'])])
67
_db, pool = pooler.restart_pool(cr.dbname, update_module=True)
68
# Did we succeed above?
69
module_ids = module_obj.search(
70
cr, uid, [('state', 'in', ['to install', 'to upgrade'])])
72
modules = module_obj.read(
73
cr, uid, module_ids, ['name'], context=context)
75
"Cannot reliably generate records",
76
("Cannot seem to install or upgrade modules " +
77
', '.join([x['name'] for x in modules])))
78
# Now reinitialize all installed modules
79
module_ids = module_obj.search(
80
cr, uid, [('state', '=', 'installed')])
82
cr, uid, module_ids, {'state': 'to install'})
84
_db, pool = pooler.restart_pool(cr.dbname, update_module=True)
85
self.write(cr, uid, ids, {'state': 'ready'})
89
generate_records_wizard()