77
88from cerberus import Validator
99
10- from odoo import _ , http
10+ from odoo import http
1111from odoo .exceptions import UserError , ValidationError
1212
1313from .tools import ROUTING_DECORATOR_ATTR , cerberus_to_json
@@ -218,13 +218,13 @@ def from_params(self, service, params):
218218 validator = self .get_cerberus_validator (service , "input" )
219219 if validator .validate (params ):
220220 return validator .document
221- raise UserError (_ ("BadRequest %s" ) % validator .errors )
221+ raise UserError (service . env . _ ("BadRequest %s" ) % validator .errors )
222222
223223 def to_response (self , service , result ):
224224 validator = self .get_cerberus_validator (service , "output" )
225225 if validator .validate (result ):
226226 return validator .document
227- raise SystemError (_ ("Invalid Response %s" ) % validator .errors )
227+ raise SystemError (service . env . _ ("Invalid Response %s" ) % validator .errors )
228228
229229 def to_openapi_query_parameters (self , service , spec ):
230230 json_schema = self .to_json_schema (service , spec , "input" )
@@ -275,7 +275,9 @@ def get_cerberus_validator(self, service, direction):
275275 return schema
276276 if isinstance (schema , dict ):
277277 return Validator (schema , purge_unknown = True )
278- raise Exception (_ ("Unable to get cerberus schema from %s" ) % self ._schema )
278+ raise Exception (
279+ service .env ._ ("Unable to get cerberus schema from %s" ) % self ._schema
280+ )
279281
280282 def to_json_schema (self , service , spec , direction ):
281283 schema = self .get_cerberus_validator (service , direction ).schema
@@ -321,7 +323,7 @@ def _do_validate(self, service, data, direction):
321323 for idx , p in enumerate (data ):
322324 if not validator .validate (p ):
323325 raise ExceptionClass (
324- _ (
326+ service . env . _ (
325327 "BadRequest item %(idx)s :%(errors)s" ,
326328 idx = idx ,
327329 errors = validator .errors ,
@@ -330,7 +332,7 @@ def _do_validate(self, service, data, direction):
330332 values .append (validator .document )
331333 if self ._min_items is not None and len (values ) < self ._min_items :
332334 raise ExceptionClass (
333- _ (
335+ service . env . _ (
334336 "BadRequest: Not enough items in the list (%(current)s "
335337 "< %(expected)s)" ,
336338 current = len (values ),
@@ -339,7 +341,7 @@ def _do_validate(self, service, data, direction):
339341 )
340342 if self ._max_items is not None and len (values ) > self ._max_items :
341343 raise ExceptionClass (
342- _ (
344+ service . env . _ (
343345 "BadRequest: Too many items in the list (%(current)s "
344346 "> %(expected)s)" ,
345347 current = len (values ),
@@ -367,7 +369,7 @@ def __init__(self, parts):
367369 :param parts: list of RestMethodParam
368370 """
369371 if not isinstance (parts , dict ):
370- raise ValidationError ( _ ( "You must provide a dict of RestMethodParam" ) )
372+ raise RuntimeError ( "You must provide a dict of RestMethodParam" )
371373 self ._parts = parts
372374
373375 def to_openapi_properties (self , service , spec , direction ):
@@ -410,7 +412,7 @@ def from_params(self, service, params):
410412 ) # multipart ony sends its parts as string
411413 except json .JSONDecodeError as error :
412414 raise ValidationError (
413- _ (f"{ key } 's JSON content is malformed: { error } " )
415+ service . env . _ (f"{ key } 's JSON content is malformed: { error } " )
414416 ) from error
415417 param = part .from_params (service , json_param )
416418 params [key ] = param
0 commit comments