diff --git a/pms_civitfun/datamodels/pms_reservation.py b/pms_civitfun/datamodels/pms_reservation.py index 74c4a826c8..47ffddad82 100644 --- a/pms_civitfun/datamodels/pms_reservation.py +++ b/pms_civitfun/datamodels/pms_reservation.py @@ -30,6 +30,7 @@ class CivitfunReservationInfo(Datamodel): departureTime = fields.String(required=False, allow_none=True) adults = fields.Integer(required=False, allow_none=True) babies = fields.Integer(required=False, allow_none=True) + children = fields.Integer(required=False, allow_none=True) regimeStay = fields.String(required=False, allow_none=True) agency = fields.String(required=False, allow_none=True) stayAmount = fields.Float(required=False, allow_none=True) @@ -37,7 +38,7 @@ class CivitfunReservationInfo(Datamodel): customerNotes = fields.String(required=False, allow_none=True) roomTypes = fields.List(fields.Dict(required=False, allow_none=True)) reallocationPropertyId = fields.String(required=False, allow_none=True) - addionalInfo = fields.List(fields.Dict(required=False, allow_none=True)) + additionalInfo = fields.List(fields.Dict(required=False, allow_none=True)) guestsFilled = fields.Boolean(required=False, allow_none=True) guests = fields.List(NestedModel("civitfun.checkin.partner.info")) diff --git a/pms_civitfun/http.py b/pms_civitfun/http.py index 052489c880..dfec865856 100644 --- a/pms_civitfun/http.py +++ b/pms_civitfun/http.py @@ -82,6 +82,23 @@ def get_request(self, httprequest): rest_routes = _rest_services_routes.get(db, []) for root_path in rest_routes: if httprequest.path.startswith(root_path): + if "civitfun" in httprequest.path: + if ( + "Civitfun-Standard3-Request" in httprequest.environ + and httprequest.environ.get("Civitfun-Standard3-Request") + == "authorization" + ): + httprequest.environ["HTTP_AUTHORIZATION"] = httprequest.environ[ + "Civitfun-Standard3-Request" + ] + if ( + "CONTENT_TYPE" in httprequest.environ + and httprequest.environ.get("CONTENT_TYPE") + == "application/json" + ): + httprequest.environ[ + "CONTENT_TYPE" + ] = "application/json-civitfun" return HttpRestRequestCivitfun(httprequest) return ori_get_request(self, httprequest) diff --git a/pms_civitfun/services/pms_checkin_partner_service.py b/pms_civitfun/services/pms_checkin_partner_service.py index c7701e6e8e..8424d007b9 100644 --- a/pms_civitfun/services/pms_checkin_partner_service.py +++ b/pms_civitfun/services/pms_checkin_partner_service.py @@ -1,3 +1,5 @@ +import logging + from odoo import _, fields from odoo.exceptions import MissingError, ValidationError @@ -5,6 +7,8 @@ from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component +_logger = logging.getLogger(__name__) + FORMAT_DATE = "%Y-%m-%d" @@ -36,16 +40,22 @@ def register_hosts(self, pms_input_param): pms_property = ( self.env["pms.property"] .sudo() - .search([("civitfun_property_code", "=", pms_input_param.propertyId)]) + .search( + [ + ("civitfun_property_code", "=", pms_input_param.propertyId), + ("use_civitfun", "=", True), + ] + ) ) if not pms_property: raise MissingError(_("Property not found")) + booking_identifier = pms_input_param.bookingIdentifier.replace("-", "/") reservation = ( self.env["pms.reservation"] .sudo() .search( [ - ("name", "=", pms_input_param.bookingIdentifier), + ("name", "=", booking_identifier), ("pms_property_id", "=", pms_property.id), ] ) @@ -119,42 +129,54 @@ def _mapped_hosts_info(self, guest): "document_type": self._get_mapped_document_type(guest.documentType), "document_number": guest.documentNumber, "document_expedition_date": guest.expeditionDate.strftime(FORMAT_DATE), - # "expiration_date": guest.expirationDate.strftime(FORMAT_DATE), # "assigned_room": guest.assignedRoom, # "legal_fields": guest.legalFields, # "files": guest.files, } - zip_code = False + if guest.customFields.get("phone"): + checkin_vals["phone"] = guest.customFields.get("phone") + if guest.customFields.get("address"): + checkin_vals["residence_street"] = guest.customFields.get("address") + res_zip = False if guest.customFields.get("postalCode"): - zip_code = self.env["res.city.zip"].search( + zip_code = guest.customFields.get("postalCode") + res_zip = self.env["res.city.zip"].search( [ - ("name", "=", guest.customFields.get("postalCode")), + ("name", "=", zip_code), ] ) - if zip_code: - checkin_vals["residence_zip"] = zip_code.name - checkin_vals["residence_city"] = zip_code.city_id.name - checkin_vals["residence_state_id"] = zip_code.city_id.state_id.id - checkin_vals[ - "residence_country_id" - ] = zip_code.city_id.state_id.country_id.id - if not zip_code: - checkin_vals["residence_zip"] = guest.customFields.get("postalCode") - checkin_vals["residence_city"] = guest.customFields.get("city") - checkin_vals["residence_state_id"] = guest.customFields.get("state") - checkin_vals["residence_country_id"] = self.env["res.country"].search( - [ - ("code_alpha3", "=", guest.customFields.get("country")), - ] - ) - if guest.customFields.get("address"): - checkin_vals["residence_street"] = guest.customFields.get("address") + if res_zip: + checkin_vals["residence_zip"] = res_zip.name + checkin_vals["residence_city"] = res_zip.city_id.name + checkin_vals["residence_state_id"] = res_zip.state_id.id + checkin_vals["residence_country_id"] = res_zip.country_id.id + else: + if guest.customFields.get("city"): + checkin_vals["residence_city"] = guest.customFields.get("city") + if guest.customFields.get("province"): + checkin_vals["residence_state_id"] = ( + self.env["res.country.state"] + .search( + [ + ("code", "=", guest.customFields.get("province")), + ] + ) + .id + ) + if guest.customFields.get("country"): + checkin_vals["residence_country_id"] = ( + self.env["res.country"] + .search( + [ + ("code_alpha3", "=", guest.customFields.get("country")), + ] + ) + .id + ) partner_vals = { "lang": self._get_mapped_lang(guest.lang), } - if guest.customFields.get("phone"): - partner_vals["phone"] = guest.customFields.get("phone") return checkin_vals, partner_vals diff --git a/pms_civitfun/services/pms_reservation_service.py b/pms_civitfun/services/pms_reservation_service.py index 4227716040..023f9def54 100644 --- a/pms_civitfun/services/pms_reservation_service.py +++ b/pms_civitfun/services/pms_reservation_service.py @@ -1,3 +1,4 @@ +import logging from datetime import datetime from odoo import _ @@ -7,6 +8,8 @@ from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component +_logger = logging.getLogger(__name__) + FORMAT_DATE = "%Y-%m-%d" @@ -45,11 +48,22 @@ def get_reservations(self, pms_search_param): domain = [ ("pms_property_id", "=", pms_property.id), ("state", "in", ["draft", "confirm", "done"]), + ("reservation_type", "!=", "out"), ] if pms_search_param.bookingIdentifier: - domain.append(("name", "=", pms_search_param.bookingIdentifier)) + booking_identifier = pms_search_param.bookingIdentifier.replace( + "-", "/" + ) + domain.append(("name", "=", booking_identifier)) if pms_search_param.bookingCode: - domain.append(("external_reference", "=", pms_search_param.bookingCode)) + booking_code = pms_search_param.bookingCode.replace("-", "/") + domain.extend( + [ + "|", + ("external_reference", "=", booking_code), + ("name", "=", booking_code), + ] + ) if pms_search_param.entranceDate: domain.append( ( @@ -106,9 +120,9 @@ def _mapped_reservation_info(self, reservation): """ room = reservation.reservation_line_ids[0].room_id return self.env.datamodels["civitfun.reservation.info"]( - bookingIdentifier=reservation.name, + bookingIdentifier=reservation.name.replace("/", "-"), bookingCode=reservation.folio_id.external_reference or None, - status=reservation.state, + status=self._get_mapped_state(reservation.state), holder=reservation.partner_name, # TODO: transform to civitfun format holderCountry=reservation.partner_id.country_id.code_alpha3 if reservation.partner_id.country_id @@ -119,7 +133,8 @@ def _mapped_reservation_info(self, reservation): departure=reservation.checkout.strftime(FORMAT_DATE), departureTime=reservation.departure_hour, adults=reservation.adults, - babies=reservation.children, + babies=0, + children=reservation.children, regimeStay=reservation.board_service_room_id.pms_board_service_id.name or None, agency=reservation.agency_id.name or None, @@ -128,10 +143,10 @@ def _mapped_reservation_info(self, reservation): customerNotes=reservation.partner_requests or None, roomTypes=[ { - "id": reservation.room_type_id.id, + "id": str(reservation.room_type_id.id), "name": reservation.room_type_id.name, "assignedRoom": { - "id": room.id, + "id": str(room.id), "name": room.name, }, "capacity": room.capacity, @@ -143,10 +158,63 @@ def _mapped_reservation_info(self, reservation): } ], reallocationPropertyId=None, - addionalInfo=[], + additionalInfo=[], guestsFilled=False, guests=self._mapped_guests(reservation), ) def _mapped_guests(self, reservation): - return [] + guests = [] + PmsCheckinPartner = self.env.datamodels["civitfun.checkin.partner.info"] + for checkin in reservation.checkin_partner_ids: + guests.append( + PmsCheckinPartner( + id=str(checkin.id), + position=reservation.checkin_partner_ids.ids.index(checkin.id) + 1, + email=checkin.email or None, + lang=checkin.partner_id.lang or None, + name=checkin.firstname or None, + surname=checkin.lastname or None, + secondSurname=checkin.lastname2 or None, + gender=self._get_mapped_gender(checkin.gender) + if checkin.gender + else None, + birthDate=checkin.birthdate_date.strftime(FORMAT_DATE) + if checkin.birthdate_date + else None, + nationality=checkin.nationality_id.code_alpha3 or None, + documentType=checkin.document_type.civitfun_category or None, + documentNumber=checkin.document_number or None, + expeditionDate=checkin.document_expedition_date.strftime( + FORMAT_DATE + ) + if checkin.document_expedition_date + else None, + ) + ) + return guests + + def _get_mapped_gender(self, gender): + if gender == "male": + return "M" + if gender == "female": + return "F" + return "U" + + def _get_mapped_state(self, state): + """ + Booking status + ○ cancel -> canceled + ○ / -> noShow + ○ draft, confirm, arrival_delayed -> confirmed + ○ onboard -> checkedIn + ○ done, departure_delayed -> checkedOut + """ + if state == "cancel": + return "canceled" + if state == "draft" or state == "confirm" or state == "arrival_delayed": + return "confirmed" + if state == "onboard": + return "checkedIn" + if state == "done" or state == "departure_delayed": + return "checkedOut"