Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] pms-l10n_es: rename field communication_id -> batch_id, extract… #300

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pms_l10n_es/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "PMS Spanish Adaptation",
"version": "14.0.2.15.0",
"version": "14.0.3.0.0",
"author": "Commit [Sun], Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": True,
Expand Down
29 changes: 29 additions & 0 deletions pms_l10n_es/migrations/14.0.3.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import logging
import xml.etree.cElementTree as ET

from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(env, version):
for ses_communication in env["pms.ses.communication"].search(
[
("state", "=", "processed"),
("entity", "=", "RH"),
("operation", "=", "A"),
]
):
root = ET.fromstring(ses_communication.response_query_status_soap)
ses_communication.communication_id = root.find(".//codigoComunicacion").text
ses_communication.batch_id = root.find(".//lote").text

# Retry all communications type delete, set status to to_send
env["pms.ses.communication"].search(
[
("state", "in", ["processed", "error_processing"]),
("entity", "=", "RH"),
("operation", "=", "D"),
]
).write({"state": "to_send"})
6 changes: 5 additions & 1 deletion pms_l10n_es/models/pms_ses_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class PmsSesCommunication(models.Model):
index=True,
store=True,
)
batch_id = fields.Char(
string="Batch ID",
default=False,
)
communication_id = fields.Char(
string="Communication ID",
help="ID of the communication",
Expand Down Expand Up @@ -99,5 +103,5 @@ def force_send_communication(self):
for record in self:
self.env["traveller.report.wizard"].ses_send_communication(
entity=record.entity,
communication_id=record.communication_id,
pms_ses_communication_id=record.id,
)
3 changes: 3 additions & 0 deletions pms_l10n_es/views/pms_ses_communication_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<sheet>
<group>
<field name="reservation_id" />
<field name="batch_id" />
<field name="communication_id" />
<field name="operation" />
<field name="entity" />
Expand Down Expand Up @@ -52,6 +53,7 @@
>
<field name="pms_property_id" />
<field name="reservation_id" />
<field name="batch_id" />
<field name="communication_id" />
<field name="operation" />
<field name="entity" />
Expand All @@ -73,6 +75,7 @@
<field name="arch" type="xml">
<search string="Log SES Communications">
<field name="pms_property_id" widget="selection" />
<field name="batch_id" />
<field name="communication_id" />
<field name="reservation_id" />
<!-- filters -->
Expand Down
37 changes: 20 additions & 17 deletions pms_l10n_es/wizards/traveller_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@
<codigoArrendador>{lessor_id}</codigoArrendador>
<aplicacion>Roomdoo</aplicacion>
<tipoOperacion>{operation}</tipoOperacion>
<tipoComunicacion>{entity}</tipoComunicacion>
{
'<tipoComunicacion>'+entity+'</tipoComunicacion>' if entity else ''
}
</cabecera>
<solicitud>{data}</solicitud>
</peticion>
Expand Down Expand Up @@ -1072,13 +1074,13 @@
return xml_str

@api.model
def ses_send_communications(self, entity, communication_id=False):
def ses_send_communications(self, entity, pms_ses_communication_id=False):
domain = [
("state", "=", "to_send"),
("entity", "=", entity),
]
if communication_id:
domain.append(("id", "=", communication_id))
if pms_ses_communication_id:
domain.append(("id", "=", pms_ses_communication_id))

Check warning on line 1083 in pms_l10n_es/wizards/traveller_report.py

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L1083

Added line #L1083 was not covered by tests
for communication in self.env["pms.ses.communication"].search(domain):
data = False
try:
Expand Down Expand Up @@ -1135,15 +1137,16 @@
communication.response_communication_soap = soap_response.text
result_code = root.find(".//codigo").text
if result_code == REQUEST_CODE_OK:
communication.communication_id = root.find(".//lote").text
communication.batch_id = root.find(".//lote").text

Check warning on line 1140 in pms_l10n_es/wizards/traveller_report.py

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L1140

Added line #L1140 was not covered by tests

communication.state = "to_process"
else:
communication.state = "error_sending"

except requests.exceptions.RequestException as e:
_handle_request_exception(communication, e)
except requests.exceptions.HTTPError as http_err:
_handle_request_exception(communication, http_err)
except requests.exceptions.RequestException as e:
_handle_request_exception(communication, e)

Check warning on line 1149 in pms_l10n_es/wizards/traveller_report.py

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L1149

Added line #L1149 was not covered by tests
except Exception as e:
_handle_request_exception(communication, e)

Expand Down Expand Up @@ -1199,18 +1202,17 @@
communication.response_communication_soap = soap_response.text
result_code = root.find(".//codigo").text
if result_code == REQUEST_CODE_OK:
communication.communication_id = root.find(".//lote").text
communication.batch_id = root.find(".//lote").text

Check warning on line 1205 in pms_l10n_es/wizards/traveller_report.py

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L1205

Added line #L1205 was not covered by tests
if communication.operation == CREATE_OPERATION_CODE:
communication.state = "to_process"
else:
communication.state = "processed"
else:
communication.state = "error_sending"

except requests.exceptions.RequestException as e:
_handle_request_exception(communication, e)
except requests.exceptions.HTTPError as http_err:
_handle_request_exception(communication, http_err)
except requests.exceptions.RequestException as e:
_handle_request_exception(communication, e)

Check warning on line 1215 in pms_l10n_es/wizards/traveller_report.py

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L1215

Added line #L1215 was not covered by tests
except Exception as e:
_handle_request_exception(communication, e)

Expand All @@ -1219,22 +1221,21 @@
for communication in self.env["pms.ses.communication"].search(
[
("state", "=", "to_process"),
("operation", "!=", DELETE_OPERATION_CODE),
]
):
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:lote>{communication.batch_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",
"",
False,
data,
)
communication.query_status_soap = payload
Expand All @@ -1249,13 +1250,15 @@
)
soap_response.raise_for_status()
root = ET.fromstring(soap_response.text)
communication.response_communication_soap = soap_response.text
result_code = root.find(".//codigo").text
communication.response_query_status_soap = soap_response.text
if result_code == REQUEST_CODE_OK:
result_status = root.find(".//codigoEstado").text
if result_status == XML_OK:
communication.state = "processed"
communication.communication_id = root.find(

Check warning on line 1259 in pms_l10n_es/wizards/traveller_report.py

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L1259

Added line #L1259 was not covered by tests
".//codigoComunicacion"
).text
communication.processing_result = root.find(
".//descripcion"
).text
Expand All @@ -1269,9 +1272,9 @@
else:
communication.state = "error_processing"
communication.processing_result = root.find(".//descripcion").text
except requests.exceptions.RequestException as e:
_handle_request_exception(communication, e)
except requests.exceptions.HTTPError as http_err:
_handle_request_exception(communication, http_err)
except requests.exceptions.RequestException as e:
_handle_request_exception(communication, e)

Check warning on line 1278 in pms_l10n_es/wizards/traveller_report.py

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L1278

Added line #L1278 was not covered by tests
except Exception as e:
_handle_request_exception(communication, e)
Loading