1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
__author__ = 'Gaetan de Menten, <ged@tiny.be>'
31
parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
33
parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
35
group = optparse.OptionGroup(parser, "Database related options")
36
group.add_option("--db_host", dest="db_host", help="specify the database host")
37
group.add_option("--db_port", dest="db_port", help="specify the database port")
38
group.add_option("-d", "--database", dest="db_name", help="specify the database name")
39
group.add_option("-r", "--db_user", dest="db_user", help="specify the database user name")
40
group.add_option("-w", "--db_password", dest="db_password", help="specify the database password")
41
parser.add_option_group(group)
43
options = optparse.Values()
44
options.db_name = 'terp' # default value
45
parser.parse_args(values=options)
47
if hasattr(options, 'config'):
48
configparser = ConfigParser.ConfigParser()
49
configparser.read([options.config])
50
for name, value in configparser.items('options'):
51
if not (hasattr(options, name) and getattr(options, name)):
52
if value in ('true', 'True'):
54
if value in ('false', 'False'):
56
setattr(options, name, value)
60
host = hasattr(options, 'db_host') and "host=%s" % options.db_host or ''
61
port = hasattr(options, 'db_port') and "port=%s" % options.db_port or ''
62
name = "dbname=%s" % options.db_name
63
user = hasattr(options, 'db_user') and "user=%s" % options.db_user or ''
64
password = hasattr(options, 'db_password') and "password=%s" % options.db_password or ''
66
db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
69
# ---------------------------------------------------------------- #
70
# move user id from hr_analytic_timesheet to account_analytic_line #
71
# ---------------------------------------------------------------- #
73
cr.execute("UPDATE account_analytic_line SET user_id = hr_analytic_timesheet.user_id FROM hr_analytic_timesheet WHERE hr_analytic_timesheet.line_id = account_analytic_line.id")
81
cr.execute("select id from ir_ui_menu where (id not in (select parent_id from ir_ui_menu where parent_id is not null)) and (id not in (select res_id from ir_values where model='ir.ui.menu'))")
84
cr.execute("delete from ir_ui_menu where (id not in (select parent_id from ir_ui_menu where parent_id is not null)) and (id not in (select res_id from ir_values where model='ir.ui.menu'))")
87
# ----------------------------------------- #
88
# add default value for discount in invoice #
89
# ----------------------------------------- #
91
cr.execute("update account_invoice_line set discount=0.0 where discount is null;")
95
# -------------------------------------------------------------------------- #
96
# update constraint account_invoice_line_uos_id_fkey on account_invoice_line #
97
# -------------------------------------------------------------------------- #
99
cr.execute("ALTER TABLE account_invoice_line DROP CONSTRAINT account_invoice_line_uos_id_fkey")
100
cr.execute("ALTER TABLE account_invoice_line ADD FOREIGN KEY (uos_id) REFERENCES product_uom(id) ON DELETE SET NULL")
104
WARNING: account_uos has been replaced by product_uom.
105
It is not possible to migrate the data automatically so you need to create the old account_uos in the new product_uom.
106
And then update the field uos_id of the table account_invoice to match the new id of product_uom.
109
UPDATE account_invoice SET uos_id = new_id WHERE uos_id = old_id;
115
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: