mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP]pms: refactor precheckin
This commit is contained in:
@@ -6,6 +6,7 @@ from odoo.http import request
|
||||
|
||||
from odoo.addons.payment.controllers.portal import PaymentProcessing
|
||||
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
|
||||
from odoo.addons.portal.models.portal_mixin import PortalMixin
|
||||
|
||||
|
||||
class PortalFolio(CustomerPortal):
|
||||
@@ -182,38 +183,6 @@ class PortalFolio(CustomerPortal):
|
||||
values = self._folio_get_page_view_values(folio_sudo, access_token, **kw)
|
||||
return request.render("pms.folio_portal_template", values)
|
||||
|
||||
@http.route(
|
||||
["/my/folios/<int:folio_id>/precheckin"],
|
||||
type="http",
|
||||
auth="public",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_folio_precheckin(
|
||||
self, folio_id, access_token=None, report_type=None, download=False, **kw
|
||||
):
|
||||
values = self._prepare_portal_layout_values()
|
||||
try:
|
||||
folio_sudo = self._document_check_access(
|
||||
"pms.folio",
|
||||
folio_id,
|
||||
access_token=access_token,
|
||||
)
|
||||
except (AccessError, MissingError):
|
||||
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)
|
||||
|
||||
|
||||
class PortalReservation(CustomerPortal):
|
||||
def _prepare_home_portal_values(self, counters):
|
||||
@@ -316,41 +285,13 @@ class PortalReservation(CustomerPortal):
|
||||
)
|
||||
return request.render("pms.portal_my_reservation_detail", values)
|
||||
|
||||
@http.route(
|
||||
["/my/reservations/<int:reservation_id>/precheckin"],
|
||||
type="http",
|
||||
auth="public",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_reservation_precheckin(self, reservation_id, access_token=None, **kw):
|
||||
try:
|
||||
reservation_sudo = self._document_check_access(
|
||||
"pms.reservation",
|
||||
reservation_id,
|
||||
access_token=access_token,
|
||||
)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my")
|
||||
values = self._reservation_get_page_view_values(
|
||||
reservation_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_reservation_precheckin", values)
|
||||
|
||||
|
||||
class PortalPrecheckin(CustomerPortal):
|
||||
def _precheckin_get_page_view_values(self, checkin_partner, access_token, **kwargs):
|
||||
values = {"checkin_partner": checkin_partner, "token": access_token}
|
||||
def _precheckin_get_page_view_values(
|
||||
self, checkin_partner_id, access_token, **kwargs
|
||||
):
|
||||
checkin_partner = request.env["pms.checkin.partner"].browse(checkin_partner_id)
|
||||
values = {"checkin_partner_id": checkin_partner, "token": access_token}
|
||||
return self._get_page_view_values(
|
||||
checkin_partner,
|
||||
access_token,
|
||||
@@ -361,280 +302,169 @@ class PortalPrecheckin(CustomerPortal):
|
||||
)
|
||||
|
||||
@http.route(
|
||||
["/my/precheckin/<int:checkin_partner_id>"],
|
||||
["/my/folios/<int:folio_id>/precheckin"],
|
||||
type="http",
|
||||
auth="public",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_precheckin_detail(self, checkin_partner_id, access_token=None, **kw):
|
||||
def portal_my_precheckin(
|
||||
self,
|
||||
folio_id,
|
||||
access_token=None,
|
||||
):
|
||||
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 = self._prepare_portal_layout_values()
|
||||
try:
|
||||
checkin_sudo = self._document_check_access(
|
||||
"pms.checkin.partner",
|
||||
checkin_partner_id,
|
||||
folio_sudo = self._document_check_access(
|
||||
"pms.folio",
|
||||
folio_id,
|
||||
access_token=access_token,
|
||||
)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my")
|
||||
values = self._precheckin_get_page_view_values(checkin_sudo, access_token, **kw)
|
||||
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([])
|
||||
checkin_partner = folio_sudo.checkin_partner_ids[0]
|
||||
values.update(
|
||||
{
|
||||
"doc_type_ids": doc_type_ids,
|
||||
"country_ids": country_ids,
|
||||
"state_ids": state_ids,
|
||||
"no_breadcrumbs": True,
|
||||
"error": {},
|
||||
"country_ids": country_ids,
|
||||
"state_ids": state_ids,
|
||||
"doc_type_ids": doc_type_ids,
|
||||
"folio": folio_sudo,
|
||||
"checkin_partner_id": checkin_partner,
|
||||
}
|
||||
)
|
||||
return request.render("pms.portal_my_precheckin_detail", values)
|
||||
return request.render("pms.portal_my_reservation_precheckin", values)
|
||||
|
||||
@http.route(
|
||||
["/my/precheckin"], type="http", auth="public", website=True, csrf=False
|
||||
)
|
||||
def portal_precheckin_submit(self, **kw):
|
||||
values = dict()
|
||||
checkin_partner = request.env["pms.checkin.partner"].browse(int(kw.get("id")))
|
||||
values.update(
|
||||
{
|
||||
"checkin_partner": checkin_partner,
|
||||
"error": {},
|
||||
"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 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.id,
|
||||
}
|
||||
)
|
||||
request.env["pms.checkin.partner"].sudo()._save_data_from_portal(
|
||||
values
|
||||
)
|
||||
doc_type_ids = (
|
||||
request.env["res.partner.id_category"].sudo().search([])
|
||||
)
|
||||
values.update(
|
||||
{
|
||||
"doc_type_ids": doc_type_ids,
|
||||
}
|
||||
)
|
||||
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"],
|
||||
["/my/precheckin/<int:folio_id>/checkin/<int:checkin_partner_id>"],
|
||||
type="http",
|
||||
auth="public",
|
||||
website=True,
|
||||
csrf=False,
|
||||
)
|
||||
def portal_precheckin_folio_submit(self, **kw):
|
||||
errors = {}
|
||||
e_messages = {}
|
||||
counter = 1
|
||||
has_error = False
|
||||
checkin_partners = False
|
||||
if kw.get("folio_id"):
|
||||
folio = request.env["pms.folio"].sudo().browse(int(kw.get("folio_id")))
|
||||
checkin_partners = folio.checkin_partner_ids
|
||||
elif kw.get("reservation_id"):
|
||||
reservation = (
|
||||
request.env["pms.reservation"]
|
||||
.sudo()
|
||||
.browse(int(kw.get("reservation_id")))
|
||||
)
|
||||
checkin_partners = reservation.checkin_partner_ids
|
||||
for checkin in checkin_partners:
|
||||
values = {
|
||||
"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)),
|
||||
"nationality_id": kw.get("nationality_id-" + str(counter)),
|
||||
"state": kw.get("state-" + str(counter)),
|
||||
}
|
||||
|
||||
if values.get("document_type"):
|
||||
doc_type_code = values.get("document_type")
|
||||
doc_type = (
|
||||
request.env["res.partner.id_category"]
|
||||
.sudo()
|
||||
.search([("name", "=", doc_type_code)])
|
||||
)
|
||||
values.update(
|
||||
{
|
||||
"document_type": doc_type.id,
|
||||
}
|
||||
)
|
||||
error, error_message = self.form_validate(kw, counter)
|
||||
errors.update(error)
|
||||
e_messages.update(error_message)
|
||||
if error_message:
|
||||
has_error = True
|
||||
else:
|
||||
checkin.sudo()._save_data_from_portal(values)
|
||||
counter = counter + 1
|
||||
values = {"no_breadcrumbs": True}
|
||||
doc_type_ids = request.env["res.partner.id_category"].sudo().search([])
|
||||
def portal_precheckin_submit(self, folio_id, checkin_partner_id, **kw):
|
||||
error, error_message = {}, {}
|
||||
checkin_pos = int(kw.get("checkin_pos"))
|
||||
folio_id = request.env["pms.folio"].browse(folio_id)
|
||||
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 = kw
|
||||
if not kw.get("first"):
|
||||
error, error_message = self.form_validate(kw, None)
|
||||
if not kw.get("first") and not error:
|
||||
kw.update({"checkin_partner_id": checkin_partner_id})
|
||||
request.env["pms.checkin.partner"]._save_data_from_portal(kw)
|
||||
if error:
|
||||
checkin_pos = checkin_pos - 1
|
||||
values.update({"checkin_pos": checkin_pos})
|
||||
if checkin_pos == len(folio_id.checkin_partner_ids):
|
||||
values = {
|
||||
"folio": folio_id,
|
||||
"no_breadcrumbs": True,
|
||||
}
|
||||
return request.render("pms.portal_my_precheckin_end", values)
|
||||
values.update(
|
||||
{
|
||||
"doc_type_ids": doc_type_ids,
|
||||
"folio": folio_id,
|
||||
"error": error,
|
||||
"error_message": error_message,
|
||||
"country_ids": country_ids,
|
||||
"state_ids": state_ids,
|
||||
"doc_type_ids": doc_type_ids,
|
||||
"checkin_pos": checkin_pos,
|
||||
}
|
||||
)
|
||||
if has_error:
|
||||
filtered_dict_error = {k: v for k, v in errors.items() if v}
|
||||
filtered_dict_error_messages = {k: v for k, v in e_messages.items() if v}
|
||||
values.update(
|
||||
{
|
||||
"error": filtered_dict_error,
|
||||
"error_message": filtered_dict_error_messages,
|
||||
}
|
||||
checkin_partner_id = folio_id.checkin_partner_ids[checkin_pos]
|
||||
access_token = checkin_partner_id.access_token
|
||||
if not checkin_partner_id.access_token:
|
||||
access_token = PortalMixin._portal_ensure_token(checkin_partner_id)
|
||||
values.update(
|
||||
self._precheckin_get_page_view_values(checkin_partner_id.id, access_token)
|
||||
)
|
||||
values.update({"no_breadcrumbs": True})
|
||||
return request.render("pms.portal_my_precheckin_detail", values)
|
||||
|
||||
@http.route(
|
||||
["/my/folios/<int:folio_id>/invitations"],
|
||||
type="http",
|
||||
auth="public",
|
||||
website=True,
|
||||
csrf=False,
|
||||
)
|
||||
def portal_precheckin_invitation(self, folio_id, access_token=None, **kw):
|
||||
try:
|
||||
folio_sudo = self._document_check_access(
|
||||
"pms.folio",
|
||||
folio_id,
|
||||
access_token=access_token,
|
||||
)
|
||||
else:
|
||||
values.update({"success": True, "error": {}})
|
||||
if kw.get("folio_id"):
|
||||
folio = request.env["pms.folio"].sudo().browse(int(kw.get("folio_id")))
|
||||
values.update(
|
||||
{
|
||||
"folio": folio,
|
||||
}
|
||||
)
|
||||
return request.render("pms.portal_my_folio_precheckin", values)
|
||||
elif kw.get("reservation_id"):
|
||||
reservation = request.env["pms.reservation"].browse(
|
||||
int(kw.get("reservation_id"))
|
||||
)
|
||||
values.update(
|
||||
{
|
||||
"reservation": reservation,
|
||||
}
|
||||
)
|
||||
return request.render("pms.portal_my_reservation_precheckin", values)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my")
|
||||
values = self._folio_get_page_view_values(folio_sudo, access_token, **kw)
|
||||
values.update({"no_breadcrumbs": True, "error": {}})
|
||||
return request.render("pms.portal_my_folio_invitations", values)
|
||||
|
||||
def form_validate(self, data, counter):
|
||||
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]:
|
||||
if not re.match(
|
||||
r"^(\d{3}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?|"
|
||||
r"\d{3}[\-\s]?\d{3}[\-\s]?\d{3})$",
|
||||
data[mobile],
|
||||
error, error_message = {}, {}
|
||||
if data.get("checkin_pos") != "-1":
|
||||
error, error_message = self.form_document_validate(data, counter)
|
||||
mobile = "mobile"
|
||||
if data.get("mobile"):
|
||||
if not re.match(
|
||||
r"^(\d{3}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?\d{2}[\-\s]?|"
|
||||
r"\d{3}[\-\s]?\d{3}[\-\s]?\d{3})$",
|
||||
data[mobile],
|
||||
):
|
||||
error[mobile] = "error"
|
||||
error_message[mobile] = "Invalid phone"
|
||||
birthdate_date = "birthdate_date"
|
||||
if data.get("birthdate_date") and data.get("birthdate_date") > str(
|
||||
fields.Datetime.today()
|
||||
):
|
||||
error[mobile] = "error"
|
||||
error_message[mobile] = "Invalid phone"
|
||||
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[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[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[firstname] = "Firstname or any lastname are not included"
|
||||
error[birthdate_date] = "error"
|
||||
error_message[birthdate_date] = "Birthdate must be less than today"
|
||||
email = "email"
|
||||
if data.get("email") and not tools.single_email_re.match(data.get("email")):
|
||||
error[email] = "error"
|
||||
error_message[email] = "Email format is wrong"
|
||||
firstname = "firstname"
|
||||
if (
|
||||
not data.get("firstname")
|
||||
and not data.get("lastname")
|
||||
and not data.get("lastname2")
|
||||
):
|
||||
error[firstname] = "error"
|
||||
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 = {}
|
||||
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)
|
||||
)
|
||||
document_expedition_date = (
|
||||
"document_expedition_date"
|
||||
if "document_expedition_date" in keys
|
||||
else "document_expedition_date-" + str(counter)
|
||||
)
|
||||
if data[document_expedition_date] and not data[document_number]:
|
||||
data.keys()
|
||||
document_number = "document_number"
|
||||
document_type = "document_type"
|
||||
document_expedition_date = "document_expedition_date"
|
||||
if data.get("document_expedition_date") and not data.get("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]:
|
||||
if data.get("document_number"):
|
||||
if not data[document_type]:
|
||||
error[document_type] = "error"
|
||||
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]):
|
||||
if (
|
||||
len(data.get("document_number")) == 9
|
||||
or len(data.get("document_number")) == 10
|
||||
):
|
||||
if not re.match(
|
||||
r"^\d{8}[ -]?[a-zA-Z]$", data.get("document_number")
|
||||
):
|
||||
error[document_number] = "error"
|
||||
error_message[document_number] = "The DNI format is wrong"
|
||||
letters = {
|
||||
@@ -662,9 +492,10 @@ 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.get("document_number")[0:8]
|
||||
dni_letter = data.get("document_number")[
|
||||
len(data.get("document_number"))
|
||||
- 1 : len(data.get("document_number"))
|
||||
]
|
||||
if letters.get(int(dni_number) % 23) != dni_letter.upper():
|
||||
error[document_number] = "error"
|
||||
@@ -673,25 +504,25 @@ class PortalPrecheckin(CustomerPortal):
|
||||
error[document_number] = "error"
|
||||
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]
|
||||
r"^\d{8}[ -]?[a-zA-Z]$", data.get("document_number")
|
||||
):
|
||||
error[document_number] = "error"
|
||||
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]
|
||||
r"^[X|Y]{1}[ -]?\d{7,8}[ -]?[a-zA-Z]$", data.get("document_number")
|
||||
):
|
||||
error[document_number] = "error"
|
||||
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]
|
||||
r"^[X|Y]{1}[ -]?\d{7,8}[ -]?[a-zA-Z]$", data.get("document_number")
|
||||
):
|
||||
error[document_number] = "error"
|
||||
error_message[
|
||||
document_number
|
||||
] = "The European Residence Permit format is wrong"
|
||||
elif data[document_type]:
|
||||
elif data.get("document_type"):
|
||||
error[document_number] = "error"
|
||||
error_message[document_number] = "Document Number not entered"
|
||||
return error, error_message
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a
|
||||
href="/my/precheckin/${object.id}?access_token=${object.access_token}"
|
||||
href="${object.get_portal_url()}"
|
||||
target="_blank"
|
||||
style="text-decoration: none; color: #FFFFFF; font-size: 2em; padding: 10px 20px 10px 20px;"
|
||||
>
|
||||
@@ -42,7 +42,7 @@
|
||||
alt="Hacer check-in"
|
||||
width="80px"
|
||||
height="80px"
|
||||
href="${object.url}"
|
||||
href="${object.get_portal_url()}"
|
||||
/></center></a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -467,7 +467,10 @@ class PmsCheckinPartner(models.Model):
|
||||
def _compute_access_url(self):
|
||||
super(PmsCheckinPartner, self)._compute_access_url()
|
||||
for checkin in self:
|
||||
checkin.access_url = "/my/precheckin/%s" % (checkin.id)
|
||||
checkin.access_url = "/my/precheckin/%s/checkin/%s" % (
|
||||
checkin.folio_id.id,
|
||||
checkin.id,
|
||||
)
|
||||
|
||||
# Constraints and onchanges
|
||||
|
||||
@@ -665,16 +668,14 @@ class PmsCheckinPartner(models.Model):
|
||||
return datetime_doc_date
|
||||
datetime_birthdate = datetime.strptime(birthdate, DEFAULT_SERVER_DATE_FORMAT)
|
||||
age = today.year - datetime_birthdate.year
|
||||
document_type = self.env["res.partner.id_category"].search(
|
||||
[("id", "=", doc_type)]
|
||||
)
|
||||
|
||||
document_expedition_date = False
|
||||
if document_type.code == "D" or document_type.code == "P":
|
||||
if doc_type.code == "D" or doc_type.code == "P":
|
||||
if age < 30:
|
||||
document_expedition_date = datetime_doc_date - relativedelta(years=5)
|
||||
else:
|
||||
document_expedition_date = datetime_doc_date - relativedelta(years=10)
|
||||
if document_type.code == "C":
|
||||
if doc_type.code == "C":
|
||||
if age < 70:
|
||||
document_expedition_date = datetime_doc_date - relativedelta(years=10)
|
||||
return document_expedition_date
|
||||
@@ -736,7 +737,15 @@ class PmsCheckinPartner(models.Model):
|
||||
}
|
||||
|
||||
def _save_data_from_portal(self, values):
|
||||
checkin_partner = self.env["pms.checkin.partner"].browse(int(values.get("id")))
|
||||
checkin_partner = self.env["pms.checkin.partner"].browse(
|
||||
int(values.get("checkin_partner_id"))
|
||||
)
|
||||
if values.get("checkin_partner_id"):
|
||||
values.pop("checkin_partner_id")
|
||||
if values.get("checkin_pos"):
|
||||
values.pop("checkin_pos")
|
||||
if values.get("first"):
|
||||
values.pop("first")
|
||||
if values.get("nationality_id"):
|
||||
nationality_id = self.env["res.country"].search(
|
||||
[("id", "=", values.get("nationality_id"))]
|
||||
@@ -754,6 +763,9 @@ class PmsCheckinPartner(models.Model):
|
||||
values.pop("state")
|
||||
if values.get("document_expedition_date"):
|
||||
doc_type = values.get("document_type")
|
||||
doc_type = self.env["res.partner.id_category"].search(
|
||||
[("name", "=", doc_type)]
|
||||
)
|
||||
doc_date = values.get("document_expedition_date")
|
||||
birthdate = values.get("birthdate_date")
|
||||
document_expedition_date = (
|
||||
@@ -761,7 +773,13 @@ class PmsCheckinPartner(models.Model):
|
||||
doc_type, doc_date, birthdate
|
||||
)
|
||||
)
|
||||
values.update({"document_expedition_date": document_expedition_date})
|
||||
values.update(
|
||||
{
|
||||
"document_expedition_date": document_expedition_date,
|
||||
"document_type": doc_type,
|
||||
}
|
||||
)
|
||||
|
||||
checkin_partner.sudo().write(values)
|
||||
|
||||
def send_portal_invitation_email(self, invitation_firstname=None, email=None):
|
||||
|
||||
@@ -1201,9 +1201,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
is = 20 years old and document_date = today + 1 year. The expected
|
||||
expedition date has to be doc_date - 5 years
|
||||
"""
|
||||
doc_type_id = (
|
||||
self.env["res.partner.id_category"].search([("code", "=", "D")]).id
|
||||
)
|
||||
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "D")])
|
||||
doc_date = fields.date.today() + datetime.timedelta(days=366)
|
||||
doc_date_str = str(doc_date)
|
||||
|
||||
@@ -1240,9 +1238,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
is = 40 years old and document_date = today + 1 year. The expected
|
||||
expedition date has to be doc_date - 10 years
|
||||
"""
|
||||
doc_type_id = (
|
||||
self.env["res.partner.id_category"].search([("code", "=", "D")]).id
|
||||
)
|
||||
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "D")])
|
||||
doc_date = fields.date.today() + datetime.timedelta(days=366)
|
||||
doc_date_str = str(doc_date)
|
||||
|
||||
@@ -1279,9 +1275,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
is = 20 years old and document_date = today + 1 year. The expected
|
||||
expedition date has to be doc_date - 5 years
|
||||
"""
|
||||
doc_type_id = (
|
||||
self.env["res.partner.id_category"].search([("code", "=", "P")]).id
|
||||
)
|
||||
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "P")])
|
||||
doc_date = fields.date.today() + datetime.timedelta(days=366)
|
||||
doc_date_str = str(doc_date)
|
||||
|
||||
@@ -1318,9 +1312,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
is = 40 years old and document_date = today + 1 year. The expected
|
||||
expedition date has to be doc_date - 10 years
|
||||
"""
|
||||
doc_type_id = (
|
||||
self.env["res.partner.id_category"].search([("code", "=", "P")]).id
|
||||
)
|
||||
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "P")])
|
||||
doc_date = fields.date.today() + datetime.timedelta(days=366)
|
||||
doc_date_str = str(doc_date)
|
||||
|
||||
@@ -1357,9 +1349,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
is = 40 years old and document_date = today + 1 year. The expected
|
||||
expedition date has to be doc_date - 10 years
|
||||
"""
|
||||
doc_type_id = (
|
||||
self.env["res.partner.id_category"].search([("code", "=", "C")]).id
|
||||
)
|
||||
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "C")])
|
||||
doc_date = fields.date.today() + datetime.timedelta(days=366)
|
||||
doc_date_str = str(doc_date)
|
||||
|
||||
@@ -1396,9 +1386,7 @@ class TestPmsCheckinPartner(TestPms):
|
||||
is = 20 years old and document_date = today - 1 year. The expected
|
||||
expedition date has to be the value of doc_date.
|
||||
"""
|
||||
doc_type_id = (
|
||||
self.env["res.partner.id_category"].search([("code", "=", "D")]).id
|
||||
)
|
||||
doc_type_id = self.env["res.partner.id_category"].search([("code", "=", "D")])
|
||||
doc_date = fields.date.today() - datetime.timedelta(days=366)
|
||||
doc_date_str = str(doc_date)
|
||||
birthdate = fields.date.today() - datetime.timedelta(days=7305)
|
||||
@@ -1443,11 +1431,12 @@ class TestPmsCheckinPartner(TestPms):
|
||||
)
|
||||
checkin_partner_id = self.reservation.checkin_partner_ids[0]
|
||||
checkin_partner_vals = {
|
||||
"checkin_partner_id": checkin_partner_id.id,
|
||||
"id": checkin_partner_id.id,
|
||||
"firstname": "Serafín",
|
||||
"lastname": "Rivas",
|
||||
"lastname2": "Gonzalez",
|
||||
"document_type": self.id_category,
|
||||
"document_type": self.id_category.name,
|
||||
"document_number": "18038946T",
|
||||
"document_expedition_date": "2015-10-07",
|
||||
"birthdate_date": "1983-10-05",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user