Skip to content

Commit

Permalink
[IMP] *: automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jue-adhoc authored and vib-adhoc committed Feb 6, 2025
1 parent dc21bed commit d0bd11d
Show file tree
Hide file tree
Showing 30 changed files with 272 additions and 521 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

exclude: |
(?x)
# We don't want to mess with tool-generated files
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|^eslint.config.cjs|^prettier.config.cjs|
# Library files can have extraneous formatting (even minimized)
Expand Down
16 changes: 8 additions & 8 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
> **No me gusta mi camisa**
>
> *Version affectada:*
>
>
> - 7.0 y encima
>
>
> *Pasos para reproducir:*
>
>
> 1. ponerse antes de un espejo
> 2. prender la luz
> 3. abrir los ojos
>
>
> *Lo que pasa actualmente:*
>
>
> - Asusto
>
>
> *Lo que debe pasar:*
>
> - Todo bien, listo para la fiesta
>
> - Todo bien, listo para la fiesta
>
> *Analisis profunda:*
>
Expand Down
2 changes: 1 addition & 1 deletion l10n_ar_afipws/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"demo/parameter_demo.xml",
],
"images": [],
'installable': True,
"installable": True,
"auto_install": False,
"application": False,
}
15 changes: 4 additions & 11 deletions l10n_ar_afipws/models/afipws_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo import fields, models, api, _

try:
from OpenSSL import crypto
Expand Down Expand Up @@ -97,10 +97,7 @@ def verify_crt(self):
msg = False

if not crt:
msg = _(
"Invalid action! Please, set the certification string to "
"continue."
)
msg = _("Invalid action! Please, set the certification string to " "continue.")
certificate = rec.get_certificate()
if certificate is None:
msg = _(
Expand All @@ -119,9 +116,7 @@ def get_certificate(self):
self.ensure_one()
if self.crt:
try:
certificate = crypto.load_certificate(
crypto.FILETYPE_PEM, self.crt.encode("ascii")
)
certificate = crypto.load_certificate(crypto.FILETYPE_PEM, self.crt.encode("ascii"))
except Exception as e:
if "Expecting: CERTIFICATE" in e[0]:
raise UserError(
Expand All @@ -131,9 +126,7 @@ def get_certificate(self):
)
)
else:
raise UserError(
_("Unknown error.\nX509 return this message:\n %s") % (e[0])
)
raise UserError(_("Unknown error.\nX509 return this message:\n %s") % (e[0]))
else:
certificate = None
return certificate
10 changes: 3 additions & 7 deletions l10n_ar_afipws/models/afipws_certificate_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, models, api, _
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

try:
Expand Down Expand Up @@ -179,9 +179,7 @@ def action_create_certificate_request(self):
req.get_subject().O = self.company_id.name.encode("ascii", "ignore")
req.get_subject().OU = self.department.encode("ascii", "ignore")
req.get_subject().CN = self.common_name.encode("ascii", "ignore")
req.get_subject().serialNumber = "CUIT %s" % self.cuit.encode(
"ascii", "ignore"
)
req.get_subject().serialNumber = "CUIT %s" % self.cuit.encode("ascii", "ignore")
k = crypto.load_privatekey(crypto.FILETYPE_PEM, self.key)
self.key = crypto.dump_privatekey(crypto.FILETYPE_PEM, k)
req.set_pubkey(k)
Expand All @@ -197,6 +195,4 @@ def action_create_certificate_request(self):
@api.constrains("common_name")
def check_common_name_len(self):
if self.filtered(lambda x: x.common_name and len(x.common_name) > 50):
raise ValidationError(
_("The Common Name must be lower than 50 characters long")
)
raise ValidationError(_("The Common Name must be lower than 50 characters long"))
54 changes: 14 additions & 40 deletions l10n_ar_afipws/models/afipws_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, models, api, _
from odoo.exceptions import UserError, RedirectWarning
import logging

from odoo import _, api, fields, models
from odoo.exceptions import RedirectWarning, UserError

_logger = logging.getLogger(__name__)


class AfipwsConnection(models.Model):

