@@ -87,7 +87,7 @@ def get_arba_file_data(
8787
8888 company = self .mapped ("company_id" )
8989 if len (company ) > 1 :
90- raise UserError (self .env ._ ("Los remitos seleccionados deben pertenecer a la misma " " compañía" ))
90+ raise UserError (self .env ._ ("Los remitos seleccionados deben pertenecer a la misma compañía" ))
9191 cuit = company .partner_id .ensure_vat ()
9292 cuit_carrier = carrier_partner .ensure_vat ()
9393
@@ -106,7 +106,7 @@ def get_arba_file_data(
106106 nro_secuencial = self .env ["ir.sequence" ].with_company (company ).next_by_code ("arba.cot.file" )
107107 if not nro_secuencial :
108108 raise UserError (
109- self .env ._ ('No sequence found for COT files (code = "arba.cot.file") on ' ' company "%s' , company .name )
109+ self .env ._ ('No sequence found for COT files (code = "arba.cot.file") on company "%s' , company .name )
110110 )
111111
112112 filename = "TB_%s_%s%s_%s_%s.txt" % (
@@ -136,7 +136,7 @@ def get_arba_file_data(
136136
137137 if not source_partner .state_id .code or not dest_partner .state_id .code :
138138 raise UserError (
139- self .env ._ ("Las provincias de origen y destino son obligatorias y " " deben tener un código válido" )
139+ self .env ._ ("Las provincias de origen y destino son obligatorias y deben tener un código válido" )
140140 )
141141
142142 if not rec .document_type_id :
@@ -147,7 +147,7 @@ def get_arba_file_data(
147147 if not CODIGO_DGI or not letter :
148148 raise UserError (
149149 self .env ._ (
150- "Document type has no validator, code or letter configured" " (Id: %s" , rec .document_type_id .id
150+ "Document type has no validator, code or letter configured (Id: %s" , rec .document_type_id .id
151151 )
152152 )
153153
@@ -294,7 +294,7 @@ def get_arba_file_data(
294294 if not uom_arba_with_code :
295295 raise UserError (
296296 self .env ._ (
297- 'No arba code for uom "%(uom)s" (Id: %(id)s) or any uom in ' ' category "%(category)s"' ,
297+ 'No arba code for uom "%(uom)s" (Id: %(id)s) or any uom in category "%(category)s"' ,
298298 uom = line .product_uom .name ,
299299 id = line .product_uom .id ,
300300 category = line .product_uom .category_id .name ,
@@ -352,80 +352,89 @@ def do_pyafipws_presentar_remito(
352352 prod_no_term_dev ,
353353 importe ,
354354 ):
355- self .ensure_one ()
356-
357- COT = self .company_id .arba_cot_connect ()
355+ # self.ensure_one()
356+ for rec in self :
357+ COT = rec .company_id .arba_cot_connect ()
358358
359- if not carrier_partner :
360- raise UserError (
361- 'Debe vincular una "Empresa transportista" a la forma de envío'
362- " seleccionada o elegir otra forma de envío"
359+ if not carrier_partner :
360+ raise UserError (
361+ 'Debe vincular una "Empresa transportista" a la forma de envío'
362+ " seleccionada o elegir otra forma de envío"
363+ )
364+ content , filename = rec .get_arba_file_data (
365+ datetime_out ,
366+ tipo_recorrido ,
367+ carrier_partner ,
368+ patente_vehiculo ,
369+ patente_acoplado ,
370+ prod_no_term_dev ,
371+ importe ,
363372 )
364- content , filename = self .get_arba_file_data (
365- datetime_out , tipo_recorrido , carrier_partner , patente_vehiculo , patente_acoplado , prod_no_term_dev , importe
366- )
367373
368- filename = "/tmp/%s" % filename
369- file = open (filename , "w" )
370- file .write (content )
371- file .close ()
372- _logger .info ('Presentando COT con archivo "%s"' % filename )
373- COT .PresentarRemito (filename , testing = "" )
374- os .remove (filename )
375-
376- if COT .TipoError :
377- msg = self .env ._ (
378- "Error al presentar remito:\n "
379- "* Tipo Error: %(tipo)s\n "
380- "* Codigo Error: %(cod)s\n "
381- "* Mensaje Error: %(msj)s" ,
382- tipo = COT .TipoError ,
383- cod = COT .CodigoError ,
384- msj = COT .MensajeError ,
374+ filename = "/tmp/%s" % filename
375+ file = open (filename , "w" )
376+ file .write (content )
377+ file .close ()
378+ _logger .info ('Presentando COT con archivo "%s"' % filename )
379+ COT .PresentarRemito (filename , testing = "" )
380+ os .remove (filename )
381+
382+ if COT .TipoError :
383+ msg = rec .env ._ (
384+ "Error al presentar remito:\n "
385+ "* Tipo Error: %(tipo)s\n "
386+ "* Codigo Error: %(cod)s\n "
387+ "* Mensaje Error: %(msj)s" ,
388+ tipo = COT .TipoError ,
389+ cod = COT .CodigoError ,
390+ msj = COT .MensajeError ,
391+ )
392+ _logger .warning (msg )
393+ raise UserError (msg )
394+ elif COT .Excepcion :
395+ msg = rec .env ._ ("Error al presentar remito:\n * %s" , COT .Excepcion )
396+ _logger .warning (msg )
397+ raise UserError (msg )
398+
399+ errors = []
400+ while COT .LeerErrorValidacion ():
401+ errors .append (
402+ ("* MensajeError: %s\n * TipoError: %s\n * CodigoError: %s\n " )
403+ % (COT .MensajeError , COT .TipoError , COT .CodigoError )
404+ )
405+
406+ if errors :
407+ raise UserError (rec .env ._ ("Error al presentar remito:\n %s" , "\n " .join (errors )))
408+
409+ attachments = [(filename , content )]
410+ body = """
411+ <p>
412+ Resultado solicitud COT:
413+ <ul>
414+ <li>Número Comprobante: %s</li>
415+ <li>Codigo Integridad: %s</li>
416+ <li>Procesado: %s</li>
417+ <li>Número Único: %s</li>
418+ <li>COT: %s</li>
419+ </ul>
420+ </p>
421+ """ % (COT .NumeroComprobante , COT .CodigoIntegridad , COT .Procesado , COT .NumeroUnico , COT .COT )
422+
423+ rec .write (
424+ {
425+ "cot_numero_unico" : COT .NumeroComprobante ,
426+ "cot_numero_comprobante" : COT .NumeroUnico ,
427+ "cot" : COT .COT ,
428+ }
385429 )
386- _logger .warning (msg )
387- raise UserError (msg )
388- elif COT .Excepcion :
389- msg = self .env ._ ("Error al presentar remito:\n * %s" , COT .Excepcion )
390- _logger .warning (msg )
391- raise UserError (msg )
392-
393- errors = []
394- while COT .LeerErrorValidacion ():
395- errors .append (
396- ("* MensajeError: %s\n " "* TipoError: %s\n " "* CodigoError: %s\n " )
397- % (COT .MensajeError , COT .TipoError , COT .CodigoError )
430+ rec .message_post (
431+ body = body ,
432+ subject = rec .env ._ ("Remito Electrónico Solicitado" ),
433+ attachments = attachments ,
434+ body_is_html = True ,
398435 )
399436
400- if errors :
401- raise UserError (self .env ._ ("Error al presentar remito:\n %s" , "\n " .join (errors )))
402-
403- attachments = [(filename , content )]
404- body = """
405- <p>
406- Resultado solicitud COT:
407- <ul>
408- <li>Número Comprobante: %s</li>
409- <li>Codigo Integridad: %s</li>
410- <li>Procesado: %s</li>
411- <li>Número Único: %s</li>
412- <li>COT: %s</li>
413- </ul>
414- </p>
415- """ % (COT .NumeroComprobante , COT .CodigoIntegridad , COT .Procesado , COT .NumeroUnico , COT .COT )
416-
417- self .write (
418- {
419- "cot_numero_unico" : COT .NumeroComprobante ,
420- "cot_numero_comprobante" : COT .NumeroUnico ,
421- "cot" : COT .COT ,
422- }
423- )
424- self .message_post (
425- body = body , subject = self .env ._ ("Remito Electrónico Solicitado" ), attachments = attachments , body_is_html = True
426- )
427-
428- return True
437+ return True
429438
430439 def _action_done (self ):
431440 res = super ()._action_done ()
0 commit comments