bank-payment/account_banking_mandate/migrations/14.0.1.0.0/post-migrate.py

31 lines
922 B
Python
Raw Normal View History

2021-03-12 16:21:19 +00:00
# Copyright 2021 Opener B.V. - Stefan Rijnhart <stefan@opener.amsterdam>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
from flectra.tools.sql import column_exists
def migrate(cr, version):
logger = logging.getLogger(
"flectra.addons.account_banking_mandate.migrations.14.0.1.0.0"
)
if not column_exists(cr, "account_move_line", "mandate_id"):
logger.warning(
"Column account_move_line.mandate_id not found when "
"populating account_move.mandate_id"
)
return
logger.info(
"Populating account_move.mandate_id from obsolete "
"account_move_line.mandate_id"
)
cr.execute(
"""
UPDATE account_move am
SET mandate_id = aml.mandate_id
FROM account_move_line aml
WHERE aml.mandate_id IS NOT NULL
AND am.mandate_id IS NULL
"""
)