_name = "afipws.connection"
_description = "AFIP WS Connection"
_rec_name = "afip_ws"
Expand Down Expand Up @@ -87,31 +87,17 @@ def get_afip_ws_url(self, afip_ws, environment_type):
afip_ws_url = False
if afip_ws == "ws_sr_padron_a4":
if environment_type == "production":
afip_ws_url = (
"https://aws.afip.gov.ar/sr-padron/webservices/"
"personaServiceA4?wsdl"
)
afip_ws_url = "https://aws.afip.gov.ar/sr-padron/webservices/" "personaServiceA4?wsdl"
else:
afip_ws_url = (
"https://awshomo.afip.gov.ar/sr-padron/webservices/"
"personaServiceA4?wsdl"
)
afip_ws_url = "https://awshomo.afip.gov.ar/sr-padron/webservices/" "personaServiceA4?wsdl"
elif afip_ws == "ws_sr_padron_a5":
if environment_type == "production":
afip_ws_url = (
"https://aws.afip.gov.ar/sr-padron/webservices/"
"personaServiceA5?wsdl"
)
afip_ws_url = "https://aws.afip.gov.ar/sr-padron/webservices/" "personaServiceA5?wsdl"
else:
afip_ws_url = (
"https://awshomo.afip.gov.ar/sr-padron/webservices/"
"personaServiceA5?wsdl"
)
afip_ws_url = "https://awshomo.afip.gov.ar/sr-padron/webservices/" "personaServiceA5?wsdl"
elif afip_ws == "wsfecred":
if environment_type == "production":
afip_ws_url = (
"https://serviciosjava.afip.gob.ar/wsfecred/FECredService?wsdl"
)
afip_ws_url = "https://serviciosjava.afip.gob.ar/wsfecred/FECredService?wsdl"
else:
afip_ws_url = "https://fwshomo.afip.gov.ar/wsfecred/FECredService?wsdl"

Expand All @@ -122,10 +108,7 @@ def check_afip_ws(self, afip_ws):
self.ensure_one()
if self.afip_ws != afip_ws:
raise UserError(
_(
"This method is for %s connections and you call it from an"
" %s connection"
)
_("This method is for %s connections and you call it from an" " %s connection")
% (afip_ws, self.afip_ws)
)

Expand All @@ -134,10 +117,7 @@ def connect(self):
Method to be called
"""
self.ensure_one()
_logger.info(
"Getting connection to ws %s from libraries on "
"connection id %s" % (self.afip_ws, self.id)
)
_logger.info("Getting connection to ws %s from libraries on " "connection id %s" % (self.afip_ws, self.id))
ws = self._get_ws(self.afip_ws)

# parche por este error que da al consultar por esa opción de homo
Expand All @@ -148,9 +128,7 @@ def connect(self):
ws.HOMO = False

if not ws:
raise UserError(
_('AFIP Webservice %s not implemented yet') % self.afip_ws
)
raise UserError(_("AFIP Webservice %s not implemented yet") % self.afip_ws)
# TODO implementar cache y proxy
# create the proxy and get the configuration system parameters:
# cfg = self.pool.get('ir.config_parameter').sudo()
Expand All @@ -167,17 +145,13 @@ def connect(self):
"ExpatError" in repr(error)
or "mismatched tag" in repr(error)
or "Conexión reinicializada por la máquina remota" in repr(error)
or "module 'httplib2' has no attribute 'SSLHandshakeError'"
in repr(error)
or "module 'httplib2' has no attribute 'SSLHandshakeError'" in repr(error)
):
action = self.env.ref("l10n_ar_afipws.action_afip_padron")
msg = _(
"It seems like AFIP service is not available.\nPlease try again later or try manually"
)
msg = _("It seems like AFIP service is not available.\nPlease try again later or try manually")
raise RedirectWarning(msg, action.id, _("Go and find data manually"))
raise UserError(
"There was a connection problem to AFIP. Contact your Odoo Provider. Error\n\n%s"
% repr(error)
"There was a connection problem to AFIP. Contact your Odoo Provider. Error\n\n%s" % repr(error)
)

cuit = self.company_id.partner_id.ensure_vat()
Expand Down
58 changes: 19 additions & 39 deletions l10n_ar_afipws/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, models, api, _
import hashlib
import logging
from odoo.exceptions import UserError
import dateutil.parser
import pytz
import odoo.tools as tools
import os
import hashlib
import time
import sys
import time
import traceback

import dateutil.parser
import odoo.tools as tools
import pytz
from odoo import _, api, fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)


class ResCompany(models.Model):

_inherit = "res.company"

alias_ids = fields.One2many(
Expand Down Expand Up @@ -46,9 +46,7 @@ def _get_environment_type(self):
* 'test' or 'develop' --> homologation
* other or no parameter --> production
"""
parameter_env_type = (
self.env["ir.config_parameter"].sudo().get_param("afip.ws.env.type")
)
parameter_env_type = self.env["ir.config_parameter"].sudo().get_param("afip.ws.env.type")
if parameter_env_type == "production":
environment_type = "production"
elif parameter_env_type == "homologation":
Expand Down Expand Up @@ -112,9 +110,9 @@ def get_key_and_certificate(self, environment_type):
if pkey_path and cert_path:
try:
if os.path.isfile(pkey_path) and os.path.isfile(cert_path):
with open(pkey_path, "r") as pkey_file:
with open(pkey_path) as pkey_file:
pkey = pkey_file.read()
with open(cert_path, "r") as cert_file:
with open(cert_path) as cert_file:
cert = cert_file.read()
msg = "Could not find %s or %s files" % (pkey_path, cert_path)
except Exception:
Expand All @@ -127,9 +125,7 @@ def get_key_and_certificate(self, environment_type):

