mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[RFC] pms_api_rest: change partner reservations from partner service to reservation service
This commit is contained in:
committed by
Darío Lodeiros
parent
14f8dd8059
commit
3a8e76d99e
@@ -136,43 +136,6 @@ class PmsPartnerService(Component):
|
||||
vals = self.mapping_partner_values(partner_info)
|
||||
self.env["res.partner"].create(vals)
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:partner_id>/hosted-reservations",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.reservation.short.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_partner_as_host(self, partner_id):
|
||||
checkins = self.env["pms.checkin.partner"].search(
|
||||
[("partner_id", "=", partner_id)]
|
||||
)
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
reservations = []
|
||||
if checkins:
|
||||
for checkin in checkins:
|
||||
reservation = self.env["pms.reservation"].search(
|
||||
[("id", "=", checkin.reservation_id.id)]
|
||||
)
|
||||
|
||||
reservations.append(
|
||||
PmsReservationShortInfo(
|
||||
id=reservation.id,
|
||||
checkin=reservation.checkin.strftime("%d/%m/%Y"),
|
||||
checkout=reservation.checkout.strftime("%d/%m/%Y"),
|
||||
adults=reservation.adults,
|
||||
priceTotal=round(reservation.price_room_services_set, 2),
|
||||
stateCode=reservation.state,
|
||||
paymentState=reservation.folio_payment_state,
|
||||
)
|
||||
)
|
||||
return reservations
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
@@ -190,43 +153,6 @@ class PmsPartnerService(Component):
|
||||
if partner:
|
||||
partner.write(self.mapping_partner_values(partner_info))
|
||||
|
||||
# REVIEW: analyze in which service file this method should be
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:partner_id>/customer-reservations",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.reservation.short.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_partner_as_customer(self, partner_id):
|
||||
partnerReservations = self.env["pms.reservation"].search(
|
||||
[("partner_id", "=", partner_id)]
|
||||
)
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
reservations = []
|
||||
for reservation in partnerReservations:
|
||||
reservations.append(
|
||||
PmsReservationShortInfo(
|
||||
checkin=datetime.combine(
|
||||
reservation.checkin, datetime.min.time()
|
||||
).isoformat(),
|
||||
checkout=datetime.combine(
|
||||
reservation.checkout, datetime.min.time()
|
||||
).isoformat(),
|
||||
adults=reservation.adults,
|
||||
priceTotal=round(reservation.price_room_services_set, 2),
|
||||
stateCode=reservation.state,
|
||||
paymentState=reservation.folio_payment_state,
|
||||
)
|
||||
)
|
||||
return reservations
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
|
||||
@@ -536,6 +536,76 @@ class PmsReservationService(Component):
|
||||
self.mapping_checkin_partner_values(pms_checkin_partner_info)
|
||||
)
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/partner-as-host",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.partner.search.param", is_list=False),
|
||||
output_param=Datamodel("pms.reservation.short.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_reservations_for_partners_as_host(self, pms_partner_search_param):
|
||||
checkins = self.env["pms.checkin.partner"].search(
|
||||
[("partner_id", "=", pms_partner_search_param.id)]
|
||||
)
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
reservations = []
|
||||
if checkins:
|
||||
for checkin in checkins:
|
||||
reservation = self.env["pms.reservation"].search(
|
||||
[("id", "=", checkin.reservation_id.id)]
|
||||
)
|
||||
|
||||
reservations.append(
|
||||
PmsReservationShortInfo(
|
||||
id=reservation.id,
|
||||
checkin=reservation.checkin.strftime("%d/%m/%Y"),
|
||||
checkout=reservation.checkout.strftime("%d/%m/%Y"),
|
||||
adults=reservation.adults,
|
||||
priceTotal=round(reservation.price_room_services_set, 2),
|
||||
stateCode=reservation.state,
|
||||
paymentState=reservation.folio_payment_state,
|
||||
)
|
||||
)
|
||||
return reservations
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/partner-as-customer",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.partner.search.param", is_list=False),
|
||||
output_param=Datamodel("pms.reservation.short.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_reservations_for_partner_as_customer(self, pms_partner_search_param):
|
||||
partnerReservations = self.env["pms.reservation"].search(
|
||||
[("partner_id", "=", pms_partner_search_param.id)]
|
||||
)
|
||||
PmsReservationShortInfo = self.env.datamodels["pms.reservation.short.info"]
|
||||
reservations = []
|
||||
for reservation in partnerReservations:
|
||||
reservations.append(
|
||||
PmsReservationShortInfo(
|
||||
checkin=reservation.checkin.strftime("%d/%m/%Y"),
|
||||
checkout=reservation.checkout.strftime("%d/%m/%Y"),
|
||||
adults=reservation.adults,
|
||||
priceTotal=round(reservation.price_room_services_set, 2),
|
||||
stateCode=reservation.state,
|
||||
paymentState=reservation.folio_payment_state,
|
||||
)
|
||||
)
|
||||
return reservations
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user