Skip to content

Commit

Permalink
Merge PR #290 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by DarioLodeiros
  • Loading branch information
OCA-git-bot committed Oct 11, 2024
2 parents 864c409 + 28b3acb commit cefcdbb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 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
48 changes: 35 additions & 13 deletions pms_l10n_es/wizards/traveller_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@
# requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


def clean_string_ses(string):
clean_string = re.sub(r"[^a-zA-Z0-9\s]", "", string).upper()
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_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


Expand Down Expand Up @@ -104,9 +113,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",
Expand All @@ -115,9 +128,16 @@ 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
Expand All @@ -126,21 +146,21 @@ 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."),
)

if checkin_partner.document_type.code == CODE_DNI:
_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."),
)

Expand Down Expand Up @@ -1121,9 +1141,11 @@ 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=_(
Expand Down

0 comments on commit cefcdbb

Please sign in to comment.