gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.6KB

  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. """The Odoo Exceptions module defines a few core exception types.
  4. Those types are understood by the RPC layer.
  5. Any other exception type bubbling until the RPC layer will be
  6. treated as a 'Server error'.
  7. .. note::
  8. If you consider introducing new exceptions,
  9. check out the :mod:`odoo.addons.test_exceptions` module.
  10. """
  11. class UserError(Exception):
  12. """Generic error managed by the client.
  13. Typically when the user tries to do something that has no sense given the current
  14. state of a record. Semantically comparable to the generic 400 HTTP status codes.
  15. """
  16. def __init__(self, message):
  17. """
  18. :param message: exception message and frontend modal content
  19. """
  20. super().__init__(message)
  21. class RedirectWarning(Exception):
  22. """ Warning with a possibility to redirect the user instead of simply
  23. displaying the warning message.
  24. :param str message: exception message and frontend modal content
  25. :param int action_id: id of the action where to perform the redirection
  26. :param str button_text: text to put on the button that will trigger
  27. the redirection.
  28. :param dict additional_context: parameter passed to action_id.
  29. Can be used to limit a view to active_ids for example.
  30. """
  31. def __init__(self, message, action, button_text, additional_context=None):
  32. super().__init__(message, action, button_text, additional_context)
  33. class AccessDenied(UserError):
  34. """Login/password error.
  35. .. note::
  36. No traceback.
  37. .. admonition:: Example
  38. When you try to log with a wrong password.
  39. """
  40. def __init__(self, message="Access Denied"):
  41. super().__init__(message)
  42. self.with_traceback(None)
  43. self.__cause__ = None
  44. self.traceback = ('', '', '')
  45. class AccessError(UserError):
  46. """Access rights error.
  47. .. admonition:: Example
  48. When you try to read a record that you are not allowed to.
  49. """
  50. class CacheMiss(KeyError):
  51. """Missing value(s) in cache.
  52. .. admonition:: Example
  53. When you try to read a value in a flushed cache.
  54. """
  55. def __init__(self, record, field):
  56. super().__init__("%r.%s" % (record, field.name))
  57. class MissingError(UserError):
  58. """Missing record(s).
  59. .. admonition:: Example
  60. When you try to write on a deleted record.
  61. """
  62. class ValidationError(UserError):
  63. """Violation of python constraints.
  64. .. admonition:: Example
  65. When you try to create a new user with a login which already exist in the db.
  66. """
上海开阖软件有限公司 沪ICP备12045867号-1