mirror of
https://github.com/brain-tec/account_ebics.git
synced 2025-08-14 06:35:36 +00:00
account_ebics - mulit-company fix company_ids field
This commit is contained in:
54
account_ebics/migrations/15.0.1.1/pre-migration.py
Normal file
54
account_ebics/migrations/15.0.1.1/pre-migration.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# Copyright 2009-2022 Noviat.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
if not version:
|
||||
return
|
||||
|
||||
cr.execute("select id from ebics_config")
|
||||
cfg_ids = [x[0] for x in cr.fetchall()]
|
||||
for cfg_id in cfg_ids:
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT aj.company_id
|
||||
FROM account_journal_ebics_config_rel rel
|
||||
JOIN account_journal aj ON rel.account_journal_id = aj.id
|
||||
WHERE ebics_config_id = %s
|
||||
""",
|
||||
(cfg_id,),
|
||||
)
|
||||
new_cpy_ids = [x[0] for x in cr.fetchall()]
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT res_company_id
|
||||
FROM ebics_config_res_company_rel
|
||||
WHERE ebics_config_id = %s
|
||||
""",
|
||||
(cfg_id,),
|
||||
)
|
||||
old_cpy_ids = [x[0] for x in cr.fetchall()]
|
||||
|
||||
to_add = []
|
||||
for cid in new_cpy_ids:
|
||||
if cid in old_cpy_ids:
|
||||
old_cpy_ids.remove(cid)
|
||||
else:
|
||||
to_add.append(cid)
|
||||
if old_cpy_ids:
|
||||
cr.execute(
|
||||
"""
|
||||
DELETE FROM ebics_config_res_company_rel
|
||||
WHERE res_company_id IN %s
|
||||
""",
|
||||
(tuple(old_cpy_ids),),
|
||||
)
|
||||
if to_add:
|
||||
for cid in to_add:
|
||||
cr.execute(
|
||||
"""
|
||||
INSERT INTO ebics_config_res_company_rel(ebics_config_id, res_company_id)
|
||||
VALUES (%s, %s);
|
||||
""",
|
||||
(cfg_id, cid),
|
||||
)
|
Reference in New Issue
Block a user