Skip to content

Commit

Permalink
[ADD] pms-pwa: add calendar service
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Sep 22, 2021
1 parent 79f613b commit eb1582a
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 11 deletions.
6 changes: 5 additions & 1 deletion pms_api_rest/datamodels/__init__.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions pms_api_rest/datamodels/pms_calendar_search_param.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions pms_api_rest/datamodels/pms_calendar_short_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from marshmallow import fields

from odoo.addons.datamodel.core import Datamodel


class PmsCalendarShortInfo(Datamodel):
_name = "pms.calendar.short.info"
date = fields.String(required=False, allow_none=True)
roomId = fields.Integer(required=False, allow_none=True)
partnerId = fields.Integer(required=False, allow_none=True)
5 changes: 2 additions & 3 deletions pms_api_rest/datamodels/pms_room_search_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions pms_api_rest/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import folio_services
from . import room_services
from . import calendar_service
49 changes: 49 additions & 0 deletions pms_api_rest/services/calendar_service.py
Original file line number Diff line number Diff line change
@@ -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 = []
if calendar_search_param.date_from:
domain.append(("date", ">=", datetime.fromisoformat(calendar_search_param.date_from)))
if calendar_search_param.date_to:
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(
roomId=line.room_id.id,
date=datetime.combine(line.date, datetime.min.time()).isoformat(),
partnerId=line.reservation_id.partner_id.id,
)
)
return result_lines
6 changes: 4 additions & 2 deletions pms_api_rest/services/folio_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 3 additions & 5 deletions pms_api_rest/services/room_services.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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):
Expand Down

0 comments on commit eb1582a

Please sign in to comment.