Skip to content

Commit

Permalink
[IMP]pms_civitfun: custom header and fields
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Apr 18, 2023
1 parent 66bf71b commit ef27377
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 36 deletions.
3 changes: 2 additions & 1 deletion pms_civitfun/datamodels/pms_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ 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)
depositAmount = fields.Float(required=False, allow_none=True)
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"))

Expand Down
17 changes: 17 additions & 0 deletions pms_civitfun/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
74 changes: 48 additions & 26 deletions pms_civitfun/services/pms_checkin_partner_service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import logging

from odoo import _, fields
from odoo.exceptions import MissingError, ValidationError

from odoo.addons.base_rest import restapi
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"


Expand Down Expand Up @@ -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),
]
)
Expand Down Expand Up @@ -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

Expand Down
86 changes: 77 additions & 9 deletions pms_civitfun/services/pms_reservation_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from datetime import datetime

from odoo import _
Expand All @@ -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"


Expand Down Expand Up @@ -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(
(
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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"

0 comments on commit ef27377

Please sign in to comment.