Skip to content

Commit 2b85641

Browse files
committed
[IMP] Pyafip So Long, and Thanks for All the Fish
1 parent 3f6f2f9 commit 2b85641

2 files changed

Lines changed: 80 additions & 102 deletions

File tree

l10n_ar_stock_ux/models/res_company.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
from odoo.exceptions import UserError
66

77
warnings.filterwarnings("ignore", category=DeprecationWarning)
8-
try:
9-
from pyafipws.cot import COT
10-
except ImportError:
11-
COT = None
8+
129

1310
_logger = logging.getLogger(__name__)
1411

@@ -22,33 +19,22 @@ class ResCompany(models.Model):
2219
)
2320

2421
@api.model
25-
def get_arba_cot_login_url(self, environment_type):
22+
def _get_arba_cot_login_url(self, environment_type=False):
23+
if not environment_type:
24+
environment_type = self._get_environment_type()
25+
_logger.info("Getting connection to ARBA on %s mode" % environment_type)
2626
base_url = "https://cot.arba.gov.ar/TransporteBienes/SeguridadCliente/presentarRemitos.do"
2727
if environment_type != "production":
2828
base_url = base_url.replace("cot.arba.gov.ar", "cot.test.arba.gov.ar")
2929
return base_url
3030

31-
def arba_cot_connect(self):
32-
"""
33-
Method to be called
34-
"""
31+
def _get_arba_cot_request_data(self):
3532
self.ensure_one()
36-
cuit = self.partner_id.ensure_vat()
3733

3834
if not self.arba_cot:
3935
raise UserError(self.env._("You must configure ARBA COT on company %s", self.name))
40-
41-
ws = COT()
42-
# en este caso si deberia andar cot en test y es más critico que para
43-
# arba donde obtenemos
44-
environment_type = self._get_environment_type()
45-
_logger.info("Getting connection to ARBA on %s mode" % environment_type)
46-
47-
# argumentos de conectar: self, url=None, proxy="",
48-
# wrapper=None, cacert=None, trace=False, testing=""
49-
arba_cot_url = self.get_arba_cot_login_url(environment_type)
50-
ws.Usuario = cuit
51-
ws.Password = self.arba_cot
52-
ws.Conectar(url=arba_cot_url)
53-
_logger.info('Connection getted to ARBA COT with url "%s" and CUIT %s' % (arba_cot_url, cuit))
54-
return ws
36+
user = self.partner_id.ensure_vat()
37+
return {
38+
"Usuario": user,
39+
"Password": self.arba_cot,
40+
}

l10n_ar_stock_ux/models/stock_picking.py

Lines changed: 69 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import datetime
2+
import logging
23
import re
34

5+
import requests
46
from 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-
137
from 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

Comments
 (0)