def get_connection(self, afip_ws):
self.ensure_one()
_logger.info(
"Getting connection for company %s and ws %s" % (self.name, afip_ws)
)
_logger.info("Getting connection for company %s and ws %s" % (self.name, afip_ws))
now = fields.Datetime.now()
environment_type = self._get_environment_type()

Expand Down Expand Up @@ -173,14 +169,10 @@ def _create_connection(self, afip_ws, environment_type):
)

auth_data["generationtime"] = (
dateutil.parser.parse(auth_data["generationtime"])
.astimezone(pytz.utc)
.replace(tzinfo=None)
dateutil.parser.parse(auth_data["generationtime"]).astimezone(pytz.utc).replace(tzinfo=None)
)
auth_data["expirationtime"] = (
dateutil.parser.parse(auth_data["expirationtime"])
.astimezone(pytz.utc)
.replace(tzinfo=None)
dateutil.parser.parse(auth_data["expirationtime"]).astimezone(pytz.utc).replace(tzinfo=None)
)

_logger.info("Successful Connection to AFIP.")
Expand Down Expand Up @@ -213,23 +205,15 @@ def authenticate(
DEFAULT_TTL = 60 * 60 * 5

# make md5 hash of the parameter for caching...
fn = (
"%s.xml"
% hashlib.md5(
(service + certificate + private_key).encode("utf-8")
).hexdigest()
)
fn = "%s.xml" % hashlib.md5((service + certificate + private_key).encode("utf-8")).hexdigest()
if cache:
fn = os.path.join(cache, fn)
else:
fn = os.path.join(wsaa.InstallDir, "cache", fn)

try:
# read the access ticket (if already authenticated)
if (
not os.path.exists(fn)
or os.path.getmtime(fn) + (DEFAULT_TTL) < time.time()
):
if not os.path.exists(fn) or os.path.getmtime(fn) + (DEFAULT_TTL) < time.time():
# access ticket (TA) outdated, create new access request
# ticket (TRA)
tra = wsaa.CreateTRA(service=service, ttl=DEFAULT_TTL)
Expand All @@ -245,7 +229,7 @@ def authenticate(
open(fn, "w").write(ta)
else:
# get the access ticket from the previously written file
ta = open(fn, "r").read()
ta = open(fn).read()
# analyze the access ticket xml and extract the relevant fields
wsaa.AnalizarXml(xml=ta)
token = wsaa.ObtenerTagXml("token")
Expand All @@ -260,12 +244,8 @@ def authenticate(
err_msg = wsaa.Excepcion
else:
# avoid encoding problem when reporting exceptions to the user:
err_msg = traceback.format_exception_only(sys.exc_type, sys.exc_value)[
0
]
raise UserError(
_("Could not connect. This is the what we received: %s") % (err_msg)
)
err_msg = traceback.format_exception_only(sys.exc_type, sys.exc_value)[0]
raise UserError(_("Could not connect. This is the what we received: %s") % (err_msg))
return {
"uniqueid": uniqueId,
"generationtime": generationTime,
Expand Down
1 change: 0 additions & 1 deletion l10n_ar_afipws/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class ResConfigSettings(models.TransientModel):

_inherit = "res.config.settings"

afip_ws_env_type = fields.Selection(
Expand Down
Loading

0 comments on commit d0bd11d

Please sign in to comment.