From 28b3acba933ace2f0bd19e2d752bd36af1ea73e6 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Thu, 3 Oct 2024 16:50:36 +0200 Subject: [PATCH] [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 f1a425211a..eeaaf5db96 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 34927ca4dc..66dca9a1ba 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(