diff --git a/pms_api_rest/__manifest__.py b/pms_api_rest/__manifest__.py index bf4ba876f32..582fb9f23bc 100644 --- a/pms_api_rest/__manifest__.py +++ b/pms_api_rest/__manifest__.py @@ -15,5 +15,8 @@ "external_dependencies": { "python": ["jwt", "simplejson", "marshmallow"], }, + "data": [ + "security/ir.model.access.csv", + ], "installable": True, } diff --git a/pms_api_rest/datamodels/__init__.py b/pms_api_rest/datamodels/__init__.py index 393c4780449..71fd56e93fd 100644 --- a/pms_api_rest/datamodels/__init__.py +++ b/pms_api_rest/datamodels/__init__.py @@ -7,6 +7,6 @@ from . import pms_room_short_info from . import pms_room_search_param -from . import pms_partner_short_info from . import pms_reservation_short_info +from . import pms_checkin_partner_short_info diff --git a/pms_api_rest/datamodels/pms_checkin_partner_short_info.py b/pms_api_rest/datamodels/pms_checkin_partner_short_info.py new file mode 100644 index 00000000000..5afccd3c7c1 --- /dev/null +++ b/pms_api_rest/datamodels/pms_checkin_partner_short_info.py @@ -0,0 +1,18 @@ +from marshmallow import fields + +from odoo.addons.datamodel.core import Datamodel + + +class PmsCheckinPartnerShortInfo(Datamodel): + _name = "pms.checkin.partner.short.info" + id = fields.Integer(required=False, allow_none=True) + # partner = fields.String(required=False, allow_none=True) + reservationId = fields.Integer(required=False, allow_none=True) + name = fields.String(required=False, allow_none=True) + email = fields.String(required=False, allow_none=True) + mobile = fields.String(required=False, allow_none=True) + nationality = fields.String(required=False, allow_none=True) + documentType = fields.String(required=False, allow_none=True) + documentNumber = fields.String(required=False, allow_none=True) + gender = fields.String(required=False, allow_none=True) + state = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_reservation_short_info.py b/pms_api_rest/datamodels/pms_reservation_short_info.py index 2fa4a3b2209..ae6613f1a7e 100644 --- a/pms_api_rest/datamodels/pms_reservation_short_info.py +++ b/pms_api_rest/datamodels/pms_reservation_short_info.py @@ -6,6 +6,15 @@ class PmsReservationShortInfo(Datamodel): _name = "pms.reservation.short.info" id = fields.Integer(required=False, allow_none=True) - price = fields.Float(required=False, allow_none=True) + partner = fields.String(required=False, allow_none=True) + name = fields.String(required=False, allow_none=True) checkin = fields.String(required=False, allow_none=True) checkout = fields.String(required=False, allow_none=True) + roomTypeId = fields.String(required=False, allow_none=True) + preferredRoomId = fields.String(required=False, allow_none=True) + priceTotal = fields.Float(required=False, allow_none=True) + priceOnlyServices = fields.Float(required=False, allow_none=True) + priceOnlyRoom = fields.Float(required=False, allow_none=True) + pricelist = fields.String(required=False, allow_none=True) + services = fields.List(fields.Dict(required=False, allow_none=True)) + messages = fields.List(fields.Dict(required=False, allow_none=True)) diff --git a/pms_api_rest/services/calendar_service.py b/pms_api_rest/services/calendar_service.py index 096d34f7045..357d9ce6085 100644 --- a/pms_api_rest/services/calendar_service.py +++ b/pms_api_rest/services/calendar_service.py @@ -26,8 +26,12 @@ class PmsCalendarService(Component): ) def get_calendar(self, calendar_search_param): domain = list() - domain.append(("date", ">=", datetime.fromisoformat(calendar_search_param.date_from))) - domain.append(("date", "<=", datetime.fromisoformat(calendar_search_param.date_to))) + domain.append( + ("date", ">", datetime.fromisoformat(calendar_search_param.date_from)) + ) + domain.append( + ("date", "<=", datetime.fromisoformat(calendar_search_param.date_to)) + ) result_lines = [] PmsCalendarShortInfo = self.env.datamodels["pms.calendar.short.info"] for line in ( diff --git a/pms_api_rest/services/folio_services.py b/pms_api_rest/services/folio_services.py index 4c6601b3bdc..ba307e434f4 100644 --- a/pms_api_rest/services/folio_services.py +++ b/pms_api_rest/services/folio_services.py @@ -69,12 +69,17 @@ def get_folios(self, folio_search_param): "priceTotal": reservation.price_total, "adults": reservation.adults, "pricelist": reservation.pricelist_id.name, - "boardService": reservation.board_service_room_id.pms_board_service_id.name + "boardService": ( + reservation.board_service_room_id.pms_board_service_id.name + ) if reservation.board_service_room_id else "", "reservationLines": [] if not reservation_lines else reservation_lines, + "folioId": reservation.folio_id.id + if reservation.folio_id + else "", } ) result_folios.append( @@ -102,55 +107,119 @@ def get_folios(self, folio_search_param): [ ( [ - "//reservations", + "//reservations/", ], "GET", ) ], - output_param=Datamodel("pms.folio.short.info", is_list=True), + output_param=Datamodel("pms.reservation.short.info"), auth="public", ) - def get_reservations(self, folio_id): - folio = self.env["pms.folio"].sudo().search([("id", "=", folio_id)]) + def get_reservation(self, folio_id, reservation_id): + reservation = ( + self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)]) + ) res = [] - if not folio.reservation_ids: + PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"] + if not reservation: pass else: - PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"] + services = [] + for service in reservation.service_ids: + if service.is_board_service: + services.append( + { + "id": service.id, + "name": service.name, + "quantity": service.product_qty, + "priceTotal": service.price_total, + "priceSubtotal": service.price_subtotal, + "priceTaxes": service.price_tax, + "discount": service.discount, + } + ) + messages = [] + import re - for reservation in folio.reservation_ids: - res.append( - PmsReservationShortInfo( - id=reservation.id, - partner=reservation.partner_id.name, - checkin=str(reservation.checkin), - checkout=str(reservation.checkout), - preferredRoomId=reservation.preferred_room_id.name - if reservation.preferred_room_id + text = re.compile("<.*?>") + for message in reservation.message_ids.sorted(key=lambda x: x.date): + messages.append( + { + "author": message.author_id.name, + "date": str(message.date), + # print(self.env["ir.fields.converter"].text_from_html(message.body)) + "body": re.sub(text, "", message.body), + } + ) + res = PmsReservationShortInfo( + id=reservation.id, + partner=reservation.partner_id.name, + checkin=str(reservation.checkin), + checkout=str(reservation.checkout), + preferredRoomId=reservation.preferred_room_id.name + if reservation.preferred_room_id + else "", + roomTypeId=reservation.room_type_id.name + if reservation.room_type_id + else "", + name=reservation.name, + priceTotal=reservation.price_room_services_set, + priceOnlyServices=reservation.price_services + if reservation.price_services + else 0.0, + priceOnlyRoom=reservation.price_total, + pricelist=reservation.pricelist_id.name + if reservation.pricelist_id + else "", + services=services if services else [], + messages=messages, + ) + return res + + @restapi.method( + [ + ( + [ + "//reservations//checkinpartners", + ], + "GET", + ) + ], + output_param=Datamodel("pms.checkin.partner.short.info", is_list=True), + auth="public", + ) + def get_checkin_partners(self, folio_id, reservation_id): + reservation = ( + self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)]) + ) + checkin_partners = [] + PmsCheckinPartnerShortInfo = self.env.datamodels[ + "pms.checkin.partner.short.info" + ] + if not reservation: + pass + else: + for checkin_partner in reservation.checkin_partner_ids: + checkin_partners.append( + PmsCheckinPartnerShortInfo( + id=checkin_partner.id, + reservationId=checkin_partner.reservation_id.id, + name=checkin_partner.name if checkin_partner.name else "", + email=checkin_partner.email if checkin_partner.email else "", + mobile=checkin_partner.mobile if checkin_partner.mobile else "", + nationality=checkin_partner.nationality_id.name + if checkin_partner.nationality_id else "", - roomTypeId=reservation.room_type_id.name - if reservation.room_type_id + documentType=checkin_partner.document_type.name + if checkin_partner.document_type else "", - name=reservation.name, - partnerRequests=reservation.partner_requests - if reservation.partner_requests + documentNumber=checkin_partner.document_number + if checkin_partner.document_number else "", + gender=checkin_partner.gender if checkin_partner.gender else "", state=dict( - reservation.fields_get(["state"])["state"]["selection"] - )[reservation.state], - priceTotal=reservation.price_total, - adults=reservation.adults, - channelTypeId=reservation.channel_type_id.name - if reservation.channel_type_id - else "", - agencyId=reservation.agency_id.name - if reservation.agency_id - else "", - boardServiceId=reservation.board_service_room_id.pms_board_service_id.name - if reservation.board_service_room_id - else "", - checkinsRatio=reservation.checkins_ratio, - outstanding=reservation.folio_id.pending_amount, + checkin_partner.fields_get(["state"])["state"]["selection"] + )[checkin_partner.state], ) ) - return res + return checkin_partners