AttributeError: type object ‘gnuhealth.emergency.registration’ has no attribute ‘raise_user_error’

hi! I am facing this error when I create @classmethod. the below is the example of an error.

Traceback (most recent call last):
  File "/trytond/", line 117, in dispatch_request
    return endpoint(request, **request.view_args)
  File "/trytond/protocols/", line 46, in rpc
    return methods.get(request.rpc_method, _dispatch)(
  File "/trytond/", line 84, in auth_required
    return wrapped(*args, **kwargs)
  File "/trytond/protocols/", line 170, in wrapper
    return func(request, pool, *args, **kwargs)
  File "/trytond/protocols/", line 180, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
  File "/trytond/model/", line 775, in wrapper
    return func(cls, records, *args, **kwargs)
  File "/trytond/modules/health_proc/", line 953, in dischargenursing
    cls.raise_user_error('Final Discharge can only be done after Financial Clearance or if the patient has already been finally discharged.')
AttributeError: type object 'gnuhealth.emergency.registration' has no attribute 'raise_user_error'

Fault: type object 'gnuhealth.emergency.registration' has no attribute 'raise_user_error'

plz someone guide me how can I fix this.

    def dischargefinancial(cls, registrations):
        registration_id = registrations[0]

        if registration_id.state != 'done':
            cls.raise_user_error('Financial clearance process can only be started after Discharge by Attending Physician')

        if not registration_id.final_invoice_id:
            cls.raise_user_error('Please prepare the invoice first in order to give financial clearance')

raise_user_error method has been removed since Tryton 5.2 (6 years ago), see Generalize error message (#3672) · Issues · Tryton / Tryton · GitLab

is there any alternate function??

There are plenty of examples of what those functions got changed to in the link that @ced provided.

You will probably want to create a new exception class based on UserError (Exceptions — Tryton server) and raise that.

Possibly something a bit like:

class DischargeError(UserError):


def dischargefinancial(...):
    if not registration_id.final_invoice_id:
        raise DischargeError(gettext(