Skip to content

Commit d0bd11d

Browse files
jue-adhocvib-adhoc
authored andcommitted
[IMP] *: automatic fixes
1 parent dc21bed commit d0bd11d

30 files changed

+272
-521
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
exclude: |
66
(?x)
7-
7+
88
# We don't want to mess with tool-generated files
99
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|^eslint.config.cjs|^prettier.config.cjs|
1010
# Library files can have extraneous formatting (even minimized)

ISSUE_TEMPLATE.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
> **No me gusta mi camisa**
22
>
33
> *Version affectada:*
4-
>
4+
>
55
> - 7.0 y encima
6-
>
6+
>
77
> *Pasos para reproducir:*
8-
>
8+
>
99
> 1. ponerse antes de un espejo
1010
> 2. prender la luz
1111
> 3. abrir los ojos
12-
>
12+
>
1313
> *Lo que pasa actualmente:*
14-
>
14+
>
1515
> - Asusto
16-
>
16+
>
1717
> *Lo que debe pasar:*
18-
>
19-
> - Todo bien, listo para la fiesta
18+
>
19+
> - Todo bien, listo para la fiesta
2020
>
2121
> *Analisis profunda:*
2222
>

l10n_ar_afipws/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"demo/parameter_demo.xml",
2929
],
3030
"images": [],
31-
'installable': True,
31+
"installable": True,
3232
"auto_install": False,
3333
"application": False,
3434
}

l10n_ar_afipws/models/afipws_certificate.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# For copyright and license notices, see __manifest__.py file in module root
33
# directory
44
##############################################################################
5+
from odoo import _, api, fields, models
56
from odoo.exceptions import UserError
6-
from odoo import fields, models, api, _
77

88
try:
99
from OpenSSL import crypto
@@ -97,10 +97,7 @@ def verify_crt(self):
9797
msg = False
9898

9999
if not crt:
100-
msg = _(
101-
"Invalid action! Please, set the certification string to "
102-
"continue."
103-
)
100+
msg = _("Invalid action! Please, set the certification string to " "continue.")
104101
certificate = rec.get_certificate()
105102
if certificate is None:
106103
msg = _(
@@ -119,9 +116,7 @@ def get_certificate(self):
119116
self.ensure_one()
120117
if self.crt:
121118
try:
122-
certificate = crypto.load_certificate(
123-
crypto.FILETYPE_PEM, self.crt.encode("ascii")
124-
)
119+
certificate = crypto.load_certificate(crypto.FILETYPE_PEM, self.crt.encode("ascii"))
125120
except Exception as e:
126121
if "Expecting: CERTIFICATE" in e[0]:
127122
raise UserError(
@@ -131,9 +126,7 @@ def get_certificate(self):
131126
)
132127
)
133128
else:
134-
raise UserError(
135-
_("Unknown error.\nX509 return this message:\n %s") % (e[0])
136-
)
129+
raise UserError(_("Unknown error.\nX509 return this message:\n %s") % (e[0]))
137130
else:
138131
certificate = None
139132
return certificate

l10n_ar_afipws/models/afipws_certificate_alias.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# For copyright and license notices, see __manifest__.py file in module root
33
# directory
44
##############################################################################
5-
from odoo import fields, models, api, _
5+
from odoo import _, api, fields, models
66
from odoo.exceptions import ValidationError
77

88
try:
@@ -179,9 +179,7 @@ def action_create_certificate_request(self):
179179
req.get_subject().O = self.company_id.name.encode("ascii", "ignore")
180180
req.get_subject().OU = self.department.encode("ascii", "ignore")
181181
req.get_subject().CN = self.common_name.encode("ascii", "ignore")
182-
req.get_subject().serialNumber = "CUIT %s" % self.cuit.encode(
183-
"ascii", "ignore"
184-
)
182+
req.get_subject().serialNumber = "CUIT %s" % self.cuit.encode("ascii", "ignore")
185183
k = crypto.load_privatekey(crypto.FILETYPE_PEM, self.key)
186184
self.key = crypto.dump_privatekey(crypto.FILETYPE_PEM, k)
187185
req.set_pubkey(k)
@@ -197,6 +195,4 @@ def action_create_certificate_request(self):
197195
@api.constrains("common_name")
198196
def check_common_name_len(self):
199197
if self.filtered(lambda x: x.common_name and len(x.common_name) > 50):
200-
raise ValidationError(
201-
_("The Common Name must be lower than 50 characters long")
202-
)
198+
raise ValidationError(_("The Common Name must be lower than 50 characters long"))

l10n_ar_afipws/models/afipws_connection.py

+14-40
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# For copyright and license notices, see __manifest__.py file in module root
33
# directory
44
##############################################################################
5-
from odoo import fields, models, api, _
6-
from odoo.exceptions import UserError, RedirectWarning
75
import logging
86

7+
from odoo import _, api, fields, models
8+
from odoo.exceptions import RedirectWarning, UserError
9+
910
_logger = logging.getLogger(__name__)
1011

1112

