diff --git a/yuthon_official/__manifest__.py b/yuthon_official/__manifest__.py index 421d9fa34..aee8674d9 100644 --- a/yuthon_official/__manifest__.py +++ b/yuthon_official/__manifest__.py @@ -8,7 +8,7 @@ 'author': 'pengyuthon', 'website': 'https://www.pengyuthon.com', 'category': 'Human Resources/Attendances', - 'version': '0.1', + 'version': '17.0.0.2', 'license': 'LGPL-3', 'depends': ['mail', 'hr', 'soong_workflow', 'room', 'yuthon_issue', 'yuthon_trade'], 'data': [ diff --git a/yuthon_official/migrations/17.0.0.2/pre-migrate.py b/yuthon_official/migrations/17.0.0.2/pre-migrate.py new file mode 100644 index 000000000..b32f92b7c --- /dev/null +++ b/yuthon_official/migrations/17.0.0.2/pre-migrate.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# 迁移脚本:修复 yuthon.official.party 主送单位 Many2many 字段列名错误 +# 旧的字段定义少了个逗号,导致 column1 变成 'official_idflat_id' +# 新版本修正为 'official_id',需要先重命名旧列 + +def migrate(cr, version): + # 检查关系表是否存在 + cr.execute(""" + SELECT EXISTS ( + SELECT FROM information_schema.tables + WHERE table_name = 'yuthon_official_party_main_flats_rel' + ) + """) + if not cr.fetchone()[0]: + return + + # 检查是否有旧的错误列名 + cr.execute(""" + SELECT column_name FROM information_schema.columns + WHERE table_name = 'yuthon_official_party_main_flats_rel' + """) + cols = [r[0] for r in cr.fetchall()] + + if 'official_idflat_id' in cols: + # 旧列存在,创建正确的新列并迁移数据 + cr.execute("ALTER TABLE yuthon_official_party_main_flats_rel ADD COLUMN IF NOT EXISTS official_id INTEGER") + cr.execute("ALTER TABLE yuthon_official_party_main_flats_rel ADD COLUMN IF NOT EXISTS flat_id INTEGER") + cr.execute(""" + UPDATE yuthon_official_party_main_flats_rel + SET official_id = official_idflat_id::integer + WHERE official_idflat_id IS NOT NULL + """) + # 删除旧列 + cr.execute("ALTER TABLE yuthon_official_party_main_flats_rel DROP COLUMN IF EXISTS official_idflat_id") + # 删除可能存在的旧 yuthon_official_party_main_flats_rel_id 自动列 + cr.execute(""" + SELECT column_name FROM information_schema.columns + WHERE table_name = 'yuthon_official_party_main_flats_rel' + AND column_name LIKE '%rel_id' + """) + for row in cr.fetchall(): + cr.execute(f'ALTER TABLE yuthon_official_party_main_flats_rel DROP COLUMN IF EXISTS "{row[0]}"')