-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
hooks.py
37 lines (33 loc) · 1.04 KB
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from odoo.tools.sql import column_exists
_logger = logging.getLogger(__name__)
def pre_init_hook(cr):
"""Pre init hook."""
# add columns for computed fields to avoid useless computation by the ORM
# when installing the module
if column_exists(cr, "ir_attachment", "fs_storage_id"):
return # columns already added; update probably failed partway
_logger.info("Add columns for computed fields on ir_attachment")
cr.execute(
"""
ALTER TABLE ir_attachment
ADD COLUMN fs_storage_id INTEGER;
ALTER TABLE ir_attachment
ADD FOREIGN KEY (fs_storage_id) REFERENCES fs_storage(id);
"""
)
cr.execute(
"""
ALTER TABLE ir_attachment
ADD COLUMN fs_url VARCHAR;
"""
)
cr.execute(
"""
ALTER TABLE ir_attachment
ADD COLUMN fs_storage_code VARCHAR;
"""
)
_logger.info("Columns added on ir_attachment")