2006-12-28 14:41:28 +00:00
##############################################################################
#
2008-06-16 11:00:21 +00:00
# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# $Id$
2006-12-28 14:41:28 +00:00
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
__author__ = ' Gaetan de Menten, <ged@tiny.be> '
__version__ = ' 0.1.0 '
import psycopg
import optparse
import ConfigParser
# -----
parser = optparse . OptionParser ( version = " Tiny ERP server migration script " + __version__ )
parser . add_option ( " -c " , " --config " , dest = " config " , help = " specify path to Tiny ERP config file " )
group = optparse . OptionGroup ( parser , " Database related options " )
group . add_option ( " --db_host " , dest = " db_host " , help = " specify the database host " )
group . add_option ( " --db_port " , dest = " db_port " , help = " specify the database port " )
group . add_option ( " -d " , " --database " , dest = " db_name " , help = " specify the database name " )
group . add_option ( " -r " , " --db_user " , dest = " db_user " , help = " specify the database user name " )
group . add_option ( " -w " , " --db_password " , dest = " db_password " , help = " specify the database password " )
parser . add_option_group ( group )
options = optparse . Values ( )
options . db_name = ' terp ' # default value
parser . parse_args ( values = options )
if hasattr ( options , ' config ' ) :
2008-07-22 14:24:36 +00:00
configparser = ConfigParser . ConfigParser ( )
configparser . read ( [ options . config ] )
for name , value in configparser . items ( ' options ' ) :
if not ( hasattr ( options , name ) and getattr ( options , name ) ) :
if value in ( ' true ' , ' True ' ) :
value = True
if value in ( ' false ' , ' False ' ) :
value = False
setattr ( options , name , value )
2006-12-28 14:41:28 +00:00
# -----
host = hasattr ( options , ' db_host ' ) and " host= %s " % options . db_host or ' '
port = hasattr ( options , ' db_port ' ) and " port= %s " % options . db_port or ' '
name = " dbname= %s " % options . db_name
user = hasattr ( options , ' db_user ' ) and " user= %s " % options . db_user or ' '
password = hasattr ( options , ' db_password ' ) and " password= %s " % options . db_password or ' '
db = psycopg . connect ( ' %s %s %s %s %s ' % ( host , port , name , user , password ) , serialize = 0 )
cr = db . cursor ( )
2006-12-29 07:33:56 +00:00
# ---------------------------------------------------------------- #
# move user id from hr_analytic_timesheet to account_analytic_line #
# ---------------------------------------------------------------- #
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 " )
cr . commit ( )
2006-12-28 14:41:28 +00:00
# --------------- #
# remove old menu #
# --------------- #
2007-02-07 15:44:53 +00:00
while True :
2008-07-22 14:24:36 +00:00
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 ' )) " )
if not cr . rowcount :
break
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 ' )) " )
2006-12-28 14:41:28 +00:00
cr . commit ( )
2007-01-17 07:14:15 +00:00
# ----------------------------------------- #
# add default value for discount in invoice #
# ----------------------------------------- #
cr . execute ( " update account_invoice_line set discount=0.0 where discount is null; " )
cr . commit ( )
2007-03-13 12:51:56 +00:00
# -------------------------------------------------------------------------- #
# update constraint account_invoice_line_uos_id_fkey on account_invoice_line #
# -------------------------------------------------------------------------- #
cr . execute ( " ALTER TABLE account_invoice_line DROP CONSTRAINT account_invoice_line_uos_id_fkey " )
cr . execute ( " ALTER TABLE account_invoice_line ADD FOREIGN KEY (uos_id) REFERENCES product_uom(id) ON DELETE SET NULL " )
cr . commit ( )
2007-03-14 11:09:42 +00:00
print """
WARNING : account_uos has been replaced by product_uom .
It is not possible to migrate the data automatically so you need to create the old account_uos in the new product_uom .
And then update the field uos_id of the table account_invoice to match the new id of product_uom .
EXAMPLE :
2008-07-22 14:24:36 +00:00
UPDATE account_invoice SET uos_id = new_id WHERE uos_id = old_id ;
2007-03-14 11:09:42 +00:00
"""
2006-12-28 14:41:28 +00:00
cr . close ( )