11import datetime
2+ import logging
23import re
34
5+ import requests
46from odoo import api , fields , models
5-
6- try :
7- from pyafipws .iibb import IIBB
8- except ImportError :
9- IIBB = None
10- import logging
11- import os
12-
137from odoo .exceptions import UserError
148
159_logger = logging .getLogger (__name__ )
@@ -100,7 +94,7 @@ def _compute_l10n_ar_afip_barcode(self):
10094 )
10195 rec .l10n_ar_afip_barcode = barcode
10296
103- def get_arba_file_data (
97+ def _get_arba_file_data (
10498 self ,
10599 datetime_out ,
106100 tipo_recorrido ,
@@ -377,9 +371,12 @@ def get_arba_file_data(
377371 content = ""
378372 for line in [HEADER ] + REMITOS_PRODUCTOS + [FOOTER ]:
379373 content += "%s\r " % ("|" .join (line ))
380- return (content , filename )
374+ return (filename , content , "text/plain" )
375+
376+ def _parse_arba_response (self , response_content ):
377+ pass
381378
382- def do_pyafipws_presentar_remito (
379+ def _arba_send_pricking (
383380 self ,
384381 datetime_out ,
385382 tipo_recorrido ,
@@ -389,15 +386,13 @@ def do_pyafipws_presentar_remito(
389386 prod_no_term_dev ,
390387 importe ,
391388 ):
392- for rec in self :
393- COT = rec .company_id .arba_cot_connect ()
394-
389+ for company_id , rec in self .grouped ("company_id" ):
395390 if not carrier_partner :
396391 raise UserError (
397392 'Debe vincular una "Empresa transportista" a la forma de envío'
398393 " seleccionada o elegir otra forma de envío"
399394 )
400- content , filename = rec .get_arba_file_data (
395+ file = rec ._get_arba_file_data (
401396 datetime_out ,
402397 tipo_recorrido ,
403398 carrier_partner ,
@@ -407,68 +402,65 @@ def do_pyafipws_presentar_remito(
407402 importe ,
408403 )
409404
410- filename = "/tmp/%s" % filename
411- file = open (filename , "w" )
412- file .write (content )
413- file .close ()
414- _logger .info ('Presentando COT con archivo "%s"' % filename )
415- COT .PresentarRemito (filename , testing = "" )
416- os .remove (filename )
417-
418- if COT .TipoError :
419- msg = rec .env ._ (
420- "Error al presentar remito:\n "
421- "* Tipo Error: %(tipo)s\n "
422- "* Codigo Error: %(cod)s\n "
423- "* Mensaje Error: %(msj)s" ,
424- tipo = COT .TipoError ,
425- cod = COT .CodigoError ,
426- msj = COT .MensajeError ,
427- )
428- _logger .warning (msg )
429- raise UserError (msg )
430- elif COT .Excepcion :
431- msg = rec .env ._ ("Error al presentar remito:\n * %s" , COT .Excepcion )
432- _logger .warning (msg )
433- raise UserError (msg )
434-
435- errors = []
436- while COT .LeerErrorValidacion ():
437- errors .append (
438- ("* MensajeError: %s\n * TipoError: %s\n * CodigoError: %s\n " )
439- % (COT .MensajeError , COT .TipoError , COT .CodigoError )
440- )
441-
442- if errors :
443- raise UserError (rec .env ._ ("Error al presentar remito:\n %s" , "\n " .join (errors )))
444-
445- attachments = [(filename , content )]
446- body = """
447- <p>
448- Resultado solicitud COT:
449- <ul>
450- <li>Número Comprobante: %s</li>
451- <li>Codigo Integridad: %s</li>
452- <li>Procesado: %s</li>
453- <li>Número Único: %s</li>
454- <li>COT: %s</li>
455- </ul>
456- </p>
457- """ % (COT .NumeroComprobante , COT .CodigoIntegridad , COT .Procesado , COT .NumeroUnico , COT .COT )
458-
459- rec .write (
460- {
461- "cot_numero_unico" : COT .NumeroComprobante ,
462- "cot_numero_comprobante" : COT .NumeroUnico ,
463- "cot" : COT .COT ,
464- }
465- )
466- rec .message_post (
467- body = body ,
468- subject = rec .env ._ ("Remito Electrónico Solicitado" ),
469- attachments = attachments ,
470- body_is_html = True ,
471- )
405+ login_url = rec .company_id ._get_arba_cot_login_url ()
406+ request_data = rec .company_id ._get_arba_cot_request_data ()
407+ res = requests .post (login_url , data = request_data , files = {"file" : file })
408+ self ._parse_arba_response (res .content )
409+
410+ # if COT.TipoError:
411+ # msg = rec.env._(
412+ # "Error al presentar remito:\n"
413+ # "* Tipo Error: %(tipo)s\n"
414+ # "* Codigo Error: %(cod)s\n"
415+ # "* Mensaje Error: %(msj)s",
416+ # tipo=COT.TipoError,
417+ # cod=COT.CodigoError,
418+ # msj=COT.MensajeError,
419+ # )
420+ # _logger.warning(msg)
421+ # raise UserError(msg)
422+ # elif COT.Excepcion:
423+ # msg = rec.env._("Error al presentar remito:\n* %s", COT.Excepcion)
424+ # _logger.warning(msg)
425+ # raise UserError(msg)
426+
427+ # errors = []
428+ # while COT.LeerErrorValidacion():
429+ # errors.append(
430+ # ("* MensajeError: %s\n* TipoError: %s\n* CodigoError: %s\n")
431+ # % (COT.MensajeError, COT.TipoError, COT.CodigoError)
432+ # )
433+
434+ # if errors:
435+ # raise UserError(rec.env._("Error al presentar remito:\n%s", "\n".join(errors)))
436+
437+ # attachments = [(filename, content)]
438+ # body = """
439+ # <p>
440+ # Resultado solicitud COT:
441+ # <ul>
442+ # <li>Número Comprobante: %s</li>
443+ # <li>Codigo Integridad: %s</li>
444+ # <li>Procesado: %s</li>
445+ # <li>Número Único: %s</li>
446+ # <li>COT: %s</li>
447+ # </ul>
448+ # </p>
449+ # """ % (COT.NumeroComprobante, COT.CodigoIntegridad, COT.Procesado, COT.NumeroUnico, COT.COT)
450+
451+ # rec.write(
452+ # {
453+ # "cot_numero_unico": COT.NumeroComprobante,
454+ # "cot_numero_comprobante": COT.NumeroUnico,
455+ # "cot": COT.COT,
456+ # }
457+ # )
458+ # rec.message_post(
459+ # body=body,
460+ # subject=rec.env._("Remito Electrónico Solicitado"),
461+ # attachments=attachments,
462+ # body_is_html=True,
463+ # )
472464
473465 return True
474466
0 commit comments