From bc465018ba5fc421bcf3f0ab307ffe8db6dd6b32 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 3 Oct 2024 16:43:02 +0200 Subject: [PATCH 1/3] [FIX] pms-l10n_es: fix name, lastname & lasname2 sent to SES (length and not valid chars) --- pms_l10n_es/wizards/traveller_report.py | 40 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/pms_l10n_es/wizards/traveller_report.py b/pms_l10n_es/wizards/traveller_report.py index 16dbfd93a4f..4af6eeee16f 100644 --- a/pms_l10n_es/wizards/traveller_report.py +++ b/pms_l10n_es/wizards/traveller_report.py @@ -36,12 +36,20 @@ # Disable insecure request warnings # requests.packages.urllib3.disable_warnings(InsecureRequestWarning) +def replace_multiple_spaces(text: str) -> str: + # Replace 2 or more consecutive spaces with a single space + return re.sub(r'\s{2,}', ' ', text) -def clean_string_ses(string): - clean_string = re.sub(r"[^a-zA-Z0-9\s]", "", string).upper() +def clean_string_only_letters(string): + clean_string = re.sub(r"[^a-zA-Z\s]", "", string).upper() clean_string = " ".join(clean_string.split()) + return + +def clean_string_only_numbers_and_letters(string): + clean_string = re.sub(r"[^a-zA-Z0-9\s]", "", string).upper() + clean_string = " ".join(clean_string.split()) return clean_string @@ -104,9 +112,13 @@ def _ses_xml_person_names_elements(persona, reservation, checkin_partner): if reservation: ses_firstname = False if reservation.partner_id.firstname: - ses_firstname = clean_string_ses(reservation.partner_id.firstname) + ses_firstname = clean_string_only_letters(reservation.partner_id.firstname)[:50] elif reservation.partner_name: - ses_firstname = clean_string_ses(reservation.partner_name).split(" ")[0] + ses_firstname = clean_string_only_letters( + replace_multiple_spaces( + reservation.partner_name + ) + ).split(" ")[0][:50] _ses_xml_text_element_and_validate( persona, "nombre", @@ -115,9 +127,17 @@ def _ses_xml_person_names_elements(persona, reservation, checkin_partner): ) if reservation.partner_id.lastname: - ses_lastname = clean_string_ses(reservation.partner_id.lastname) - elif reservation.partner_name and len(reservation.partner_name.split(" ")) > 1: - ses_lastname = clean_string_ses(reservation.partner_name).split(" ")[1] + ses_lastname = clean_string_only_letters(reservation.partner_id.lastname)[:50] + elif (reservation.partner_name and len( + replace_multiple_spaces( + reservation.partner_name + ).split(" ")) > 1 + ): + ses_lastname = clean_string_only_letters( + replace_multiple_spaces( + reservation.partner_name + ) + ).split(" ")[1][:50] else: ses_lastname = "No aplica" ET.SubElement(persona, "apellido1").text = ses_lastname @@ -126,13 +146,13 @@ def _ses_xml_person_names_elements(persona, reservation, checkin_partner): _ses_xml_text_element_and_validate( persona, "nombre", - clean_string_ses(checkin_partner.firstname), + clean_string_only_letters(checkin_partner.firstname)[:50], _("The guest does not have a name."), ) _ses_xml_text_element_and_validate( persona, "apellido1", - clean_string_ses(checkin_partner.lastname), + clean_string_only_letters(checkin_partner.lastname)[:50], _("The guest does not have a lastname."), ) @@ -140,7 +160,7 @@ def _ses_xml_person_names_elements(persona, reservation, checkin_partner): _ses_xml_text_element_and_validate( persona, "apellido2", - clean_string_ses(checkin_partner.partner_id.lastname2), + clean_string_only_letters(checkin_partner.partner_id.lastname2)[:50], _("The guest does not have a second lastname."), ) From f9ac160f7f074f04f2a1f7ace5912c5048bbaf13 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 3 Oct 2024 16:45:56 +0200 Subject: [PATCH 2/3] [FIX] pms-l10n_es: fix sending incomplete PV's checkin hours after 1st checkin --- pms_l10n_es/wizards/traveller_report.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pms_l10n_es/wizards/traveller_report.py b/pms_l10n_es/wizards/traveller_report.py index 4af6eeee16f..34927ca4dca 100644 --- a/pms_l10n_es/wizards/traveller_report.py +++ b/pms_l10n_es/wizards/traveller_report.py @@ -1141,9 +1141,9 @@ def ses_send_incomplete_traveller_reports( ] ): try: - if ( - fields.Datetime.now() - communication.create_date - ).hours > hours_after_first_checkin_to_inform: + time_difference = fields.Datetime.now() - communication.create_date + hours_difference = time_difference.days * 24 + time_difference.seconds // 3600 + if hours_difference > hours_after_first_checkin_to_inform: # add a note to the reservation communication.reservation_id.sudo().message_post( body=_( From 28b3acba933ace2f0bd19e2d752bd36af1ea73e6 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 3 Oct 2024 16:50:36 +0200 Subject: [PATCH 3/3] [FIX] pms-l10n_es: avoid creating out of service reservations communications --- pms_l10n_es/models/pms_reservation.py | 5 ++++- pms_l10n_es/wizards/traveller_report.py | 30 +++++++++++++------------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pms_l10n_es/models/pms_reservation.py b/pms_l10n_es/models/pms_reservation.py index f1a425211ae..eeaaf5db962 100644 --- a/pms_l10n_es/models/pms_reservation.py +++ b/pms_l10n_es/models/pms_reservation.py @@ -35,7 +35,10 @@ def create_communication(self, reservation_id, operation, entity): @api.model def create(self, vals): reservation = super(PmsReservation, self).create(vals) - if reservation.pms_property_id.institution == "ses": + if ( + reservation.pms_property_id.institution == "ses" + and reservation.reservation_type != "out" + ): self.create_communication(reservation.id, CREATE_OPERATION_CODE, "RH") return reservation diff --git a/pms_l10n_es/wizards/traveller_report.py b/pms_l10n_es/wizards/traveller_report.py index 34927ca4dca..66dca9a1baa 100644 --- a/pms_l10n_es/wizards/traveller_report.py +++ b/pms_l10n_es/wizards/traveller_report.py @@ -36,9 +36,10 @@ # Disable insecure request warnings # requests.packages.urllib3.disable_warnings(InsecureRequestWarning) + def replace_multiple_spaces(text: str) -> str: # Replace 2 or more consecutive spaces with a single space - return re.sub(r'\s{2,}', ' ', text) + return re.sub(r"\s{2,}", " ", text) def clean_string_only_letters(string): @@ -112,12 +113,12 @@ def _ses_xml_person_names_elements(persona, reservation, checkin_partner): if reservation: ses_firstname = False if reservation.partner_id.firstname: - ses_firstname = clean_string_only_letters(reservation.partner_id.firstname)[:50] + ses_firstname = clean_string_only_letters(reservation.partner_id.firstname)[ + :50 + ] elif reservation.partner_name: ses_firstname = clean_string_only_letters( - replace_multiple_spaces( - reservation.partner_name - ) + replace_multiple_spaces(reservation.partner_name) ).split(" ")[0][:50] _ses_xml_text_element_and_validate( persona, @@ -127,16 +128,15 @@ def _ses_xml_person_names_elements(persona, reservation, checkin_partner): ) if reservation.partner_id.lastname: - ses_lastname = clean_string_only_letters(reservation.partner_id.lastname)[:50] - elif (reservation.partner_name and len( - replace_multiple_spaces( - reservation.partner_name - ).split(" ")) > 1 + ses_lastname = clean_string_only_letters(reservation.partner_id.lastname)[ + :50 + ] + elif ( + reservation.partner_name + and len(replace_multiple_spaces(reservation.partner_name).split(" ")) > 1 ): ses_lastname = clean_string_only_letters( - replace_multiple_spaces( - reservation.partner_name - ) + replace_multiple_spaces(reservation.partner_name) ).split(" ")[1][:50] else: ses_lastname = "No aplica" @@ -1142,7 +1142,9 @@ def ses_send_incomplete_traveller_reports( ): try: time_difference = fields.Datetime.now() - communication.create_date - hours_difference = time_difference.days * 24 + time_difference.seconds // 3600 + hours_difference = ( + time_difference.days * 24 + time_difference.seconds // 3600 + ) if hours_difference > hours_after_first_checkin_to_inform: # add a note to the reservation communication.reservation_id.sudo().message_post(