[FIX] website_mail_group: restore missing snippet icon
[odoo/odoo.git] / history / migrate / 3.3.0-3.4.0 / post.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.     
19 #
20 ##############################################################################
21
22 __author__ = 'Gaetan de Menten, <ged@tiny.be>'
23 __version__ = '0.1.0'
24
25 import psycopg
26 import optparse
27 import ConfigParser
28
29 # -----
30
31 parser = optparse.OptionParser(version="Tiny ERP server migration script " + __version__)
32
33 parser.add_option("-c", "--config", dest="config", help="specify path to Tiny ERP config file")
34
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)
42
43 options = optparse.Values()
44 options.db_name = 'terp' # default value
45 parser.parse_args(values=options)
46
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'):
53                 value = True
54             if value in ('false', 'False'):
55                 value = False
56             setattr(options, name, value)
57
58 # -----
59
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 ''
65
66 db = psycopg.connect('%s %s %s %s %s' % (host, port, name, user, password), serialize=0)
67 cr = db.cursor()
68
69 # ------------------------------------------- #
70 # convert partner payment terms to properties #
71 # ------------------------------------------- #
72
73 # setup
74
75 cr.execute("select id from ir_model_fields where name='property_payment_term' and model='res.partner'")
76 fields_id = cr.fetchone()[0]
77
78 cr.execute("select company_id from res_users where company_id is not null limit 1")
79 company_id = cr.fetchone()[0]
80
81 # get partners
82 cr.execute("SELECT c.relname FROM pg_class c, pg_attribute a WHERE c.relname='res_partner' AND a.attname='payment_term' AND c.oid=a.attrelid")
83 partners=[]
84 drop_payment_term=False
85 if cr.rowcount:
86     drop_payment_term=True
87     cr.execute("select id, payment_term from res_partner where payment_term is not null")
88     partners = cr.dictfetchall()
89
90 # loop over them
91
92 for partner in partners:
93     value = 'account.payment.term,%d' % partner['payment_term']
94     res_id = 'res.partner,%d' % partner['id']
95     cr.execute(
96         "insert into ir_property(name, value, res_id, company_id, fields_id) "\
97         "values(%s, %s, %s, %d, %d)", 
98         ('property_payment_term', value, res_id, company_id, fields_id))
99
100 # remove the field
101 if drop_payment_term:
102     cr.execute("alter table res_partner drop column payment_term")
103 cr.execute("delete from ir_model_fields where model = 'res.partner' and name = 'payment_term'")
104
105 cr.commit()
106
107 # ------------------------ #
108 # remove duplicate reports #
109 # ------------------------ #
110
111 cr.execute("select model, report_name from ir_act_report_xml group by model, report_name having count(*)>1")
112 reports_wh_duplicates = cr.dictfetchall()
113
114 cr.execute("select res_id from ir_model_data where model='ir.actions.report.xml'")
115 registered_reports = cr.fetchall()
116 reg_reports_ids = ','.join([str(id) for (id,) in registered_reports])
117
118 for report in reports_wh_duplicates:
119     cr.execute("select id from ir_act_report_xml where model=%s and report_name=%s and id not in ("+reg_reports_ids+")", (report['model'], report['report_name']))
120     (id,) = cr.fetchone()
121     cr.execute("delete from ir_act_report_xml where id=%d", (id,))
122     cr.execute("delete from ir_values where value='ir.actions.report.xml,%d'", (id,))
123
124 cr.commit()
125
126 # ------------------------------------- #
127 # remove duplicate workflow transitions #
128 # ------------------------------------- #
129
130 # this removes all transitions which are not registered in ir_model_data
131
132 cr.execute("delete from wkf_transition where id not in (select res_id from ir_model_data where model='workflow.transition')")
133 cr.commit()
134
135 # -------------------------------- #
136 # remove bad "default" menu action #
137 # -------------------------------- #
138
139 cr.execute("delete from ir_values where key='action' and model='ir.ui.menu' and res_id is null")
140 cr.commit()
141
142 cr.close()
143
144
145 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
146