mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP]pms: changes in pms portal
This commit is contained in:
@@ -128,6 +128,16 @@ class PortalFolio(CustomerPortal):
|
||||
return request.redirect("/my")
|
||||
values.update(self._folio_get_page_view_values(folio_sudo, access_token, **kw))
|
||||
values.update({"no_breadcrumbs": True, "error": {}})
|
||||
country_ids = request.env['res.country'].search([])
|
||||
state_ids = request.env['res.country.state'].search([])
|
||||
doc_type_ids = request.env["res.partner.id_category"].sudo().search([])
|
||||
values.update(
|
||||
{
|
||||
"country_ids": country_ids,
|
||||
"state_ids": state_ids,
|
||||
"doc_type_ids": doc_type_ids,
|
||||
}
|
||||
)
|
||||
return request.render("pms.portal_my_folio_precheckin", values)
|
||||
|
||||
|
||||
@@ -261,21 +271,6 @@ class PortalReservation(CustomerPortal):
|
||||
|
||||
|
||||
class PortalPrecheckin(CustomerPortal):
|
||||
def _prepare_home_portal_values(self, counters):
|
||||
partner = request.env.user.partner_id
|
||||
values = super()._prepare_home_portal_values(counters)
|
||||
Reservation = request.env["pms.reservation"].search(
|
||||
[("partner_id", "=", partner.id)]
|
||||
)
|
||||
if "checkin_count" in counters:
|
||||
checkin_partner_count = len(Reservation.checkin_partner_ids)
|
||||
values["checkin_count"] = (
|
||||
checkin_partner_count
|
||||
if Reservation.check_access_rights("read", raise_exception=False)
|
||||
else 0
|
||||
)
|
||||
return values
|
||||
|
||||
def _precheckin_get_page_view_values(self, checkin_partner, access_token, **kwargs):
|
||||
values = {"checkin_partner": checkin_partner, "token": access_token}
|
||||
return self._get_page_view_values(
|
||||
@@ -303,77 +298,95 @@ class PortalPrecheckin(CustomerPortal):
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my")
|
||||
values = self._precheckin_get_page_view_values(checkin_sudo, access_token, **kw)
|
||||
values.update({"no_breadcrumbs": True, "error": {}})
|
||||
country_ids = request.env['res.country'].search([])
|
||||
state_ids = request.env['res.country.state'].search([])
|
||||
doc_type_ids = request.env['res.partner.id_category'].sudo().search([])
|
||||
values.update(
|
||||
{
|
||||
"doc_type_ids": doc_type_ids,
|
||||
"country_ids": country_ids,
|
||||
"state_ids": state_ids,
|
||||
"no_breadcrumbs": True,
|
||||
"error": {}
|
||||
}
|
||||
)
|
||||
return request.render("pms.portal_my_precheckin_detail", values)
|
||||
|
||||
@http.route(["/my/precheckin"], type="http", auth="user", website=True, csrf=False)
|
||||
def portal_precheckin_submit(self, access_token=None, **kw):
|
||||
|
||||
values = dict()
|
||||
checkin_partner = request.env["pms.checkin.partner"].browse(
|
||||
int(kw.get("id"))
|
||||
)
|
||||
values.update(
|
||||
{
|
||||
"checkin_partner": checkin_partner,
|
||||
"error": {},
|
||||
"error_message": [],
|
||||
"error_message": {},
|
||||
}
|
||||
)
|
||||
country_ids = request.env['res.country'].search([])
|
||||
state_ids = request.env['res.country.state'].search([])
|
||||
doc_type_ids = request.env["res.partner.id_category"].sudo().search([])
|
||||
if kw:
|
||||
error, error_message = self.form_validate(kw, None)
|
||||
values.update(
|
||||
{
|
||||
"no_breadcrumbs": True,
|
||||
"error": error,
|
||||
"error_message": error_message,
|
||||
"country_ids": country_ids,
|
||||
"state_ids": state_ids,
|
||||
"doc_type_ids": doc_type_ids,
|
||||
}
|
||||
)
|
||||
if not error:
|
||||
values = kw
|
||||
checkin_partner = request.env["pms.checkin.partner"].browse(
|
||||
int(kw.get("id"))
|
||||
)
|
||||
if not values.get("birthdate_date"):
|
||||
values.update({"birthdate_date": False})
|
||||
if not values.get("document_expedition_date"):
|
||||
values.update({"document_expedition_date": False})
|
||||
lastname = True if values.get("lastname") else False
|
||||
firstname = True if values.get("firstname") else False
|
||||
lastname2 = True if values.get("lastname2") else False
|
||||
if not checkin_partner.partner_id and (
|
||||
lastname or firstname or lastname2
|
||||
):
|
||||
ResPartner = request.env["res.partner"]
|
||||
res_partner = ResPartner.create(values)
|
||||
if error:
|
||||
|
||||
return request.render("pms.portal_my_precheckin_detail", values)
|
||||
else:
|
||||
try:
|
||||
values = kw
|
||||
if values.get("document_type"):
|
||||
doc_type = request.env["res.partner.id_category"].sudo().search([("name", "=", values.get("document_type"))])
|
||||
values.update(
|
||||
{
|
||||
"document_type": doc_type,
|
||||
}
|
||||
)
|
||||
request.env["pms.checkin.partner"].sudo()._save_data_from_portal(values)
|
||||
doc_type_ids = request.env['res.partner.id_category'].sudo().search([])
|
||||
values.update(
|
||||
{
|
||||
"partner_id": res_partner.id,
|
||||
"doc_type_ids": doc_type_ids,
|
||||
}
|
||||
)
|
||||
elif checkin_partner.partner_id:
|
||||
res_partner = checkin_partner.partner_id
|
||||
res_partner.write(values)
|
||||
|
||||
checkin_partner.write(values)
|
||||
values1 = dict()
|
||||
values1.update(
|
||||
{
|
||||
"success": True,
|
||||
"checkin_partner": checkin_partner,
|
||||
"no_breadcrumbs": True,
|
||||
"error": {},
|
||||
}
|
||||
)
|
||||
return request.render("pms.portal_my_precheckin_detail", values1)
|
||||
try:
|
||||
checkin_partner = request.env["pms.checkin.partner"].browse(
|
||||
int(kw.get("id"))
|
||||
)
|
||||
values.update(
|
||||
{
|
||||
"checkin_partner": checkin_partner,
|
||||
"no_breadcrumbs": True,
|
||||
}
|
||||
)
|
||||
return request.render("pms.portal_my_precheckin_detail", values)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my")
|
||||
# if values.get("document_type"):
|
||||
# doc_type_id = values.get("document_type")
|
||||
# doc_type = request.env["res.partner.id_category"].sudo().search([("id", "=", doc_type_id)])
|
||||
# values.update(
|
||||
# {
|
||||
# "document_type": doc_type,
|
||||
# }
|
||||
# )
|
||||
country_ids = request.env['res.country'].search([])
|
||||
state_ids = request.env['res.country.state'].search([])
|
||||
values.update(
|
||||
{
|
||||
"country_ids": country_ids,
|
||||
"state_ids": state_ids,
|
||||
}
|
||||
)
|
||||
values.update(
|
||||
{
|
||||
"success": True,
|
||||
"checkin_partner": checkin_partner,
|
||||
"no_breadcrumbs": True,
|
||||
"error": {},
|
||||
}
|
||||
)
|
||||
return request.render("pms.portal_my_precheckin_detail", values)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my")
|
||||
|
||||
@http.route(
|
||||
["/my/precheckin/folio_reservation"],
|
||||
@@ -384,7 +397,7 @@ class PortalPrecheckin(CustomerPortal):
|
||||
)
|
||||
def portal_precheckin_folio_submit(self, **kw):
|
||||
errors = {}
|
||||
e_messages = []
|
||||
e_messages = {}
|
||||
counter = 1
|
||||
has_error = False
|
||||
checkin_partners = False
|
||||
@@ -396,47 +409,51 @@ class PortalPrecheckin(CustomerPortal):
|
||||
int(kw.get("reservation_id"))
|
||||
)
|
||||
checkin_partners = reservation.checkin_partner_ids
|
||||
country_ids = request.env['res.country'].search([])
|
||||
state_ids = request.env['res.country.state'].search([])
|
||||
doc_type_ids = request.env["res.partner.id_category"].sudo().search([])
|
||||
values = {
|
||||
"no_breadcrumbs": True,
|
||||
"country_ids": country_ids,
|
||||
"state_ids": state_ids,
|
||||
"doc_type_ids": doc_type_ids,
|
||||
}
|
||||
for checkin in checkin_partners:
|
||||
values = {
|
||||
"firstname": kw.get("firstname-" + str(counter)),
|
||||
"lastname": kw.get("lastname-" + str(counter)),
|
||||
"lastname2": kw.get("lastname2-" + str(counter)),
|
||||
"gender": kw.get("gender-" + str(counter)),
|
||||
"birthdate_date": kw.get("birthdate_date-" + str(counter))
|
||||
if kw.get("birthdate_date-" + str(counter))
|
||||
else False,
|
||||
"document_type": kw.get("document_type-" + str(counter)),
|
||||
"document_number": kw.get("document_number-" + str(counter)),
|
||||
"document_expedition_date": kw.get(
|
||||
"document_expedition_date-" + str(counter)
|
||||
values.update(
|
||||
{
|
||||
"id": kw.get("id-" + str(counter)),
|
||||
"firstname": kw.get("firstname-" + str(counter)),
|
||||
"lastname": kw.get("lastname-" + str(counter)),
|
||||
"lastname2": kw.get("lastname2-" + str(counter)),
|
||||
"gender": kw.get("gender-" + str(counter)),
|
||||
"birthdate_date": kw.get("birthdate_date-" + str(counter))
|
||||
if kw.get("birthdate_date-" + str(counter))
|
||||
else False,
|
||||
"document_type": kw.get("document_type-" + str(counter)),
|
||||
"document_number": kw.get("document_number-" + str(counter)),
|
||||
"document_expedition_date": kw.get(
|
||||
"document_expedition_date-" + str(counter)
|
||||
)
|
||||
if kw.get("document_expedition_date-" + str(counter))
|
||||
else False,
|
||||
"mobile": kw.get("mobile-" + str(counter)),
|
||||
"email": kw.get("email-" + str(counter)),
|
||||
}
|
||||
)
|
||||
if values.get("document_type"):
|
||||
doc_type_code = values.get("document_type")
|
||||
doc_type = request.env["res.partner.id_category"].sudo().search([("code", "=", doc_type_code)])
|
||||
values.update(
|
||||
{
|
||||
"document_type": doc_type,
|
||||
}
|
||||
)
|
||||
if kw.get("document_expedition_date-" + str(counter))
|
||||
else False,
|
||||
"mobile": kw.get("mobile-" + str(counter)),
|
||||
"email": kw.get("email-" + str(counter)),
|
||||
}
|
||||
error, error_message = self.form_validate(kw, counter)
|
||||
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
|
||||
firstname = True if kw.get("firstname-" + str(counter)) else False
|
||||
lastname2 = True if kw.get("lastname2-" + str(counter)) else False
|
||||
if not checkin.partner_id and (lastname or firstname or lastname2):
|
||||
ResPartner = request.env["res.partner"]
|
||||
res_partner = ResPartner.create(values)
|
||||
values.update(
|
||||
{
|
||||
"partner_id": res_partner.id,
|
||||
}
|
||||
)
|
||||
elif checkin.partner_id:
|
||||
res_partner = checkin.partner_id
|
||||
res_partner.write(values)
|
||||
checkin.write(values)
|
||||
checkin.sudo()._save_data_from_portal(values)
|
||||
counter = counter + 1
|
||||
values = {"no_breadcrumbs": True}
|
||||
|
||||
@@ -480,7 +497,7 @@ class PortalPrecheckin(CustomerPortal):
|
||||
data[mobile],
|
||||
):
|
||||
error[mobile] = "error"
|
||||
error_message.append("Invalid phone")
|
||||
error_message[mobile] = "Invalid phone"
|
||||
birthdate_date = (
|
||||
"birthdate_date"
|
||||
if "birthdate_date" in keys
|
||||
@@ -488,32 +505,22 @@ class PortalPrecheckin(CustomerPortal):
|
||||
)
|
||||
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")
|
||||
error_message[birthdate_date] = "Birthdate 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")
|
||||
error_message[email] = "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")
|
||||
error_message[firstname] = "Firstname or any lastname are not included"
|
||||
return error, error_message
|
||||
|
||||
def form_document_validate(self, data, counter):
|
||||
error = dict()
|
||||
error_message = []
|
||||
error_message = {}
|
||||
keys = data.keys()
|
||||
document_number = (
|
||||
"document_number"
|
||||
@@ -525,28 +532,23 @@ class PortalPrecheckin(CustomerPortal):
|
||||
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])]
|
||||
document_expedition_date = (
|
||||
"document_expedition_date"
|
||||
if "document_expedition_date" in keys
|
||||
else "document_expedition_date-" + str(counter)
|
||||
)
|
||||
partner_id = checkin_partner.partner_id.id
|
||||
if partner_id:
|
||||
partners = request.env["res.partner"].search(
|
||||
[("id", "!=", str(partner_id))]
|
||||
)
|
||||
if data[document_expedition_date] and not data[document_number]:
|
||||
error[document_expedition_date] = "error"
|
||||
error_message[document_expedition_date] = "Document Number not entered and Document Type is not selected"
|
||||
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")
|
||||
error_message[document_type] ="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"
|
||||
error_message.append("The DNI format is wrong")
|
||||
error_message[document_number] = "The DNI format is wrong"
|
||||
letters = {
|
||||
0: "T",
|
||||
1: "R",
|
||||
@@ -574,30 +576,44 @@ class PortalPrecheckin(CustomerPortal):
|
||||
}
|
||||
dni_number = data[document_number][0:8]
|
||||
dni_letter = data[document_number][
|
||||
len(data[document_number]) - 1 : len(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_message.append("DNI is invalid")
|
||||
error_message[document_number] = "DNI format is invalid"
|
||||
else:
|
||||
error[document_number] = "error"
|
||||
error_message.append("DNI is invalid")
|
||||
error_message[document_number] = "DNI is invalid"
|
||||
if data[document_type] == "C" and not re.match(
|
||||
r"^\d{8}[ -]?[a-zA-Z]$", data[document_number]
|
||||
):
|
||||
error[document_number] = "error"
|
||||
error_message.append("The Driving License format is wrong")
|
||||
error_message[document_number] = "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]
|
||||
):
|
||||
error[document_number] = "error"
|
||||
error_message.append("The Spanish Residence Permit format is wrong")
|
||||
error_message[document_number] = "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]
|
||||
):
|
||||
error[document_number] = "error"
|
||||
error_message.append("The European Residence Permit format is wrong")
|
||||
error_message[document_number] = "The European Residence Permit format is wrong"
|
||||
elif data[document_type]:
|
||||
error[document_number] = "error"
|
||||
error_message.append("Document Number not entered")
|
||||
error_message[document_number] = "Document Number not entered"
|
||||
return error, error_message
|
||||
|
||||
|
||||
@http.route(
|
||||
["/my/precheckin/send_invitation"],
|
||||
auth="user",
|
||||
website=True,
|
||||
csrf=False,
|
||||
)
|
||||
def portal_precheckin_folio_send_invitation(self, **kw):
|
||||
print(kw)
|
||||
# checkin_partner_id = kw.get("checkin_partner_id")
|
||||
# checkin_partner = request.env["pms.checkin.partner"].search([("id", "=", checkin_partner_id)])
|
||||
# print(checkin_partner)
|
||||
return request.redirect("/my")
|
||||
|
||||
Reference in New Issue
Block a user