1213
class AfipwsConnection(models.Model):
13-
1414
_name = "afipws.connection"
1515
_description = "AFIP WS Connection"
1616
_rec_name = "afip_ws"
@@ -87,31 +87,17 @@ def get_afip_ws_url(self, afip_ws, environment_type):
8787
afip_ws_url = False
8888
if afip_ws == "ws_sr_padron_a4":
8989
if environment_type == "production":
90-
afip_ws_url = (
91-
"https://aws.afip.gov.ar/sr-padron/webservices/"
92-
"personaServiceA4?wsdl"
93-
)
90+
afip_ws_url = "https://aws.afip.gov.ar/sr-padron/webservices/" "personaServiceA4?wsdl"
9491
else:
95-
afip_ws_url = (
96-
"https://awshomo.afip.gov.ar/sr-padron/webservices/"
97-
"personaServiceA4?wsdl"
98-
)
92+
afip_ws_url = "https://awshomo.afip.gov.ar/sr-padron/webservices/" "personaServiceA4?wsdl"
9993
elif afip_ws == "ws_sr_padron_a5":
10094
if environment_type == "production":
101-
afip_ws_url = (
102-
"https://aws.afip.gov.ar/sr-padron/webservices/"
103-
"personaServiceA5?wsdl"
104-
)
95+
afip_ws_url = "https://aws.afip.gov.ar/sr-padron/webservices/" "personaServiceA5?wsdl"
10596
else:
106-
afip_ws_url = (
107-
"https://awshomo.afip.gov.ar/sr-padron/webservices/"
108-
"personaServiceA5?wsdl"
109-
)
97+
afip_ws_url = "https://awshomo.afip.gov.ar/sr-padron/webservices/" "personaServiceA5?wsdl"
11098
elif afip_ws == "wsfecred":
11199
if environment_type == "production":
112-
afip_ws_url = (
113-
"https://serviciosjava.afip.gob.ar/wsfecred/FECredService?wsdl"
114-
)
100+
afip_ws_url = "https://serviciosjava.afip.gob.ar/wsfecred/FECredService?wsdl"
115101
else:
116102
afip_ws_url = "https://fwshomo.afip.gov.ar/wsfecred/FECredService?wsdl"
117103

@@ -122,10 +108,7 @@ def check_afip_ws(self, afip_ws):
122108
self.ensure_one()
123109
if self.afip_ws != afip_ws:
124110
raise UserError(
125-
_(
126-
"This method is for %s connections and you call it from an"
127-
" %s connection"
128-
)
111+
_("This method is for %s connections and you call it from an" " %s connection")
129112
% (afip_ws, self.afip_ws)
130113
)
131114

@@ -134,10 +117,7 @@ def connect(self):
134117
Method to be called
135118
"""
136119
self.ensure_one()
137-
_logger.info(
138-
"Getting connection to ws %s from libraries on "
139-
"connection id %s" % (self.afip_ws, self.id)
140-
)
120+
_logger.info("Getting connection to ws %s from libraries on " "connection id %s" % (self.afip_ws, self.id))
141121
ws = self._get_ws(self.afip_ws)
142122

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

150130
if not ws:
151-
raise UserError(
152-
_('AFIP Webservice %s not implemented yet') % self.afip_ws
153-
)
131+
raise UserError(_("AFIP Webservice %s not implemented yet") % self.afip_ws)
154132
# TODO implementar cache y proxy
155133
# create the proxy and get the configuration system parameters:
156134
# cfg = self.pool.get('ir.config_parameter').sudo()
@@ -167,17 +145,13 @@ def connect(self):
167145
"ExpatError" in repr(error)
168146
or "mismatched tag" in repr(error)
169147
or "Conexión reinicializada por la máquina remota" in repr(error)
170-
or "module 'httplib2' has no attribute 'SSLHandshakeError'"
171-
in repr(error)
148+
or "module 'httplib2' has no attribute 'SSLHandshakeError'" in repr(error)
172149
):
173150
action = self.env.ref("l10n_ar_afipws.action_afip_padron")
174-
msg = _(
175-
"It seems like AFIP service is not available.\nPlease try again later or try manually"
176-
)
151+
msg = _("It seems like AFIP service is not available.\nPlease try again later or try manually")
177152
raise RedirectWarning(msg, action.id, _("Go and find data manually"))
178153
raise UserError(
179-
"There was a connection problem to AFIP. Contact your Odoo Provider. Error\n\n%s"
180-
% repr(error)
154+
"There was a connection problem to AFIP. Contact your Odoo Provider. Error\n\n%s" % repr(error)
181155
)
182156

183157
cuit = self.company_id.partner_id.ensure_vat()

l10n_ar_afipws/models/res_company.py

+19-39
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
# For copyright and license notices, see __manifest__.py file in module root
33
# directory
44
##############################################################################
5-
from odoo import fields, models, api, _
5+
import hashlib
66
import logging
7-
from odoo.exceptions import UserError
8-
import dateutil.parser
9-
import pytz
10-
import odoo.tools as tools
117
import os
12-
import hashlib
13-
import time
148
import sys
9+
import time
1510
import traceback
1611

12+
import dateutil.parser
13+
import odoo.tools as tools
14+
import pytz
15+
from odoo import _, api, fields, models
16+
from odoo.exceptions import UserError
17+
1718
_logger = logging.getLogger(__name__)
1819

1920

2021
class ResCompany(models.Model):
21-
2222
_inherit = "res.company"
2323

2424
alias_ids = fields.One2many(
@@ -46,9 +46,7 @@ def _get_environment_type(self):
4646
* 'test' or 'develop' --> homologation
4747
* other or no parameter --> production
4848
"""
49-
parameter_env_type = (
50-
self.env["ir.config_parameter"].sudo().get_param("afip.ws.env.type")
51-
)
49+
parameter_env_type = self.env["ir.config_parameter"].sudo().get_param("afip.ws.env.type")
5250
if parameter_env_type == "production":
5351
environment_type = "production"
5452
elif parameter_env_type == "homologation":
@@ -112,9 +110,9 @@ def get_key_and_certificate(self, environment_type):
112110
if pkey_path and cert_path:
113111
try:
114112
if os.path.isfile(pkey_path) and os.path.isfile(cert_path):
115-
with open(pkey_path, "r") as pkey_file:
113+
with open(pkey_path) as pkey_file:
116114
pkey = pkey_file.read()
117-
with open(cert_path, "r") as cert_file:
115+
with open(cert_path) as cert_file:
118116
cert = cert_file.read()
119117
msg = "Could not find %s or %s files" % (pkey_path, cert_path)
120118
except Exception:
@@ -127,9 +125,7 @@ def get_key_and_certificate(self, environment_type):
127125

