From 8c98e04be29fe91283d03d540f101d2d38daca50 Mon Sep 17 00:00:00 2001 From: Adri?n Bernardi Date: Fri, 1 Feb 2019 09:40:31 -0300 Subject: [PATCH] lims_instrument: "Load Results from File" wizard: improve error messages --- lims_instrument/locale/es.po | 20 ++++++++++++ lims_instrument/resultsimport.py | 31 ++++++++++++++----- .../notebook_load_results_file_empty_form.xml | 2 +- ...notebook_load_results_file_export_form.xml | 2 +- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/lims_instrument/locale/es.po b/lims_instrument/locale/es.po index b131803..d7ea839 100644 --- a/lims_instrument/locale/es.po +++ b/lims_instrument/locale/es.po @@ -2,6 +2,26 @@ msgid "" msgstr "Content-Type: text/plain; charset=utf-8\n" +msgctxt "error:lims.notebook.load_results_file:" +msgid "End date cannot be empty" +msgstr "La Fecha de finalización no puede estar vacía" + +msgctxt "error:lims.notebook.load_results_file:" +msgid "End date cannot be lower than Start date" +msgstr "La Fecha de finalización no puede ser menor que la Fecha de inicio" + +msgctxt "error:lims.notebook.load_results_file:" +msgid "Injection date cannot be lower than Start date" +msgstr "La Fecha de inyección no puede ser menor que la Fecha de inicio" + +msgctxt "error:lims.notebook.load_results_file:" +msgid "Injection date cannot be upper than End date" +msgstr "La Fecha de inyección no puede ser mayor que la Fecha de finalización" + +msgctxt "error:lims.notebook.load_results_file:" +msgid "Professional(s) with code %s not identified" +msgstr "Profesional(es) no identificado(s): %s" + msgctxt "error:lims.resultsimport:" msgid "No module for importer type \"%s\"" msgstr "No se ha definido un módulo para el importador \"%s\"" diff --git a/lims_instrument/resultsimport.py b/lims_instrument/resultsimport.py index 052655b..9fdb37b 100644 --- a/lims_instrument/resultsimport.py +++ b/lims_instrument/resultsimport.py @@ -299,6 +299,19 @@ class NotebookLoadResultsFile(Wizard): Button('Done', 'end', 'tryton-close', default=True), ]) + @classmethod + def __setup__(cls): + super(NotebookLoadResultsFile, cls).__setup__() + cls._error_messages.update({ + 'end_date': 'End date cannot be empty', + 'end_date_start_date': 'End date cannot be lower than Start date', + 'inj_date_start_date': ('Injection date cannot be lower than ' + 'Start date'), + 'inj_date_end_date': ('Injection date cannot be upper than ' + 'End date'), + 'professionals': 'Professional(s) with code %s not identified', + }) + def transition_collect(self): cursor = Transaction().connection.cursor() pool = Pool() @@ -476,19 +489,23 @@ class NotebookLoadResultsFile(Wizard): if line.imported_result != '-1000.0': if not line.imported_end_date: prevent_line = True - outcome = 'End date cannot be empty' + outcome = self.raise_user_error('end_date', + raise_exception=False) elif (line.imported_end_date and line.start_date and line.start_date > line.imported_end_date): prevent_line = True - outcome = 'End date cannot be lower than Start date' + outcome = self.raise_user_error('end_date_start_date', + raise_exception=False) elif (line.imported_inj_date and line.start_date and line.start_date > line.imported_inj_date): prevent_line = True - outcome = 'Injection date cannot be lower than Start date' + outcome = self.raise_user_error('inj_date_start_date', + raise_exception=False) elif (line.imported_end_date and line.imported_inj_date and line.imported_inj_date > line.imported_end_date): prevent_line = True - outcome = 'Injection date cannot be upper than End date' + outcome = self.raise_user_error('inj_date_end_date', + raise_exception=False) else: line.result = line.imported_result line.end_date = line.imported_end_date @@ -527,9 +544,9 @@ class NotebookLoadResultsFile(Wizard): outcome = msg else: prevent_line = True - outcome = ('Professional(s) with code ' - + unicode(line.imported_professionals) - + ' not identified') + outcome = self.raise_user_error('professionals', + (unicode(line.imported_professionals),), + raise_exception=False) if prevent_line: row_num = 0 diff --git a/lims_instrument/view/notebook_load_results_file_empty_form.xml b/lims_instrument/view/notebook_load_results_file_empty_form.xml index 8b40e14..752055e 100644 --- a/lims_instrument/view/notebook_load_results_file_empty_form.xml +++ b/lims_instrument/view/notebook_load_results_file_empty_form.xml @@ -1,6 +1,6 @@
- +