Skip to content

Commit 602a388

Browse files
committed
[IMP] base_tier_validation: Make validation_status field stored
This backports changes from OCA/18.0: - PR OCA#1138: Make validation_status field stored for better search performance - PR OCA#1139: Add migration script to prevent errors during upgrade Changes: * base_tier_validation: Add store=True to validation_status field * base_tier_validation: Add migration script to populate stored field * base_tier_validation_forward: Update test to use validation_status * Version bumps for both modules
1 parent 87fb61e commit 602a388

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

base_tier_validation/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Base Tier Validation",
55
"summary": "Implement a validation process based on tiers.",
6-
"version": "16.0.2.3.0",
6+
"version": "16.0.2.4.0",
77
"development_status": "Mature",
88
"maintainers": ["LoisRForgeFlow"],
99
"category": "Tools",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2025 OCA
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from openupgradelib import openupgrade
5+
6+
7+
def populate_validation_status_field(env):
8+
"""Populate the validation_status field for all existing tier validation records."""
9+
# Query to find all tables that have the validation_status column
10+
# This prevents errors when the field doesn't exist in some models
11+
env.cr.execute(
12+
"""
13+
SELECT table_name
14+
FROM information_schema.columns
15+
WHERE column_name = 'validation_status'
16+
AND table_schema = current_schema()
17+
"""
18+
)
19+
20+
tables_with_validation_status = [row[0] for row in env.cr.fetchall()]
21+
22+
for table_name in tables_with_validation_status:
23+
try:
24+
# Convert table name to model name (basic conversion)
25+
model_name = table_name.replace("_", ".")
26+
27+
# Check if the model exists in the registry
28+
if model_name in env.registry:
29+
model = env[model_name]
30+
31+
# Check if it inherits from tier.validation
32+
if hasattr(model, "_inherit") and "tier.validation" in (
33+
model._inherit
34+
if isinstance(model._inherit, list)
35+
else [model._inherit]
36+
):
37+
# Get records that need validation_status computation
38+
records = env[model_name].search([])
39+
if records:
40+
# Compute validation_status for all records in batches
41+
batch_size = 1000
42+
for i in range(0, len(records), batch_size):
43+
batch = records[i : i + batch_size]
44+
batch._compute_validation_status()
45+
env.cr.commit()
46+
47+
except Exception as e:
48+
# Log error but continue with other models to prevent migration failure
49+
openupgrade.logged_query(
50+
env.cr,
51+
f"-- Warning: Could not populate validation_status for "
52+
f"table {table_name}: {str(e)}",
53+
)
54+
55+
56+
@openupgrade.migrate()
57+
def migrate(env, version):
58+
"""Migrate validation_status field to be stored."""
59+
populate_validation_status_field(env)

base_tier_validation/models/tier_validation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class TierValidation(models.AbstractModel):
5858
],
5959
default="no",
6060
compute="_compute_validation_status",
61+
store=True,
6162
)
6263
reviewer_ids = fields.Many2many(
6364
string="Reviewers",

base_tier_validation_forward/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Base Tier Validation Forward",
55
"summary": "Forward option for base tiers",
6-
"version": "16.0.1.1.3",
6+
"version": "16.0.1.1.4",
77
"category": "Tools",
88
"website": "https://github.com/OCA/server-ux",
99
"author": "Ecosoft,Odoo Community Association (OCA)",

base_tier_validation_forward/tests/test_tier_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ def test_01_forward_tier(self):
131131
wizard.comment = "Forward tier is reviewed"
132132
wiz = wizard.save()
133133
wiz.add_comment()
134-
self.assertTrue(record.validated)
134+
self.assertEqual(record.validation_status, "validated")

0 commit comments

Comments
 (0)