128126
def get_connection(self, afip_ws):
129127
self.ensure_one()
130-
_logger.info(
131-
"Getting connection for company %s and ws %s" % (self.name, afip_ws)
132-
)
128+
_logger.info("Getting connection for company %s and ws %s" % (self.name, afip_ws))
133129
now = fields.Datetime.now()
134130
environment_type = self._get_environment_type()
135131

@@ -173,14 +169,10 @@ def _create_connection(self, afip_ws, environment_type):
173169
)
174170

175171
auth_data["generationtime"] = (
176-
dateutil.parser.parse(auth_data["generationtime"])
177-
.astimezone(pytz.utc)
178-
.replace(tzinfo=None)
172+
dateutil.parser.parse(auth_data["generationtime"]).astimezone(pytz.utc).replace(tzinfo=None)
179173
)
180174
auth_data["expirationtime"] = (
181-
dateutil.parser.parse(auth_data["expirationtime"])
182-
.astimezone(pytz.utc)
183-
.replace(tzinfo=None)
175+
dateutil.parser.parse(auth_data["expirationtime"]).astimezone(pytz.utc).replace(tzinfo=None)
184176
)
185177

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

215207
# make md5 hash of the parameter for caching...
216-
fn = (
217-
"%s.xml"
218-
% hashlib.md5(
219-
(service + certificate + private_key).encode("utf-8")
220-
).hexdigest()
221-
)
208+
fn = "%s.xml" % hashlib.md5((service + certificate + private_key).encode("utf-8")).hexdigest()
222209
if cache:
223210
fn = os.path.join(cache, fn)
224211
else:
225212
fn = os.path.join(wsaa.InstallDir, "cache", fn)
226213

227214
try:
228215
# read the access ticket (if already authenticated)
229-
if (
230-
not os.path.exists(fn)
231-
or os.path.getmtime(fn) + (DEFAULT_TTL) < time.time()
232-
):
216+
if not os.path.exists(fn) or os.path.getmtime(fn) + (DEFAULT_TTL) < time.time():
233217
# access ticket (TA) outdated, create new access request
234218
# ticket (TRA)
235219
tra = wsaa.CreateTRA(service=service, ttl=DEFAULT_TTL)
@@ -245,7 +229,7 @@ def authenticate(
245229
open(fn, "w").write(ta)
246230
else:
247231
# get the access ticket from the previously written file
248-
ta = open(fn, "r").read()
232+
ta = open(fn).read()
249233
# analyze the access ticket xml and extract the relevant fields
250234
wsaa.AnalizarXml(xml=ta)
251235
token = wsaa.ObtenerTagXml("token")
@@ -260,12 +244,8 @@ def authenticate(
260244
err_msg = wsaa.Excepcion
261245
else:
262246
# avoid encoding problem when reporting exceptions to the user:
263-
err_msg = traceback.format_exception_only(sys.exc_type, sys.exc_value)[
264-
0
265-
]
266-
raise UserError(
267-
_("Could not connect. This is the what we received: %s") % (err_msg)
268-
)
247+
err_msg = traceback.format_exception_only(sys.exc_type, sys.exc_value)[0]
248+
raise UserError(_("Could not connect. This is the what we received: %s") % (err_msg))
269249
return {
270250
"uniqueid": uniqueId,
271251
"generationtime": generationTime,

l10n_ar_afipws/models/res_config_settings.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
class ResConfigSettings(models.TransientModel):
9-
109
_inherit = "res.config.settings"
1110

1211
afip_ws_env_type = fields.Selection(

0 commit comments

Comments
 (0)