|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | # Part of Odoo. See LICENSE file for full copyright and licensing details.
|
3 | 3 | from collections import defaultdict
|
4 |
| -from urllib3.util.ssl_ import create_urllib3_context |
5 |
| -from urllib3.contrib.pyopenssl import inject_into_urllib3 |
6 |
| -from OpenSSL.crypto import load_certificate, load_privatekey, FILETYPE_PEM |
7 | 4 |
|
8 | 5 | from odoo import fields, models, _
|
| 6 | +from odoo.addons.l10n_es.tools.http_adapter import PatchedHTTPAdapter |
9 | 7 | from odoo.tools import html_escape, zeep
|
10 | 8 |
|
11 | 9 | import math
|
12 | 10 | import json
|
13 | 11 | import requests
|
14 | 12 |
|
15 | 13 |
|
16 |
| -# Custom patches to perform the WSDL requests. |
17 |
| -# Avoid failure on servers where the DH key is too small |
18 |
| -EUSKADI_CIPHERS = "DEFAULT:!DH" |
19 |
| - |
20 |
| - |
21 |
| -class PatchedHTTPAdapter(requests.adapters.HTTPAdapter): |
22 |
| - """ An adapter to block DH ciphers which may not work for the tax agencies called""" |
23 |
| - |
24 |
| - def init_poolmanager(self, *args, **kwargs): |
25 |
| - # OVERRIDE |
26 |
| - inject_into_urllib3() |
27 |
| - kwargs['ssl_context'] = create_urllib3_context(ciphers=EUSKADI_CIPHERS) |
28 |
| - return super().init_poolmanager(*args, **kwargs) |
29 |
| - |
30 |
| - def cert_verify(self, conn, url, verify, cert): |
31 |
| - # OVERRIDE |
32 |
| - # The last parameter is only used by the super method to check if the file exists. |
33 |
| - # In our case, cert is an odoo record 'l10n_es_edi.certificate' so not a path to a file. |
34 |
| - # By putting 'None' as last parameter, we ensure the check about TLS configuration is |
35 |
| - # still made without checking temporary files exist. |
36 |
| - super().cert_verify(conn, url, verify, None) |
37 |
| - conn.cert_file = cert |
38 |
| - conn.key_file = None |
39 |
| - |
40 |
| - def get_connection(self, url, proxies=None): |
41 |
| - # OVERRIDE |
42 |
| - # Patch the OpenSSLContext to decode the certificate in-memory. |
43 |
| - conn = super().get_connection(url, proxies=proxies) |
44 |
| - context = conn.conn_kw['ssl_context'] |
45 |
| - |
46 |
| - def patched_load_cert_chain(l10n_es_odoo_certificate, keyfile=None, password=None): |
47 |
| - cert_file, key_file, _certificate = l10n_es_odoo_certificate.sudo()._decode_certificate() |
48 |
| - cert_obj = load_certificate(FILETYPE_PEM, cert_file) |
49 |
| - pkey_obj = load_privatekey(FILETYPE_PEM, key_file) |
50 |
| - |
51 |
| - context._ctx.use_certificate(cert_obj) |
52 |
| - context._ctx.use_privatekey(pkey_obj) |
53 |
| - |
54 |
| - context.load_cert_chain = patched_load_cert_chain |
55 |
| - |
56 |
| - return conn |
57 |
| - |
58 |
| - |
59 | 14 | class AccountEdiFormat(models.Model):
|
60 | 15 | _inherit = 'account.edi.format'
|
61 | 16 |
|
@@ -237,29 +192,7 @@ def full_filter_invl_to_apply(invoice_line):
|
237 | 192 | }
|
238 | 193 |
|
239 | 194 | def _l10n_es_edi_get_partner_info(self, partner):
|
240 |
| - eu_country_codes = set(self.env.ref('base.europe').country_ids.mapped('code')) |
241 |
| - |
242 |
| - partner_info = {} |
243 |
| - IDOtro_ID = partner.vat or 'NO_DISPONIBLE' |
244 |
| - |
245 |
| - if (not partner.country_id or partner.country_id.code == 'ES') and partner.vat: |
246 |
| - # ES partner with VAT. |
247 |
| - partner_info['NIF'] = partner.vat[2:] if partner.vat.startswith('ES') else partner.vat |
248 |
| - if self.env.context.get('error_1117'): |
249 |
| - partner_info['IDOtro'] = {'IDType': '07', 'ID': IDOtro_ID} |
250 |
| - |
251 |
| - elif partner.country_id.code in eu_country_codes and partner.vat: |
252 |
| - # European partner. |
253 |
| - partner_info['IDOtro'] = {'IDType': '02', 'ID': IDOtro_ID} |
254 |
| - else: |
255 |
| - partner_info['IDOtro'] = {'ID': IDOtro_ID} |
256 |
| - if partner.vat: |
257 |
| - partner_info['IDOtro']['IDType'] = '04' |
258 |
| - else: |
259 |
| - partner_info['IDOtro']['IDType'] = '06' |
260 |
| - if partner.country_id: |
261 |
| - partner_info['IDOtro']['CodigoPais'] = partner.country_id.code |
262 |
| - return partner_info |
| 195 | + return partner._l10n_es_edi_get_partner_info() |
263 | 196 |
|
264 | 197 | def _l10n_es_edi_get_invoices_info(self, invoices):
|
265 | 198 | eu_country_codes = set(self.env.ref('base.europe').country_ids.mapped('code'))
|
|
0 commit comments