7
7
8
8
from cerberus import Validator
9
9
10
- from odoo import _ , http
10
+ from odoo import http
11
11
from odoo .exceptions import UserError , ValidationError
12
12
13
13
from .tools import ROUTING_DECORATOR_ATTR , cerberus_to_json
@@ -218,13 +218,13 @@ def from_params(self, service, params):
218
218
validator = self .get_cerberus_validator (service , "input" )
219
219
if validator .validate (params ):
220
220
return validator .document
221
- raise UserError (_ ("BadRequest %s" ) % validator .errors )
221
+ raise UserError (service . env . _ ("BadRequest %s" ) % validator .errors )
222
222
223
223
def to_response (self , service , result ):
224
224
validator = self .get_cerberus_validator (service , "output" )
225
225
if validator .validate (result ):
226
226
return validator .document
227
- raise SystemError (_ ("Invalid Response %s" ) % validator .errors )
227
+ raise SystemError (service . env . _ ("Invalid Response %s" ) % validator .errors )
228
228
229
229
def to_openapi_query_parameters (self , service , spec ):
230
230
json_schema = self .to_json_schema (service , spec , "input" )
@@ -275,7 +275,9 @@ def get_cerberus_validator(self, service, direction):
275
275
return schema
276
276
if isinstance (schema , dict ):
277
277
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
+ )
279
281
280
282
def to_json_schema (self , service , spec , direction ):
281
283
schema = self .get_cerberus_validator (service , direction ).schema
@@ -321,7 +323,7 @@ def _do_validate(self, service, data, direction):
321
323
for idx , p in enumerate (data ):
322
324
if not validator .validate (p ):
323
325
raise ExceptionClass (
324
- _ (
326
+ service . env . _ (
325
327
"BadRequest item %(idx)s :%(errors)s" ,
326
328
idx = idx ,
327
329
errors = validator .errors ,
@@ -330,7 +332,7 @@ def _do_validate(self, service, data, direction):
330
332
values .append (validator .document )
331
333
if self ._min_items is not None and len (values ) < self ._min_items :
332
334
raise ExceptionClass (
333
- _ (
335
+ service . env . _ (
334
336
"BadRequest: Not enough items in the list (%(current)s "
335
337
"< %(expected)s)" ,
336
338
current = len (values ),
@@ -339,7 +341,7 @@ def _do_validate(self, service, data, direction):
339
341
)
340
342
if self ._max_items is not None and len (values ) > self ._max_items :
341
343
raise ExceptionClass (
342
- _ (
344
+ service . env . _ (
343
345
"BadRequest: Too many items in the list (%(current)s "
344
346
"> %(expected)s)" ,
345
347
current = len (values ),
@@ -367,7 +369,7 @@ def __init__(self, parts):
367
369
:param parts: list of RestMethodParam
368
370
"""
369
371
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" )
371
373
self ._parts = parts
372
374
373
375
def to_openapi_properties (self , service , spec , direction ):
@@ -410,7 +412,7 @@ def from_params(self, service, params):
410
412
) # multipart ony sends its parts as string
411
413
except json .JSONDecodeError as error :
412
414
raise ValidationError (
413
- _ (f"{ key } 's JSON content is malformed: { error } " )
415
+ service . env . _ (f"{ key } 's JSON content is malformed: { error } " )
414
416
) from error
415
417
param = part .from_params (service , json_param )
416
418
params [key ] = param
0 commit comments