-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathpre-migration.py
More file actions
32 lines (27 loc) · 1.02 KB
/
pre-migration.py
File metadata and controls
32 lines (27 loc) · 1.02 KB
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
# © 2025 Solvos Consultoría Informática (<http://www.solvos.es>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from openupgradelib import openupgrade
_logger = logging.getLogger(__name__)
@openupgrade.migrate()
def migrate(env, version):
if not openupgrade.column_exists(env.cr, "sale_order", "invoice_plan_pending"):
openupgrade.add_columns(
env, [("sale_order", "invoice_plan_pending", "integer")]
)
_logger.info("Create invoice_plan_pending column in sale_order table.")
openupgrade.logged_query(
env.cr,
"""
UPDATE sale_order so
SET invoice_plan_pending = sub.count
FROM (
SELECT sale_id, COUNT(*) AS count
FROM sale_invoice_plan
WHERE NOT invoiced
GROUP BY sale_id
) AS sub
WHERE so.id = sub.sale_id;
""",
)
_logger.info("Updated invoice_plan_pending for existing sale orders.")