
- 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.
132 lines
4.9 KiB
Python
132 lines
4.9 KiB
Python
import odoo
|
|
import json
|
|
|
|
def diagnose_selection_issue(cr):
|
|
"""Diagnose why selection widget shows 'Sin Opciones'"""
|
|
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
|
|
|
|
print("="*80)
|
|
print("DIAGNOSING SELECTION WIDGET ISSUE")
|
|
print("="*80)
|
|
|
|
# 1. Check the specific test and parameter
|
|
test_id = 33
|
|
result_id = 43
|
|
|
|
# Get the test
|
|
test = env['lims.test'].browse(test_id)
|
|
if not test:
|
|
print(f"\nERROR: Test with ID {test_id} not found!")
|
|
return
|
|
|
|
print(f"\nTest: {test.name} (ID: {test.id})")
|
|
print(f"Category: {test.category_id.name}")
|
|
|
|
# Check parameters with selection type
|
|
selection_params = test.parameter_ids.filtered(lambda p: p.value_type == 'selection')
|
|
print(f"\nParameters with selection type: {len(selection_params)}")
|
|
|
|
for param in selection_params:
|
|
print(f"\n--- Parameter: {param.name} (ID: {param.id}) ---")
|
|
print(f"Value Type: {param.value_type}")
|
|
print(f"Selection Values (raw field): '{param.selection_values}'")
|
|
print(f"Selection Values (type): {type(param.selection_values)}")
|
|
print(f"Selection Values (bool): {bool(param.selection_values)}")
|
|
|
|
# Test get_selection_list method
|
|
try:
|
|
selection_list = param.get_selection_list()
|
|
print(f"\nget_selection_list() result:")
|
|
print(f" Type: {type(selection_list)}")
|
|
print(f" Content: {selection_list}")
|
|
print(f" Length: {len(selection_list) if isinstance(selection_list, list) else 'N/A'}")
|
|
except Exception as e:
|
|
print(f"\nERROR calling get_selection_list(): {str(e)}")
|
|
|
|
# 2. Check the specific result
|
|
result = env['lims.result'].browse(result_id)
|
|
if not result:
|
|
print(f"\n\nERROR: Result with ID {result_id} not found!")
|
|
return
|
|
|
|
print(f"\n\n--- Result Analysis (ID: {result_id}) ---")
|
|
print(f"Test: {result.test_id.name}")
|
|
print(f"Parameter: {result.parameter_id.name}")
|
|
print(f"Parameter Value Type: {result.parameter_id.value_type}")
|
|
|
|
# Check computed field
|
|
print(f"\nComputed field 'selection_options': {result.selection_options}")
|
|
|
|
# Manually test _get_selection_options
|
|
try:
|
|
# Clear cache to force recomputation
|
|
result.invalidate_recordset(['selection_options'])
|
|
|
|
# Access the field to trigger computation
|
|
options = result.selection_options
|
|
print(f"\nAfter invalidating cache:")
|
|
print(f" selection_options: {options}")
|
|
print(f" Type: {type(options)}")
|
|
except Exception as e:
|
|
print(f"\nERROR accessing selection_options: {str(e)}")
|
|
|
|
# 3. Direct method test
|
|
print(f"\n\n--- Direct Method Tests ---")
|
|
|
|
# Test parameter's get_selection_list directly
|
|
if result.parameter_id.value_type == 'selection':
|
|
param = result.parameter_id
|
|
print(f"\nParameter: {param.name}")
|
|
print(f"Selection Values: '{param.selection_values}'")
|
|
|
|
# Test parsing
|
|
if param.selection_values:
|
|
lines = param.selection_values.strip().split('\n')
|
|
print(f"\nParsing test:")
|
|
print(f" Lines after split: {lines}")
|
|
print(f" Number of lines: {len(lines)}")
|
|
|
|
parsed_options = []
|
|
for line in lines:
|
|
line = line.strip()
|
|
if line:
|
|
if '|' in line:
|
|
parts = line.split('|', 1)
|
|
if len(parts) == 2:
|
|
parsed_options.append((parts[0].strip(), parts[1].strip()))
|
|
else:
|
|
parsed_options.append((line, line))
|
|
|
|
print(f"\n Parsed options: {parsed_options}")
|
|
|
|
# 4. Check other results for the same test
|
|
print(f"\n\n--- Other Results for Test {test_id} ---")
|
|
other_results = env['lims.result'].search([('test_id', '=', test_id)], limit=5)
|
|
for res in other_results:
|
|
if res.parameter_id.value_type == 'selection':
|
|
print(f"\nResult ID: {res.id}")
|
|
print(f" Parameter: {res.parameter_id.name}")
|
|
print(f" Selection Options: {res.selection_options}")
|
|
print(f" Value: {res.value_text}")
|
|
|
|
# 5. Database check
|
|
print(f"\n\n--- Direct Database Check ---")
|
|
cr.execute("""
|
|
SELECT id, name, value_type, selection_values
|
|
FROM lims_parameter
|
|
WHERE value_type = 'selection'
|
|
AND id IN (SELECT parameter_id FROM lims_result WHERE id = %s)
|
|
""", (result_id,))
|
|
|
|
for row in cr.fetchall():
|
|
print(f"\nParameter ID: {row[0]}")
|
|
print(f" Name: {row[1]}")
|
|
print(f" Value Type: {row[2]}")
|
|
print(f" Selection Values: '{row[3]}'")
|
|
print(f" Selection Values (repr): {repr(row[3])}")
|
|
|
|
if __name__ == '__main__':
|
|
db_name = 'odoo'
|
|
registry = odoo.registry(db_name)
|
|
with registry.cursor() as cr:
|
|
diagnose_selection_issue(cr) |