changeset 5010:754c5341bbb7

health_services_lab: migrate raise_user_error methods
author Luis Falcon <falcon@gnuhealth.org>
date Mon, 24 Jan 2022 14:18:32 +0000
parents ac497c880320
children 207199fdff57
files tryton/health_services_lab/data/messages/messages.xml tryton/health_services_lab/exceptions.py tryton/health_services_lab/health_services_lab.py
diffstat 3 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/tryton/health_services_lab/data/messages/messages.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<!-- This file is part of GNU Health.  The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<tryton>
+    <data grouped="1">
+        <record model="ir.message" id="msg_no_service_associated">
+            <field name="text">SM-SERVICES_LAB-0001: Need to associate a service</field>
+        </record>
+    </data>
+</tryton>
new file mode 100644
--- /dev/null
+++ b/tryton/health_services_lab/exceptions.py
@@ -0,0 +1,10 @@
+# This file is part of GNU Health.  The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+from trytond.exceptions import UserError
+from trytond.model.exceptions import ValidationError
+
+
+class NoServiceAssociated(UserError):
+    pass
+
+
--- a/tryton/health_services_lab/health_services_lab.py
+++ b/tryton/health_services_lab/health_services_lab.py
@@ -24,6 +24,7 @@
 from trytond.pyson import Eval, Equal
 from trytond.pool import Pool
 
+from .exceptions import (NoServiceAssociated)
 
 __all__ = ['PatientLabTestRequest']
 
@@ -61,7 +62,9 @@
         laborder = laborders[0]
 
         if not laborder.service:
-            cls.raise_user_error("Need to associate a service !")
+            raise NoServiceAssociated(
+                gettext('health_services_lab.msg_no_service_associated')
+                )
 
         service_data = {}
         service_lines = []