mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[FIX] Issue #228 Error when table to be migrated does not exist.
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
# 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
|
||||
@@ -35,26 +34,38 @@ def migrate(cr, installed_version):
|
||||
if not installed_version:
|
||||
return
|
||||
|
||||
query = "INSERT INTO account_banking_mandate " \
|
||||
"(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, "\
|
||||
def table_exists(cr, table):
|
||||
cr.execute(
|
||||
"SELECT 1 FROM information_schema.tables"
|
||||
" WHERE table_name='%s' LIMIT 1;" % table
|
||||
)
|
||||
return cr.fetchall() and True or False
|
||||
|
||||
if table_exists(cr, 'sdd_mandate'):
|
||||
query = (
|
||||
"INSERT INTO account_banking_mandate "
|
||||
"(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, "
|
||||
"scheme) "
|
||||
"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, "\
|
||||
"scheme) "\
|
||||
"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, "\
|
||||
"'CORE' "\
|
||||
"'CORE' "
|
||||
"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 CASCADE"
|
||||
cr.execute(query6)
|
||||
)
|
||||
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 CASCADE"
|
||||
cr.execute(query6)
|
||||
|
||||
Reference in New Issue
Block a user