diff --git a/pms_api_rest/datamodels/__init__.py b/pms_api_rest/datamodels/__init__.py index 0b73cc61666..c74370760b1 100644 --- a/pms_api_rest/datamodels/__init__.py +++ b/pms_api_rest/datamodels/__init__.py @@ -1,4 +1,8 @@ -from . import pms_folio_short_info +from . import pms_calendar_search_param +from . import pms_calendar_short_info + from . import pms_folio_search_param +from . import pms_folio_short_info + from . import pms_room_short_info from . import pms_room_search_param diff --git a/pms_api_rest/datamodels/pms_calendar_search_param.py b/pms_api_rest/datamodels/pms_calendar_search_param.py new file mode 100644 index 00000000000..1414c55ecc8 --- /dev/null +++ b/pms_api_rest/datamodels/pms_calendar_search_param.py @@ -0,0 +1,9 @@ +from marshmallow import fields + +from odoo.addons.datamodel.core import Datamodel + + +class PmsCalendarSearchParam(Datamodel): + _name = "pms.calendar.search.param" + date_from = fields.String(required=False, allow_none=True) + date_to = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_calendar_short_info.py b/pms_api_rest/datamodels/pms_calendar_short_info.py new file mode 100644 index 00000000000..54e019a5984 --- /dev/null +++ b/pms_api_rest/datamodels/pms_calendar_short_info.py @@ -0,0 +1,12 @@ +from marshmallow import fields + +from odoo.addons.datamodel.core import Datamodel + + +class PmsCalendarShortInfo(Datamodel): + _name = "pms.calendar.short.info" + id = fields.Integer(required=False, allow_none=True) + date = fields.String(required=False, allow_none=True) + roomId = fields.Integer(required=False, allow_none=True) + partnerId = fields.Integer(required=False, allow_none=True) + reservationId = fields.Integer(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_room_search_param.py b/pms_api_rest/datamodels/pms_room_search_param.py index 8945237e230..3ef72c8ae74 100644 --- a/pms_api_rest/datamodels/pms_room_search_param.py +++ b/pms_api_rest/datamodels/pms_room_search_param.py @@ -5,6 +5,5 @@ class PmsRoomSearchParam(Datamodel): _name = "pms.room.search.param" - - id = fields.Integer(required=False, allow_none=False) - name = fields.String(required=False, allow_none=False) + id = fields.Integer(required=False, allow_none=True) + name = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/services/__init__.py b/pms_api_rest/services/__init__.py index 6329f4b991f..67cfea7a84f 100644 --- a/pms_api_rest/services/__init__.py +++ b/pms_api_rest/services/__init__.py @@ -1,2 +1,3 @@ from . import folio_services from . import room_services +from . import calendar_service diff --git a/pms_api_rest/services/calendar_service.py b/pms_api_rest/services/calendar_service.py new file mode 100644 index 00000000000..096d34f7045 --- /dev/null +++ b/pms_api_rest/services/calendar_service.py @@ -0,0 +1,49 @@ +from datetime import datetime + +from odoo.addons.base_rest import restapi +from odoo.addons.base_rest_datamodel.restapi import Datamodel +from odoo.addons.component.core import Component + + +class PmsCalendarService(Component): + _inherit = "base.rest.service" + _name = "pms.calendar.service" + _usage = "calendar" + _collection = "pms.reservation.service" + + @restapi.method( + [ + ( + [ + "/", + ], + "GET", + ) + ], + input_param=Datamodel("pms.calendar.search.param"), + output_param=Datamodel("pms.calendar.short.info", is_list=True), + auth="public", + ) + 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))) + result_lines = [] + PmsCalendarShortInfo = self.env.datamodels["pms.calendar.short.info"] + for line in ( + self.env["pms.reservation.line"] + .sudo() + .search( + domain, + ) + ): + result_lines.append( + PmsCalendarShortInfo( + id=line.id, + roomId=line.room_id.id, + date=datetime.combine(line.date, datetime.min.time()).isoformat(), + partnerId=line.reservation_id.partner_id.id, + reservationId=line.reservation_id, + ) + ) + return result_lines diff --git a/pms_api_rest/services/folio_services.py b/pms_api_rest/services/folio_services.py index a78c13a1f3e..4c6601b3bdc 100644 --- a/pms_api_rest/services/folio_services.py +++ b/pms_api_rest/services/folio_services.py @@ -72,7 +72,9 @@ def get_folios(self, folio_search_param): "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 + "reservationLines": [] + if not reservation_lines + else reservation_lines, } ) result_folios.append( @@ -105,7 +107,7 @@ def get_folios(self, folio_search_param): "GET", ) ], - output_param=Datamodel("pms.reservation.short.info", is_list=True), + output_param=Datamodel("pms.folio.short.info", is_list=True), auth="public", ) def get_reservations(self, folio_id): diff --git a/pms_api_rest/services/room_services.py b/pms_api_rest/services/room_services.py index 787d9d85150..c4a184f421a 100644 --- a/pms_api_rest/services/room_services.py +++ b/pms_api_rest/services/room_services.py @@ -1,11 +1,9 @@ -from datetime import datetime - from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component -class PmsFolioService(Component): +class PmsRoomService(Component): _inherit = "base.rest.service" _name = "pms.room.service" _usage = "rooms" @@ -20,8 +18,8 @@ class PmsFolioService(Component): "GET", ) ], - input_param=Datamodel("pms.folio.search.param"), - output_param=Datamodel("pms.folio.short.info", is_list=True), + input_param=Datamodel("pms.room.search.param"), + output_param=Datamodel("pms.room.short.info", is_list=True), auth="public", ) def get_rooms(self, room_search_param):