Skip to content

Commit

Permalink
[FIX] pms-l10n_es: fix name, lastname & lasname2 sent to SES (length …
Browse files Browse the repository at this point in the history
…and not valid chars)
  • Loading branch information
miguelpadin committed Oct 3, 2024
1 parent 864c409 commit bc46501
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions pms_l10n_es/wizards/traveller_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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",
Expand All @@ -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
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

0 comments on commit bc46501

Please sign in to comment.