[FIX] pms: fix try catch sendingg & procesing notifications & fix write reservation (SES)

This commit is contained in:
miguelpadin
2024-09-06 13:13:14 +01:00
parent 7e13e6b848
commit b7298feb99
2 changed files with 44 additions and 1 deletions

View File

@@ -84,6 +84,7 @@ class PmsReservation(models.Model):
elif (
vals["state"] != "cancel"
and last_communication.operation == DELETE_OPERATION_CODE
or not last_communication
):
self.create_communication(
reservation.id, CREATE_OPERATION_CODE, "RH"
@@ -100,3 +101,4 @@ class PmsReservation(models.Model):
if record.pms_property_id.institution == "ses":
self.create_communication_after_update_reservation(record, vals)
return super(PmsReservation, self).write(vals)

View File

@@ -323,7 +323,8 @@ def _handle_request_exception(communication, e):
if communication.state == "to_send":
communication.sending_result = f"Request error: {e}"
else:
communication.processing_result = f"Request error: {e}"
communication.processing_result = f"Request error: {e}" else:
communication.sending_result = f"Unexpected error: {e}"
class TravellerReport(models.TransientModel):
@@ -1027,6 +1028,24 @@ class TravellerReport(models.TransientModel):
communication.communication_soap = payload
communication.communication_time = fields.Datetime.now()
try:
data = False
if communication.entity == "RH":
data = self.generate_xml_reservations([communication.reservation_id.id])
elif communication.entity == "PV":
data = self.generate_xml_reservations_travellers_report(
[communication.reservation_id.id]
)
communication.communication_xml = data
data = _string_to_zip_to_base64(data)
payload = _generate_payload(
communication.reservation_id.pms_property_id.institution_lessor_id,
communication.operation,
communication.entity,
data,
)
communication.communication_soap = payload
communication.communication_time = fields.Datetime.now()
soap_response = requests.request(
"POST",
communication.reservation_id.pms_property_id.ses_url,
@@ -1049,6 +1068,8 @@ class TravellerReport(models.TransientModel):
except requests.exceptions.RequestException as e:
_handle_request_exception(communication, e)
except Exception as e:
_handle_request_exception(communication, e)
@api.model
def ses_process_communications(self):
@@ -1075,6 +1096,23 @@ class TravellerReport(models.TransientModel):
communication.query_status_soap = payload
communication.query_status_time = fields.Datetime.now()
try:
var_xml_get_batch = f"""
<con:lotes
xmlns:con="http://www.neg.hospedajes.mir.es/consultarComunicacion">
<con:lote>{communication.communication_id}</con:lote>
</con:lotes>
"""
communication.query_status_xml = var_xml_get_batch
data = _string_to_zip_to_base64(var_xml_get_batch)
payload = _generate_payload(
communication.reservation_id.pms_property_id.institution_lessor_id,
"C",
"",
data,
)
communication.query_status_soap = payload
communication.query_status_time = fields.Datetime.now()
soap_response = requests.request(
"POST",
communication.reservation_id.pms_property_id.ses_url,
@@ -1105,6 +1143,8 @@ class TravellerReport(models.TransientModel):
communication.processing_result = root.find(".//descripcion").text
except requests.exceptions.RequestException as e:
_handle_request_exception(communication, e)
except Exception as e:
_handle_request_exception(communication, e)
@api.model
def create_pending_notifications_traveller_report(self):
@@ -1136,3 +1176,4 @@ class TravellerReport(models.TransientModel):
CREATE_OPERATION_CODE,
"PV",
)