Skip to content

Commit

Permalink
[POC] Bookia endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Oct 11, 2024
1 parent e24210e commit f7e1cfb
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pms_api_rest/datamodels/pms_avail.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,20 @@ class PmsAvailInfo(Datamodel):
_name = "pms.avail.info"
date = fields.String(required=True, allow_none=False)
roomIds = fields.List(fields.Integer, required=False, allow_none=True)


class BookiaAvailSearchParam(Datamodel):
_name = "bookia.avail.search.param"
checkin = fields.String(required=True, allow_none=True)
checkout = fields.String(required=True, allow_none=True)
pmsPropertyId = fields.Integer(required=True, allow_none=True)
roomTypeId = fields.Integer(required=False, allow_none=True)
occupancy = fields.Integer(required=False, allow_none=True)


class BookiaAvailInfo(Datamodel):
_name = "bookia.avail.info"
roomTypeId = fields.Integer(required=True, allow_none=False)
roomTypeName = fields.String(required=True, allow_none=False)
avail = fields.Integer(required=True, allow_none=False)
price = fields.Float(required=True, allow_none=False)
88 changes: 88 additions & 0 deletions pms_api_rest/services/pms_avail_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,91 @@ def get_avails(self, avails_search_param):
)
)
return result_avails

@restapi.method(
[
(
[
"/bookia",
],
"GET",
)
],
input_param=Datamodel("bookia.avail.search.param"),
output_param=Datamodel("bookia.avail.info", is_list=True),
auth="jwt_api_pms",
)
def get_bookia_avails(self, bookia_avail_search):
if not (
bookia_avail_search.checkin
and bookia_avail_search.checkout
and bookia_avail_search.pmsPropertyId
and bookia_avail_search.occupancy
):
raise MissingError(
_(
"""Missing required parameters:
availabilityFrom, availabilityTo, pmsPropertyId"""
)
)
pms_property = self.env["pms.property"].browse(
bookia_avail_search.pmsPropertyId
)
checkin = fields.Date.from_string(bookia_avail_search.checkin)
checkout = fields.Date.from_string(bookia_avail_search.checkout)
pricelist = pms_property.default_pricelist_id
PmsAvailInfo = self.env.datamodels["bookia.avail.info"]
rooms = self.env["pms.room"].search(
[
("pms_property_id", "=", pms_property.id),
("capacity", ">=", bookia_avail_search.occupancy),
]
)
room_types = rooms.mapped("room_type_id").filtered(lambda x: x.overnight_room)
bookia_avails = []
for room_type in room_types:
pms_property = pms_property.with_context(
checkin=checkin,
checkout=checkout,
room_type_id=room_type.id,
pricelist_id=pricelist.id,
)
avail = pms_property.availability
if not avail:
continue
product_context = dict(
self.env.context,
date=datetime.today().date(),
pricelist=pricelist.id,
uom=room_type.product_id.uom_id.id,
fiscal_position=False,
property=pms_property.id,
)
total_price = 0
dates = [
checkin + timedelta(days=x) for x in range(0, (checkout - checkin).days)
]
for date in dates:
product_context["consumption_date"] = date
product = room_type.product_id.with_context(product_context)
total_price += self.env["account.tax"]._fix_tax_included_price_company(
self.env["product.product"]._pms_get_display_price(
pricelist_id=pricelist.id,
product=product,
company_id=pms_property.company_id.id,
product_qty=1,
partner_id=False,
),
room_type.product_id.taxes_id,
room_type.product_id.taxes_id,
pms_property.company_id,
)
bookia_avails.append(
PmsAvailInfo(
roomTypeId=room_type.id,
roomTypeName=room_type.name,
avail=avail,
price=round(total_price, 2),
)
)
return bookia_avails

0 comments on commit f7e1cfb

Please sign in to comment.