
- Add new Selection field 'value_selection_field' with dynamic options - Update views to use the new field instead of char field with selection widget - Add migration script to copy existing data from old field to new field - Update field synchronization and validation logic - Increment module version to trigger migration The issue was that Odoo doesn't support using widget='selection' on Char fields. The solution implements a proper Selection field with dynamic options based on the parameter configuration.
26 lines
930 B
Python
26 lines
930 B
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, SUPERUSER_ID
|
|
|
|
def migrate(cr, version):
|
|
"""Migrate existing selection values from char field to selection field."""
|
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
|
|
|
# Find all results with selection parameters that have values
|
|
results = env['lims.result'].search([
|
|
('parameter_value_type', '=', 'selection'),
|
|
('value_selection', '!=', False),
|
|
('value_selection', '!=', '')
|
|
])
|
|
|
|
if results:
|
|
cr.execute("""
|
|
UPDATE lims_result
|
|
SET value_selection_field = value_selection
|
|
WHERE id IN %s
|
|
AND parameter_value_type = 'selection'
|
|
AND value_selection IS NOT NULL
|
|
AND value_selection != ''
|
|
""", (tuple(results.ids),))
|
|
|
|
# Log migration
|
|
print(f"Migrated {len(results)} selection values from value_selection to value_selection_field") |