1313
1414import requests
1515
16- from odoo import _ , api , fields , models
16+ from odoo import api , fields , models
1717from odoo .exceptions import UserError
1818from odoo .tools import ustr
1919from odoo .tools .float_utils import float_is_zero , float_round
@@ -95,10 +95,12 @@ def _atc_get_messages(self):
9595 messages = []
9696 partner_company = self .company_id .partner_id
9797 if not partner_company .street :
98- messages .append (_ ("- The company %s has no street" ) % partner_company .name )
98+ messages .append (
99+ self .env ._ ("- The company %s has no street" , partner_company .name )
100+ )
99101 if not partner_company .zip :
100102 messages .append (
101- _ ("- The company %s has no zip code" ) % partner_company .name
103+ self . env . _ ("- The company %s has no zip code" , partner_company .name )
102104 )
103105 return messages
104106
@@ -109,14 +111,16 @@ def _atc_validate_fields(self):
109111 messages = self ._atc_get_messages ()
110112 if messages :
111113 raise UserError (
112- _ ("Please fix the following errors:\n %s" ) % "\n " .join (messages )
114+ self . env . _ ("Please fix the following errors:\n %s" , "\n " .join (messages ) )
113115 )
114116
115117 def _atc_get_country_state_code (self , country_state ):
116118 codigo_provincia = SPANISH_STATES .get (country_state .code )
117119 if not codigo_provincia :
118120 raise UserError (
119- _ ("The state code is not mapped for state: %s" , country_state .code )
121+ self .env ._ (
122+ "The state code is not mapped for state: %s" , country_state .code
123+ )
120124 )
121125 return codigo_provincia
122126
@@ -145,14 +149,19 @@ def _atc_run_cmd(self, report_name, filename, jar_filename, main_class):
145149 )
146150 if result .returncode != 0 :
147151 raise UserError (
148- f"Error al generar el modelo:\n "
149- f"Código de salida: { result .returncode } \n "
150- f"STDOUT:\n { result .stdout } \n "
151- f"STDERR:\n { result .stderr } "
152+ self .env ._ (
153+ "Error al generar el modelo:\n "
154+ "Código de salida: %(returncode)s\n "
155+ "STDOUT:\n %(stdout)s\n "
156+ "STDERR:\n %(stderr)s" ,
157+ returncode = result .returncode ,
158+ stdout = result .stdout ,
159+ stderr = result .stderr ,
160+ )
152161 )
153162 except Exception as e :
154163 raise UserError (
155- _ ( f "Excepción durante la ejecución del comando:\n { ustr (e )} " )
164+ self . env . _ ( "Excepción durante la ejecución del comando:\n %s" , ustr (e ))
156165 ) from e
157166 # check if there are errors
158167 if os .path .exists (dir_paths ["errores_path" ]):
@@ -161,7 +170,7 @@ def _atc_run_cmd(self, report_name, filename, jar_filename, main_class):
161170 errores = f .read ()
162171 if errores :
163172 raise UserError (
164- _ (
173+ self . env . _ (
165174 "No se pudo generar el archivo. Errores encontrados:\n %s" ,
166175 errores ,
167176 )
@@ -233,7 +242,7 @@ def _get_or_download_atc_jar(self, jar_filename, timeout=60):
233242 url = ATC_JAR_URL .get (self ._aeat_number )
234243 if not url :
235244 raise UserError (
236- _ (
245+ self . env . _ (
237246 "Please configure the JAR URL for %s "
238247 "by inheriting the variable `ATC_JAR_URL`." ,
239248 self ._aeat_number ,
@@ -275,7 +284,7 @@ def _get_or_download_atc_jar(self, jar_filename, timeout=60):
275284 response .raise_for_status ()
276285 except Exception as error :
277286 raise UserError (
278- _ (
287+ self . env . _ (
279288 "Error downloading the jar file from: %(url)s\n %(error)s" ,
280289 url = url ,
281290 error = ustr (error ),
@@ -284,7 +293,9 @@ def _get_or_download_atc_jar(self, jar_filename, timeout=60):
284293 content = response .content
285294 if not content :
286295 raise UserError (
287- _ ("The HTTP response from %(url)s is empty (no content)" , url = url )
296+ self .env ._ (
297+ "The HTTP response from %(url)s is empty (no content)" , url = url
298+ )
288299 )
289300 jar_content = None
290301 with contextlib .suppress (zipfile .BadZipFile ):
@@ -295,7 +306,7 @@ def _get_or_download_atc_jar(self, jar_filename, timeout=60):
295306 break
296307 if not jar_content :
297308 raise UserError (
298- _ (
309+ self . env . _ (
299310 "The jar file: %(jar_filename)s "
300311 "is not present in the zip file downloaded from: %(url)s" ,
301312 jar_filename = jar_filename ,
@@ -325,7 +336,7 @@ def _atc_get_report_data(self, dir_paths, file_name):
325336 file_path
326337 ):
327338 raise UserError (
328- _ (
339+ self . env . _ (
329340 "Declaracion no generada. Revisa si el XML es válido y "
330341 "los parámetros correctos."
331342 )
0 commit comments