Add migration scripts to move files to attachments

This commit is contained in:
Alexis de Lattre
2015-06-01 20:58:21 +02:00
parent 6d55b29523
commit c5ba16e5ef
6 changed files with 166 additions and 2 deletions

View File

@@ -22,7 +22,7 @@
{
'name': 'Account Banking SEPA Credit Transfer',
'summary': 'Create SEPA XML files for Credit Transfers',
'version': '0.2',
'version': '0.3',
'license': 'AGPL-3',
'author': "Akretion, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "

View File

@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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/>.
#
##############################################################################
from openerp import pooler, SUPERUSER_ID
def migrate(cr, version):
if not version:
return
pool = pooler.get_pool(cr.dbname)
cr.execute('''
SELECT
old_sepa.file,
rel.account_order_id AS payment_order_id,
payment_order.reference
FROM migration_banking_export_sepa old_sepa
LEFT JOIN migration_account_payment_order_sepa_rel rel
ON old_sepa.id=rel.banking_export_sepa_id
LEFT JOIN payment_order ON payment_order.id=rel.account_order_id
''')
for sepa_file in cr.dictfetchall():
filename = 'sct_%s.xml' % sepa_file['reference'].replace('/', '-')
pool['ir.attachment'].create(
cr, SUPERUSER_ID, {
'name': filename,
'res_id': sepa_file['payment_order_id'],
'res_model': 'payment.order',
'datas': str(sepa_file['file']),
})
return

View File

@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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/>.
#
##############################################################################
def migrate(cr, version):
if not version:
return
cr.execute(
'ALTER TABLE banking_export_sepa '
'RENAME TO migration_banking_export_sepa')
cr.execute(
'ALTER TABLE account_payment_order_sepa_rel '
'RENAME TO migration_account_payment_order_sepa_rel')

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, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "

View File

@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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/>.
#
##############################################################################
from openerp import pooler, SUPERUSER_ID
def migrate(cr, version):
if not version:
return
pool = pooler.get_pool(cr.dbname)
cr.execute('''
SELECT
old_sepa.file,
rel.account_order_id AS payment_order_id,
payment_order.reference
FROM migration_banking_export_sdd old_sepa
LEFT JOIN migration_account_payment_order_sdd_rel rel
ON old_sepa.id=rel.banking_export_sepa_id
LEFT JOIN payment_order ON payment_order.id=rel.account_order_id
''')
for sepa_file in cr.dictfetchall():
filename = 'sdd_%s.xml' % sepa_file['reference'].replace('/', '-')
pool['ir.attachment'].create(
cr, SUPERUSER_ID, {
'name': filename,
'res_id': sepa_file['payment_order_id'],
'res_model': 'payment.order',
'datas': str(sepa_file['file']),
})
return

View File

@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 Akretion (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# 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/>.
#
##############################################################################
def migrate(cr, version):
if not version:
return
cr.execute(
'ALTER TABLE banking_export_sdd '
'RENAME TO migration_banking_export_sdd')
cr.execute(
'ALTER TABLE account_payment_order_sdd_rel '
'RENAME TO migration_account_payment_order_sdd_rel')