[IMP] added input alert if has error and fix document number input

This commit is contained in:
braisab
2021-05-10 19:44:41 +02:00
parent 341bc26009
commit 3f4adc0524
2 changed files with 179 additions and 139 deletions

View File

@@ -416,11 +416,10 @@ class PortalPrecheckin(CustomerPortal):
"email": kw.get("email-" + str(counter)),
}
error, error_message = self.form_validate(kw, counter)
errors.update({counter: error})
errors.update(error)
if error_message:
for e in error_message:
e_messages.append(e)
has_error = True
else:
lastname = True if kw.get("lastname-" + str(counter)) else False
@@ -437,28 +436,20 @@ class PortalPrecheckin(CustomerPortal):
elif checkin.partner_id:
res_partner = checkin.partner_id
res_partner.write(values)
checkin.write(values)
counter = counter + 1
values = {"no_breadcrumbs": True}
if has_error:
filtered_dict = {k: v for k, v in errors.items() if v}
for e in filtered_dict:
error = filtered_dict[e]
values.update({"error": error})
values.update({"error": filtered_dict})
values.update(
{
"error_message": e_messages,
}
)
else:
values.update(
{
"success": True,
}
)
values.update({"success": True, "error": {}})
if kw.get("folio_id"):
folio = request.env["pms.folio"].browse(int(kw.get("folio_id")))
values.update(
@@ -479,8 +470,7 @@ class PortalPrecheckin(CustomerPortal):
return request.render("pms.portal_my_reservation_precheckin", values)
def form_validate(self, data, counter):
error = dict()
error_message = []
error, error_message = self.form_document_validate(data, counter)
keys = data.keys()
mobile = "mobile" if "mobile" in keys else "mobile-" + str(counter)
if data[mobile]:
@@ -491,17 +481,71 @@ class PortalPrecheckin(CustomerPortal):
):
error[mobile] = "error"
error_message.append("Invalid phone")
if data["document_number"]:
if not data["document_type"]:
error["document_type"] = "error"
birthdate_date = (
"birthdate_date"
if "birthdate_date" in keys
else "birthdate_date-" + str(counter)
)
if data[birthdate_date] and data[birthdate_date] > str(fields.Datetime.today()):
error[birthdate_date] = "error"
error_message.append("Birthdate must be less than today")
document_expedition_date = (
"document_expedition_date"
if "document_expedition_date" in keys
else "document_expedition_date-" + str(counter)
)
if data[document_expedition_date] and data[document_expedition_date] > str(
fields.Datetime.today()
):
error[document_expedition_date] = "error"
error_message.append("Expedition Date must be less than today")
email = "email" if "email" in keys else "email-" + str(counter)
if data[email] and not tools.single_email_re.match(data[email]):
error[email] = "error"
error_message.append("Email format is wrong")
firstname = "firstname" if "firstname" in keys else "firstname-" + str(counter)
lastname = "lastname" if "lastname" in keys else "lastname-" + str(counter)
lastname2 = "lastname2" if "lastname2" in keys else "lastname2-" + str(counter)
if not data[firstname] and not data[lastname] and not data[lastname2]:
error[firstname] = "error"
error_message.append("Firstname or any lastname are not included")
return error, error_message
def form_document_validate(self, data, counter):
error = dict()
error_message = []
keys = data.keys()
document_number = (
"document_number"
if "document_number" in keys
else "document_number-" + str(counter)
)
document_type = (
"document_type"
if "document_type" in keys
else "document_type-" + str(counter)
)
checkin_partner_id = "id" if "id" in keys else "id-" + str(counter)
checkin_partner = request.env["pms.checkin.partner"].search(
[("id", "=", data[checkin_partner_id])]
)
partner_id = checkin_partner.partner_id.id
if partner_id:
partners = request.env["res.partner"].search(
[("id", "!=", str(partner_id))]
)
if data[document_number]:
for partner in partners:
if data[document_number] == partner.document_number:
error[document_number] = "error"
error_message.append("Document Number already exists")
if not data[document_type]:
error[document_type] = "error"
error_message.append("Document Type is not selected")
if data["document_type"] == "D":
if (
len(data["document_number"]) == 9
or len(data["document_number"]) == 10
):
if not re.match(r"^\d{8}[ -]?[a-zA-Z]$", data["document_number"]):
error["document_number"] = "error"
if data[document_type] == "D":
if len(data[document_number]) == 9 or len(data[document_number]) == 10:
if not re.match(r"^\d{8}[ -]?[a-zA-Z]$", data[document_number]):
error[document_number] = "error"
error_message.append("The DNI format is wrong")
letters = {
0: "T",
@@ -528,52 +572,32 @@ class PortalPrecheckin(CustomerPortal):
21: "K",
22: "E",
}
dni_number = data["document_number"][0:8]
dni_letter = data["document_number"][
len(data["document_number"]) - 1 : len(data["document_number"])
dni_number = data[document_number][0:8]
dni_letter = data[document_number][
len(data[document_number]) - 1 : len(data[document_number])
]
if letters.get(int(dni_number) % 23) != dni_letter.upper():
error["document_number"] = "error"
error[document_number] = "error"
error_message.append("DNI is invalid")
else:
error["document_number"] = "error"
error[document_number] = "error"
error_message.append("DNI is invalid")
if data["document_type"] == "C" and not re.match(
r"^\d{8}[ -]?[a-zA-Z]$", data["document_number"]
if data[document_type] == "C" and not re.match(
r"^\d{8}[ -]?[a-zA-Z]$", data[document_number]
):
error["document_number"] = "error"
error[document_number] = "error"
error_message.append("The Driving License format is wrong")
if data["document_type"] == "N" and not re.match(
r"^[X|Y]{1}[ -]?\d{7,8}[ -]?[a-zA-Z]$", data["document_number"]
if data[document_type] == "N" and not re.match(
r"^[X|Y]{1}[ -]?\d{7,8}[ -]?[a-zA-Z]$", data[document_number]
):
error["document_number"] = "error"
error[document_number] = "error"
error_message.append("The Spanish Residence Permit format is wrong")
if data["document_type"] == "X" and not re.match(
r"^[X|Y]{1}[ -]?\d{7,8}[ -]?[a-zA-Z]$", data["document_number"]
if data[document_type] == "X" and not re.match(
r"^[X|Y]{1}[ -]?\d{7,8}[ -]?[a-zA-Z]$", data[document_number]
):
error["document_number"] = "error"
error[document_number] = "error"
error_message.append("The European Residence Permit format is wrong")
elif data["document_type"]:
error["document_number"] = "error"
elif data[document_type]:
error[document_number] = "error"
error_message.append("Document Number not entered")
if data["birthdate_date"] and data["birthdate_date"] > str(
fields.Datetime.today()
):
error["birthdate_date"] = "error"
error_message.append("Birthdate must be less than today")
if data["document_expedition_date"] and data["document_expedition_date"] > str(
fields.Datetime.today()
):
error["document_expedition_date"] = "error"
error_message.append("Expedition Date must be less than today")
if data["email"] and not tools.single_email_re.match(data["email"]):
error["email"] = "error"
error_message.append("Email format is wrong")
if not data["firstname"] and not data["lastname"] and not data["lastname2"]:
error["firstanme"] = "error"
error_message.append("Firstname or any lastname are not included")
return error, error_message

View File

@@ -30,7 +30,7 @@
<input
type="text"
name="firstname"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('firstname') and 'is-invalid' or ''}"
t-att-value="firstname or checkin_partner.firstname"
/>
</div>
@@ -42,7 +42,7 @@
<input
type="text"
name="lastname"
t-attf-class="form-control"
t-attf-class="form-control "
t-att-value="lastname or checkin_partner.lastname"
/>
</div>
@@ -99,7 +99,7 @@
t-esc="checkin_partner.document_type"
/></p></div>
<select
class="form-control"
t-attf-class="form-control #{error.get('document_type') and 'is-invalid' or ''}"
id="doc_type_id"
name="document_type"
t-att-value="document_type or checkin_partner.document_type"
@@ -202,11 +202,7 @@
</thead>
<tbody>
<t t-set="count" t-value="0" />
<form
class="collapse"
action="/my/precheckin/folio_reservation"
method="post"
>
<form action="/my/precheckin/folio_reservation" method="post">
<div
t-if="error_message"
class="alert alert-danger"
@@ -245,58 +241,71 @@
</a>
<div class="row o_portal_details">
<div class="col-lg-8">
<div class="row collapse" t-att-id="id1">
<div t-attf-class="form-group col-xl-6">
<label
<div class="col-lg-8">
<div
class="row collapse"
t-att-id="id1"
>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="firstname"
>Name</label>
<input
<input
type="text"
t-att-name="'firstname-' + str(count)"
t-attf-class="form-control"
t-att-value="firstname or checkin_partner.firstname"
t-attf-class="form-control #{error.get('firstname-'+str(count)) and 'is-invalid' or ''}"
t-att-value="firstname or (checkin_partner.firstname)"
/>
</div>
<div t-attf-class="form-group col-xl-6">
<label
</div>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="lastname"
>Lastname</label>
<input
<input
type="text"
t-att-name="'lastname-' + str(count)"
t-attf-class="form-control"
t-att-value="lastname or checkin_partner.lastname"
/>
</div>
<div t-attf-class="form-group col-xl-6">
<label
</div>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="lastname2"
> Second Lastname</label>
<input
<input
type="text"
t-att-name="'lastname2-' + str(count)"
t-attf-class="form-control"
t-att-value="lastname2 or checkin_partner.lastname2"
/>
</div>
<div t-attf-class="form-group col-xl-6">
<label
</div>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="birthdate_date"
> Birth Date</label>
<input
<input
type="date"
t-att-name="'birthdate_date-'+ str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('birthdate_date-'+str(count)) and 'is-invalid' or ''}"
t-att-value="birthdate_date or checkin_partner.birthdate_date"
/>
</div>
<div t-attf-class="form-group col-xl-6">
<label
</div>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="gender"
>Gender</label>
@@ -312,25 +321,28 @@
t-att-name="'gender-'+ str(count)"
t-att-value="gender or checkin_partner.gender"
>
<option
<option
value=""
>Select an option</option>
<option
<option
value="female"
>Female</option>
<option
<option
value="male"
>Male</option>
<option
<option
value="other"
>Other</option>
</select>
</div>
<div t-attf-class="form-group col-xl-6">
<label
</select>
</div>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="document_type"
>Doc. type</label>
<div class="d-none"><p
class="doc_type_class"
t-att-id="'docTypeId'+str(count)"
@@ -338,53 +350,59 @@
t-esc="checkin_partner.document_type"
/></p></div>
<select
class="form-control select_doc_type_class"
t-attf-class="form-control select_doc_type_class #{error.get('document_type-'+ str(count)) and 'is-invalid' or ''}"
t-att-id="'doc_type_id'+str(count)"
t-att-name="'document_type-'+ str(count)"
t-att-value="document_type or checkin_partner.document_type"
>
<option
<option
value=""
>Select an option</option>
<option value="D">DNI</option>
<option
<option
value="D"
>DNI</option>
<option
value="P"
>Passport</option>
<option
<option
value="C"
>Driving License</option>
<option
<option
value="I"
>Identification Document</option>
<option
<option
value="N"
>Spanish residence permit</option>
<option
<option
value="X"
>European residence permit</option>
</select>
</div>
<div t-attf-class="form-group col-xl-6">
<label
</select>
</div>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="document_number"
>Doc. number</label>
<input
<input
type="text"
t-att-name="'document_number-'+ str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('document_number-'+str(count)) and 'is-invalid' or ''}"
t-att-value="document_number or checkin_partner.document_number"
/>
</div>
<div t-attf-class="form-group col-xl-6">
<label
</div>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="document_expedition_date"
>Doc. expedition date</label>
<input
<input
type="date"
t-att-name="'document_expedition_date-'+ str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('document_expedition_date-'+str(count)) and 'is-invalid' or ''}"
t-att-value="document_expedition_date or checkin_partner.document_expedition_date"
/>
</div>
@@ -393,38 +411,40 @@
class="col-form-label"
for="mobile"
>Mobile</label>
<input
<input
type="phone"
t-att-name="'mobile-'+ str(count)"
t-attf-class="form-control #{error.get('mobile-'+str(count)) and 'is-invalid' or ''}"
t-att-value="mobile or checkin_partner.mobile"
/>
</div>
<div t-attf-class="form-group col-xl-6">
<label
</div>
<div
t-attf-class="form-group col-xl-6"
>
<label
class="col-form-label"
for="email"
>Email</label>
<input
<input
type="email"
t-att-name="'email-'+ str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('email-'+str(count)) and 'is-invalid' or ''}"
t-att-value="email or checkin_partner.email"
/>
</div>
<div
</div>
<div
t-attf-class="form-group col-xl-6 d-none"
>
<input
<input
type="text"
t-att-name="'id-'+ str(count)"
t-attf-class="form-control"
t-att-value="id or checkin_partner.id"
/>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
</t>
@@ -499,11 +519,7 @@
</thead>
<tbody>
<t t-set="count" t-value="0" />
<form
class="collapse"
action="/my/precheckin/folio_reservation"
method="post"
>
<form action="/my/precheckin/folio_reservation" method="post">
<div
t-if="error_message"
class="alert alert-danger"
@@ -576,7 +592,7 @@
<input
type="text"
t-att-name="'firstname-' + str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('firstname-'+str(count)) and 'is-invalid' or ''}"
t-att-value="firstname or (checkin_partner.firstname)"
/>
</div>
@@ -618,7 +634,7 @@
<input
type="date"
t-att-name="'birthdate_date-'+ str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('birthdate_date-'+str(count)) and 'is-invalid' or ''}"
t-att-value="birthdate_date or checkin_partner.birthdate_date"
/>
</div>
@@ -669,7 +685,7 @@
t-esc="checkin_partner.document_type"
/></p></div>
<select
class="form-control select_doc_type_class"
t-attf-class="form-control select_doc_type_class #{error.get('document_type-'+ str(count)) and 'is-invalid' or ''}"
t-att-id="'doc_type_id'+str(count)"
t-att-name="'document_type-'+ str(count)"
t-att-value="document_type or checkin_partner.document_type"
@@ -707,7 +723,7 @@
<input
type="text"
t-att-name="'document_number-'+ str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('document_number-'+str(count)) and 'is-invalid' or ''}"
t-att-value="document_number or checkin_partner.document_number"
/>
</div>
@@ -721,7 +737,7 @@
<input
type="date"
t-att-name="'document_expedition_date-'+ str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('document_expedition_date-'+str(count)) and 'is-invalid' or ''}"
t-att-value="document_expedition_date or checkin_partner.document_expedition_date"
/>
</div>
@@ -749,7 +765,7 @@
<input
type="email"
t-att-name="'email-'+ str(count)"
t-attf-class="form-control"
t-attf-class="form-control #{error.get('email-'+str(count)) and 'is-invalid' or ''}"
t-att-value="email or checkin_partner.email"
/>
</div>