Skip to content

Commit

Permalink
[FIX] url call
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Sep 13, 2024
1 parent 45fa1ae commit 7e8d36d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 16 deletions.
75 changes: 59 additions & 16 deletions l10n_it_fatturapa_govway/models/sdi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from urllib.parse import urljoin

import requests
from requests import Timeout, TooManyRedirects

from odoo import _, fields, models
from odoo.exceptions import UserError
Expand All @@ -16,6 +15,8 @@ class SdiChannel(models.Model):
govway_url = fields.Char(
string="GovWay URL",
)
govway_user = fields.Char(string="GovWay User")
govway_password = fields.Char(string="GovWay Password")

# @api.constrains("fetch_pec_server_id")
# def check_fetch_pec_server_id(self):
Expand Down Expand Up @@ -89,32 +90,74 @@ def send_via_govway(self, attachment_out_ids):
company = att.company_id
vat = company.vat.split("IT")[1]
url = (
f"{self.govway_url}govway/sdi/out/xml2soap/{vat}"
f"/CentroServiziFatturaPA/SdIRiceviFile/v1"
) # SoggettoSDI
"govway/sdi/out/xml2soap/Pretecno"
"/CentroServiziFatturaPA/SdIRiceviFile/v1"
)
url = urljoin(self.govway_url, url)
params = {
"Versione": 1, # VersioneFatturaPA
"TipoFile": "application/xml", # P7M: application/pkcs7-mime
"Versione": "FPR12", # VersioneFatturaPA
"TipoFile": "XML", # P7M: application/pkcs7-mime
"IdPaese": "IT",
"IdCodice": vat,
}
try:
response = requests.get(
url=url, params=params, timeout=60
) # , headers=headers)
response_data = json.loads(response.text)
status = response_data.get("status")
if status and status.get("error_code", False):
response = requests.post(
url=url,
data=att.datas,
params=params,
timeout=60,
auth=(self.govway_user, self.govway_password),
headers={"Content-Type": "application/octet-stream"},
)
if response.status_code != 200:
# response_data = json.loads(response.text)
# status = response_data.get("status")
# if status and status.get("error_code", False):
raise Exception(
_(
"Failed to fetch from CoinMarketCap with error code: "
"%s and error message: %s"
)
% (status.get("error_code"), status.get("error_message"))
% (response.status_code, response.text)
)
except (ConnectionError, Timeout, TooManyRedirects) as e:
except Exception as e:
raise UserError(
_("GovWay server not available for %s. Please configure it.")
% str(e)
)
return response_data.get("data", {})
return {} # response_data.get("data", {})
# mail_message = self.env["mail.message"].create(
# {
# "model": att._name,
# "res_id": att.id,
# "subject": att.name,
# "body": "XML file for FatturaPA {} sent to Exchange System to "
# "the email address {}.".format(
# att.name, company.email_exchange_system
# ),
# "attachment_ids": [(6, 0, att.ir_attachment_id.ids)],
# "email_from": company.email_from_for_fatturaPA,
# "reply_to": company.email_from_for_fatturaPA,
# "mail_server_id": company.sdi_channel_id.pec_server_id.id,
# }
# )
#
# mail = self.env["mail.mail"].create(
# {
# "mail_message_id": mail_message.id,
# "body_html": mail_message.body,
# "email_to": company.email_exchange_system,
# "headers": {"Return-Path": company.email_from_for_fatturaPA},
# }
# )
#
# if mail:
# try:
# mail.send(raise_exception=True)
# att.state = "sent"
# att.sending_date = fields.Datetime.now()
# att.sending_user = user.id
# company.sdi_channel_id.update_after_first_pec_sending()
# except MailDeliveryException as e:
# att.state = "sender_error"
# mail.body = str(e)
2 changes: 2 additions & 0 deletions l10n_it_fatturapa_govway/views/sdi_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<xpath expr="//newline" position="after">
<group attrs="{'invisible': [('channel_type', '!=', 'govway')]}">
<field name="govway_url" />
<field name="govway_user" password="True" />
<field name="govway_password" password="True" />
</group>
</xpath>
</field>
Expand Down

0 comments on commit 7e8d36d

Please sign in to comment.