From c959878a23259c99d7e34989a17e298bb2551c35 Mon Sep 17 00:00:00 2001 From: Luis Ernesto Portillo Zaldivar Date: Wed, 16 Jul 2025 19:57:33 -0600 Subject: [PATCH] =?UTF-8?q?fix(#67):=20Simplificar=20implementaci=C3=B3n?= =?UTF-8?q?=20de=20campo=20selection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- lims_management/models/lims_result.py | 21 ---- lims_management/views/lims_test_views.xml | 8 +- test/check_selection_issue.py | 101 +++++++++++++++++ test/create_test_selection_data.py | 132 ++++++++++++++++++++++ test/verify_selection_fix.py | 100 ++++++++++++++++ 5 files changed, 338 insertions(+), 24 deletions(-) create mode 100644 test/check_selection_issue.py create mode 100644 test/create_test_selection_data.py create mode 100644 test/verify_selection_fix.py diff --git a/lims_management/models/lims_result.py b/lims_management/models/lims_result.py index 9e2da51..b4a885f 100644 --- a/lims_management/models/lims_result.py +++ b/lims_management/models/lims_result.py @@ -92,17 +92,10 @@ class LimsResult(models.Model): string='Valor de Texto' ) - # Keep as Char but add domain validation value_selection = fields.Char( string='Valor de Selección' ) - # Add Selection field with dynamic options - value_selection_field = fields.Selection( - selection='_get_selection_options', - string='Valor de Selección' - ) - # Campo para mostrar las opciones disponibles selection_options_display = fields.Char( string='Opciones disponibles', @@ -321,7 +314,6 @@ class LimsResult(models.Model): self.value_numeric = False self.value_text = False self.value_selection = False - self.value_selection_field = False self.value_boolean = False # Si es selección, obtener las opciones @@ -329,19 +321,6 @@ class LimsResult(models.Model): # Esto se usará en las vistas para mostrar las opciones dinámicamente pass - @api.onchange('value_selection_field') - def _onchange_value_selection_field(self): - """Sincroniza el campo de selección con el campo char.""" - if self.parameter_value_type == 'selection': - self.value_selection = self.value_selection_field - - def _get_selection_options(self): - """Retorna las opciones de selección basadas en el parámetro.""" - options = [] - if self.parameter_id and self.parameter_value_type == 'selection': - param_options = self.parameter_id.get_selection_list() - options = [(opt, opt) for opt in param_options] - return options or [('', 'Sin opciones')] @api.depends('parameter_id', 'parameter_id.selection_values') def _compute_selection_options_display(self): diff --git a/lims_management/views/lims_test_views.xml b/lims_management/views/lims_test_views.xml index 1986aea..609dbff 100644 --- a/lims_management/views/lims_test_views.xml +++ b/lims_management/views/lims_test_views.xml @@ -88,16 +88,18 @@ + + placeholder="Seleccione una opción" + options="{'no_create': True, 'no_edit': True}"/> + widget="text" + style="font-size: 0.85em; color: #6c757d; margin-top: -5px;"/> 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) \ No newline at end of file