Skip to content

Commit

Permalink
[FIX] pms-l10n_es: avoid creating out of service reservations communi…
Browse files Browse the repository at this point in the history
…cations
  • Loading branch information
miguelpadin committed Oct 3, 2024
1 parent f9ac160 commit 28b3acb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
5 changes: 4 additions & 1 deletion pms_l10n_es/models/pms_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 16 additions & 14 deletions pms_l10n_es/wizards/traveller_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L42

Added line #L42 was not covered by tests


def clean_string_only_letters(string):
Expand Down Expand Up @@ -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)[

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

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L116

Added line #L116 was not covered by tests
:50
]
elif reservation.partner_name:
ses_firstname = clean_string_only_letters(

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

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L120

Added line #L120 was not covered by tests
replace_multiple_spaces(
reservation.partner_name
)
replace_multiple_spaces(reservation.partner_name)
).split(" ")[0][:50]
_ses_xml_text_element_and_validate(
persona,
Expand All @@ -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)[

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

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L131

Added line #L131 was not covered by tests
:50
]
elif (
reservation.partner_name
and len(replace_multiple_spaces(reservation.partner_name).split(" ")) > 1
):
ses_lastname = clean_string_only_letters(

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

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L138

Added line #L138 was not covered by tests
replace_multiple_spaces(
reservation.partner_name
)
replace_multiple_spaces(reservation.partner_name)
).split(" ")[1][:50]
else:
ses_lastname = "No aplica"
Expand Down Expand Up @@ -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 = (

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

View check run for this annotation

Codecov / codecov/patch

pms_l10n_es/wizards/traveller_report.py#L1144-L1145

Added lines #L1144 - L1145 were not covered by tests
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(
Expand Down

0 comments on commit 28b3acb

Please sign in to comment.