diff --git a/pms/controllers/pms_portal.py b/pms/controllers/pms_portal.py index f38486067..ae6067b66 100644 --- a/pms/controllers/pms_portal.py +++ b/pms/controllers/pms_portal.py @@ -324,7 +324,14 @@ class PortalPrecheckin(CustomerPortal): ) except (AccessError, MissingError): return request.redirect("/my") - checkin_partner = folio_sudo.checkin_partner_ids[0] + available_checkins = folio_sudo.checkin_partner_ids.filtered( + lambda c: c.state in ["dummy", "draft"] + ) + checkin_partner = ( + available_checkins[0] + if available_checkins + else folio_sudo.checkin_partner_ids[0] + ) values.update( { "no_breadcrumbs": True, @@ -371,7 +378,7 @@ class PortalPrecheckin(CustomerPortal): if error: checkin_pos = checkin_pos - 1 values.update({"checkin_pos": checkin_pos}) - if checkin_pos == len(folio_id.checkin_partner_ids): + if checkin_pos == len(folio_id.checkin_partner_ids) or checkin_pos == -2: values = { "folio": folio_id, "no_breadcrumbs": True, @@ -389,21 +396,21 @@ class PortalPrecheckin(CustomerPortal): } ) if checkin_pos >= 0: - checkin_partner_id = folio_id.checkin_partner_ids[checkin_pos] - elif checkin_pos == -2: - checkin_partner_id = request.env["pms.checkin.partner"].browse( - checkin_partner_id + available_checkins = folio_id.checkin_partner_ids.filtered( + lambda c: c.state in ["dummy", "draft"] ) - elif checkin_pos == -1: - return - access_token = checkin_partner_id.access_token - if not checkin_partner_id.access_token: - access_token = PortalMixin._portal_ensure_token(checkin_partner_id) + if available_checkins: + checkin_partner = available_checkins[0] + else: + return request.render("pms.portal_not_checkin", values) + access_token = checkin_partner.access_token + if not checkin_partner.access_token: + access_token = PortalMixin._portal_ensure_token(checkin_partner) values.update( - self._precheckin_get_page_view_values(checkin_partner_id.id, access_token) + self._precheckin_get_page_view_values(checkin_partner.id, access_token) ) values.update({"no_breadcrumbs": True}) - if checkin_partner_id.state not in ["dummy", "draft"]: + if checkin_partner.state not in ["dummy", "draft"]: return request.render("pms.portal_not_checkin", values) return request.render("pms.portal_my_precheckin_detail", values) @@ -416,7 +423,7 @@ class PortalPrecheckin(CustomerPortal): ) def portal_precheckin_invitation(self, folio_id, access_token=None, **kw): try: - folio_sudo = self.sudo()._document_check_access( + folio_sudo = self._document_check_access( "pms.folio", folio_id, access_token=access_token, @@ -463,6 +470,35 @@ class PortalPrecheckin(CustomerPortal): ): error[firstname] = "error" error_message[firstname] = "Firstname or any lastname are not included" + if not data.get("gender"): + error["gender"] = "error" + error_message["gender"] = "Gender is mandatory" + if not data.get("document_number"): + error["document_number"] = "error" + error_message["document_number"] = "Document number is mandatory" + if not data.get("document_type"): + error["document_type"] = "error" + error_message["document_type"] = "Document type is mandatory" + if not data.get("document_expedition_date"): + error["document_expedition_date"] = "error" + error_message[ + "document_expedition_date" + ] = "Document expedition date is mandatory" + if not data.get("birthdate_date"): + error["birthdate_date"] = "error" + error_message["birthdate_date"] = "Birth date is mandatory" + if not data.get("nationality_id"): + error["nationality_id"] = "error" + error_message["nationality_id"] = "Nationality is mandatory" + if ( + not data.get("residence_street") + or not data.get("residence_city") + or not data.get("residence_zip") + or data.get("residence_country_id") == "placeholder" + or data.get("residence_state_id") == "placeholder" + ): + error["address"] = "error" + error_message["address"] = "Address data is mandatory" return error, error_message def form_document_validate(self, data, counter): diff --git a/pms/models/pms_checkin_partner.py b/pms/models/pms_checkin_partner.py index a593f4e7e..6e273322e 100644 --- a/pms/models/pms_checkin_partner.py +++ b/pms/models/pms_checkin_partner.py @@ -470,12 +470,16 @@ class PmsCheckinPartner(models.Model): and record.document_number and record.document_type ): - id_number_id = self.env["res.partner.id_number"].search( - [ - ("partner_id", "=", record.partner_id.id), - ("name", "=", record.document_number), - ("category_id", "=", record.document_type.id), - ] + id_number_id = ( + self.sudo() + .env["res.partner.id_number"] + .search( + [ + ("partner_id", "=", record.partner_id.id), + ("name", "=", record.document_number), + ("category_id", "=", record.document_type.id), + ] + ) ) if not id_number_id: id_number_id = self.env["res.partner.id_number"].create( @@ -502,14 +506,20 @@ class PmsCheckinPartner(models.Model): for record in self: if not record.partner_id: if record.document_number and record.document_type: - number = self.env["res.partner.id_number"].search( - [ - ("name", "=", record.document_number), - ("category_id", "=", record.document_type.id), - ] + number = ( + self.sudo() + .env["res.partner.id_number"] + .search( + [ + ("name", "=", record.document_number), + ("category_id", "=", record.document_type.id), + ] + ) ) - partner = self.env["res.partner"].search( - [("id", "=", number.partner_id.id)] + partner = ( + self.sudo() + .env["res.partner"] + .search([("id", "=", number.partner_id.id)]) ) if not partner: if record.firstname or record.lastname or record.lastname2: @@ -774,8 +784,10 @@ class PmsCheckinPartner(models.Model): for checkin_dict in roomlist_json: identifier = checkin_dict["identifier"] reservation_id = checkin_dict["reservation_id"] - checkin = self.env["pms.checkin.partner"].search( - [("identifier", "=", identifier)] + checkin = ( + self.sudo() + .env["pms.checkin.partner"] + .search([("identifier", "=", identifier)]) ) reservation = self.env["pms.reservation"].browse(reservation_id) if not checkin: @@ -878,26 +890,25 @@ class PmsCheckinPartner(models.Model): if values.get("first"): values.pop("first") if values.get("nationality_id"): - nationality_id = self.env["res.country"].search( - [("id", "=", values.get("nationality_id"))] - ) - values.update({"nationality_id": nationality_id.id}) + values.update({"nationality_id": int(values.get("nationality_id"))}) else: values.update({"nationality_id": False}) if not values.get("document_type"): values.update({"document_type": False}) else: doc_type_name = values.get("document_type") - doc_type = self.env["res.partner.id_category"].search( - [("name", "=", doc_type_name)] + doc_type = ( + self.sudo() + .env["res.partner.id_category"] + .search([("name", "=", doc_type_name)]) ) - values.update({"document_type": doc_type}) - if values.get("state"): - residence_state_id = self.env["res.country.state"].search( - [("id", "=", values.get("state"))] + values.update({"document_type": doc_type.id}) + if values.get("residence_state_id"): + values.update({"residence_state_id": int(values.get("residence_state_id"))}) + if values.get("residence_country_id"): + values.update( + {"residence_country_id": int(values.get("residence_country_id"))} ) - values.update({"residence_state_id": residence_state_id}) - values.pop("state") if values.get("document_expedition_date"): doc_date = values.get("document_expedition_date") birthdate = values.get("birthdate_date") @@ -911,7 +922,6 @@ class PmsCheckinPartner(models.Model): "document_expedition_date": document_expedition_date, } ) - checkin_partner.sudo().write(values) def send_portal_invitation_email(self, invitation_firstname=None, email=None): diff --git a/pms/views/precheckin_portal_templates.xml b/pms/views/precheckin_portal_templates.xml index fa658aacb..2a639a4f4 100644 --- a/pms/views/precheckin_portal_templates.xml +++ b/pms/views/precheckin_portal_templates.xml @@ -76,7 +76,7 @@ @@ -84,11 +84,11 @@ Second Lastname + > Second Lastname (Optional) @@ -104,6 +104,7 @@ class="form-control" name="gender" t-att-value="checkin_partner_id.gender" + t-attf-class="form-control #{error.get('gender') and 'is-invalid' or ''}" > Select an option + + + - - @@ -180,6 +188,8 @@ /> + + Nationality @@ -241,13 +251,19 @@ + + + - + Mobile + >Mobile (Optional) - + Phone + >Phone (Optional) @@ -285,7 +301,7 @@ id="label_email" class="col-form-label" for="email" - >Email + >Email (Optional) - - Partner Relationship - - @@ -348,7 +351,7 @@ type="text" placeholder="Zip" name="residence_zip" - t-attf-class="form-control #{error.get('email') and 'is-invalid' or ''}" + t-attf-class="form-control #{error.get('address') and 'is-invalid' or ''}" t-att-value="checkin_partner_id.residence_zip" /> @@ -397,37 +400,21 @@ - - - - - - Prev - - - - - - Prev - - - - + + + + Page of - + @@ -438,36 +425,16 @@ class="d-none" t-att-value="checkin_pos" /> - + - Next + Save and Continue - - - - Save - - - - Data Saved Successfully - @@ -819,7 +786,6 @@ class="' btn btn-secondary" t-att-href="'whatsapp://send?text='+web_url+checkin_partner.get_portal_url()" style="color:#fff;margin-top:20px;" - t-attf-onclick="show_invitation(this)" > Send Whatsapp Invitation @@ -970,15 +936,7 @@ if(name){ host.innerHTML = name; - var divId = "invitation_group" + checkin_partner_id; - var btnId = "btnResendInvitation" + checkin_partner_id; - var div_invitation = document.getElementById(divId); - var btn_show_invitation_email = document.getElementById(btnId); - div_invitation.classList.add("d-none"); - btn_show_invitation_email.classList.remove("d-none"); - var x = document.getElementById("snackbar"); - x.className = "show"; - setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000); + } } } @@ -999,349 +957,13 @@ - - - - - Thank you, - . - Your check-in has been successful. - - - - You can check if all the data has been saved correctly - here - - - - - - - - - - Room: - - - - - - - - - - - - - - - - - - - - - - - - Name: - - - - - - - Lastname: - - - - - - - Second Lastname: - - - - - - - Gender: - - - - - - - Doc. Type: - - - - - - - Doc. Number: - - - - - - - Doc. Expedition Date: - - - - - - - Birthdate: - - - - - - - Mobile: - - - - - - - Phone: - - - - - - - Email: - - - - - - - Nationality: - - - - - - - Partner Relationship: - - - - - - - Residence Address - - - Street: - - - - - - - Second Street: - - - - - - - City: - - - - - - - ZIP: - - - - - - - State: - - - - - - - - - Country: - - - - - - - - - - - - - - - - - + + + Thank you! + Your check-in has been successful. + + + diff --git a/pms_l10n_es/views/precheckin_portal_templates.xml b/pms_l10n_es/views/precheckin_portal_templates.xml index 265b412d8..12ef7f2b0 100644 --- a/pms_l10n_es/views/precheckin_portal_templates.xml +++ b/pms_l10n_es/views/precheckin_portal_templates.xml @@ -4,7 +4,7 @@ inherit_id="pms.portal_my_precheckin_detail" > - + Doc. Type - + Doc. Number - - Doc. Support Number - - - - - - - - Doc. Support Number: - - - - -
- + Doc. Number - - Doc. Support Number - - - - - - - - Doc. Support Number: - - - - -