
- Mantener campo value_selection como Char con validación - Remover campos y métodos no utilizados (value_selection_field, _get_selection_values) - Mostrar opciones disponibles debajo del campo para guiar al usuario - La validación se mantiene en el constraint para asegurar valores válidos
100 lines
3.4 KiB
Python
100 lines
3.4 KiB
Python
import odoo
|
|
import json
|
|
|
|
def verify_selection_fix(cr):
|
|
"""Verify that the selection widget fix is working correctly."""
|
|
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
|
|
|
|
print("="*80)
|
|
print("VERIFYING SELECTION WIDGET FIX")
|
|
print("="*80)
|
|
|
|
# 1. Find a parameter with selection type
|
|
param = env['lims.analysis.parameter'].search([
|
|
('value_type', '=', 'selection'),
|
|
('selection_values', '!=', False)
|
|
], limit=1)
|
|
|
|
if not param:
|
|
print("ERROR: No selection parameters found!")
|
|
return
|
|
|
|
print(f"\nUsing parameter: {param.name} (ID: {param.id})")
|
|
print(f"Selection values: {param.selection_values}")
|
|
print(f"get_selection_list(): {param.get_selection_list()}")
|
|
|
|
# 2. Create a test and result
|
|
print("\n\nCreating test data...")
|
|
|
|
# Get a patient
|
|
patient = env['res.partner'].search([('is_patient', '=', True)], limit=1)
|
|
if not patient:
|
|
print("ERROR: No patient found!")
|
|
return
|
|
|
|
# Create a test
|
|
test = env['lims.test'].create({
|
|
'name': 'Test Selection Widget',
|
|
'patient_id': patient.id,
|
|
'analysis_id': param.analysis_id.id if param.analysis_id else False,
|
|
})
|
|
print(f"Created test: {test.name} (ID: {test.id})")
|
|
|
|
# Create a result
|
|
result = env['lims.result'].create({
|
|
'test_id': test.id,
|
|
'parameter_id': param.id,
|
|
})
|
|
print(f"Created result: ID {result.id}")
|
|
|
|
# 3. Check the selection field
|
|
print("\n\nChecking selection field...")
|
|
print(f"Parameter value type: {result.parameter_value_type}")
|
|
print(f"Selection options display: {result.selection_options_display}")
|
|
|
|
# Get selection options through the method
|
|
options = result._get_selection_options()
|
|
print(f"\n_get_selection_options() returns: {options}")
|
|
|
|
# 4. Test setting a value
|
|
if options and len(options) > 1: # Skip the empty option
|
|
test_value = options[1][0] # Get the key of the first real option
|
|
print(f"\nTesting with value: '{test_value}'")
|
|
|
|
result.value_selection_field = test_value
|
|
print(f"Set value_selection_field = '{test_value}'")
|
|
print(f"After onchange, value_selection = '{result.value_selection}'")
|
|
print(f"Value display: '{result.value_display}'")
|
|
|
|
# Save and check
|
|
cr.commit()
|
|
|
|
# Re-read
|
|
result = env['lims.result'].browse(result.id)
|
|
print(f"\nAfter save and re-read:")
|
|
print(f" value_selection_field: '{result.value_selection_field}'")
|
|
print(f" value_selection: '{result.value_selection}'")
|
|
print(f" value_display: '{result.value_display}'")
|
|
|
|
# 5. Check field definition
|
|
print("\n\nChecking field definitions...")
|
|
Result = env['lims.result']
|
|
|
|
if 'value_selection_field' in Result._fields:
|
|
field = Result._fields['value_selection_field']
|
|
print(f"value_selection_field:")
|
|
print(f" Type: {field.type}")
|
|
print(f" String: {field.string}")
|
|
print(f" Selection: {field.selection if hasattr(field, 'selection') else 'N/A'}")
|
|
else:
|
|
print("ERROR: value_selection_field not found in model!")
|
|
|
|
print("\n" + "="*80)
|
|
print("VERIFICATION COMPLETE")
|
|
print("="*80)
|
|
|
|
if __name__ == '__main__':
|
|
db_name = 'lims_demo'
|
|
registry = odoo.registry(db_name)
|
|
with registry.cursor() as cr:
|
|
verify_selection_fix(cr) |