Add migration field from 0.1 to 0.2

This commit is contained in:
Cyril Sester
2014-08-15 11:38:19 +02:00
parent 38a586173f
commit b4672a34c4
2 changed files with 50 additions and 1 deletions

View File

@@ -22,7 +22,7 @@
{
'name': 'Account Banking SEPA Direct Debit',
'summary': 'Create SEPA files for Direct Debit',
'version': '0.1',
'version': '0.2',
'license': 'AGPL-3',
'author': 'Akretion',
'website': 'http://www.akretion.com',

View File

@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Compassion CH (<http://www.compassion.ch>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
"""
This script covers the migration of the 0.1 to 0.2 version of sepa mandates.
As table names changed, we want to migrate values from sdd_mandate table to
newly created account_banking_mandate. We also copy foreign keys in invoice
and payment lines.
Finally, we remove useless fields (sdd_mandate_id) and obsolete table
(sdd_mandate).
"""
__name__ = "account.banking.sepa.direct_debit:: Move sdd_mandate data to account_banking_mandate"
def migrate(cr, installed_version):
query = "INSERT INTO account_banking_mandate " \
"SELECT id, create_uid, create_date, write_date, write_uid, " \
"partner_bank_id, last_debit_date, scan, company_id, state, " \
"unique_mandate_reference, signature_date, sepa_migrated, " \
"original_mandate_identification, recurrent_sequence_type, type " \
"FROM sdd_mandate"
cr.execute(query)
query2 = "UPDATE account_invoice SET mandate_id=sdd_mandate_id"
cr.execute(query2)
query3 = "UPDATE payment_line SET mandate_id=sdd_mandate_id"
cr.execute(query3)
query4 = "ALTER TABLE account_invoice DROP COLUMN IF EXISTS sdd_mandate_id"
cr.execute(query4)
query5 = "ALTER TABLE payment_line DROP COLUMN IF EXISTS sdd_mandate_id"
cr.execute(query5)
query6 = "DROP TABLE IF EXISTS sdd_mandate"
cr.execute(query6)