mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add cancelation rule and sale channel services
This commit is contained in:
@@ -39,3 +39,5 @@ from . import pms_board_service
|
|||||||
from . import pms_board_service_line
|
from . import pms_board_service_line
|
||||||
|
|
||||||
from . import pms_product
|
from . import pms_product
|
||||||
|
from . import pms_sale_channel
|
||||||
|
from . import pms_cancelation_rule
|
||||||
|
|||||||
14
pms_api_rest/datamodels/pms_cancelation_rule.py
Normal file
14
pms_api_rest/datamodels/pms_cancelation_rule.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class PmsCancelationRuleSearchParam(Datamodel):
|
||||||
|
_name = "pms.cancelation.rule.search.param"
|
||||||
|
pricelistId = fields.Integer(required=False, allow_none=True)
|
||||||
|
pmsPropertyId = fields.String(required=False, allow_none=True)
|
||||||
|
|
||||||
|
class PmsCancelationRuleInfo(Datamodel):
|
||||||
|
_name = "pms.cancelation.rule.info"
|
||||||
|
id = fields.Integer(required=True, allow_none=False)
|
||||||
|
name = fields.String(required=True, allow_none=False)
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
from sre_parse import State
|
|
||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
|
|
||||||
from odoo.addons.datamodel.core import Datamodel
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
@@ -48,5 +47,5 @@ class PmsReservationInfo(Datamodel):
|
|||||||
pendingAmount = fields.Float(required=False, allow_none=True)
|
pendingAmount = fields.Float(required=False, allow_none=True)
|
||||||
|
|
||||||
# TODO: Refact
|
# TODO: Refact
|
||||||
#services = fields.List(fields.Dict(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))
|
# messages = fields.List(fields.Dict(required=False, allow_none=True))
|
||||||
|
|||||||
15
pms_api_rest/datamodels/pms_sale_channel.py
Normal file
15
pms_api_rest/datamodels/pms_sale_channel.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class PmsSaleChannelSearchParam(Datamodel):
|
||||||
|
_name = "pms.sale.channel.search.param"
|
||||||
|
id = fields.Integer(required=False, allow_none=True)
|
||||||
|
pmsPropertyIds = fields.List(fields.Integer(), required=False)
|
||||||
|
|
||||||
|
|
||||||
|
class PmsSaleChannelInfo(Datamodel):
|
||||||
|
_name = "pms.sale.channel.info"
|
||||||
|
id = fields.Integer(required=True, allow_none=False)
|
||||||
|
name = fields.String(required=True, allow_none=False)
|
||||||
@@ -25,3 +25,5 @@ from . import pms_board_service_line_service
|
|||||||
from . import pms_board_service_service
|
from . import pms_board_service_service
|
||||||
|
|
||||||
from . import pms_product_service
|
from . import pms_product_service
|
||||||
|
from . import pms_sale_channel_service
|
||||||
|
from . import pms_cancelation_rule_service
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class PmsBoardServiceService(Component):
|
|||||||
amount=board_service.amount,
|
amount=board_service.amount,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise MissingError(_("Amenity Type not found"))
|
raise MissingError(_("Board Service not found"))
|
||||||
|
|
||||||
@restapi.method(
|
@restapi.method(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -162,9 +162,7 @@ class PmsCalendarService(Component):
|
|||||||
date_from = datetime.strptime(
|
date_from = datetime.strptime(
|
||||||
pms_calendar_search_param.dateFrom, "%Y-%m-%d"
|
pms_calendar_search_param.dateFrom, "%Y-%m-%d"
|
||||||
).date()
|
).date()
|
||||||
date_to = datetime.strptime(
|
date_to = datetime.strptime(pms_calendar_search_param.dateTo, "%Y-%m-%d").date()
|
||||||
pms_calendar_search_param.dateTo, "%Y-%m-%d"
|
|
||||||
).date()
|
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
PmsCalendarDailyInvoicing = self.env.datamodels["pms.calendar.daily.invoicing"]
|
PmsCalendarDailyInvoicing = self.env.datamodels["pms.calendar.daily.invoicing"]
|
||||||
@@ -203,9 +201,7 @@ class PmsCalendarService(Component):
|
|||||||
date_from = datetime.strptime(
|
date_from = datetime.strptime(
|
||||||
pms_calendar_search_param.dateFrom, "%Y-%m-%d"
|
pms_calendar_search_param.dateFrom, "%Y-%m-%d"
|
||||||
).date()
|
).date()
|
||||||
date_to = datetime.strptime(
|
date_to = datetime.strptime(pms_calendar_search_param.dateTo, "%Y-%m-%d").date()
|
||||||
pms_calendar_search_param.dateTo, "%Y-%m-%d"
|
|
||||||
).date()
|
|
||||||
result = []
|
result = []
|
||||||
PmsCalendarFreeDailyRoomsByType = self.env.datamodels[
|
PmsCalendarFreeDailyRoomsByType = self.env.datamodels[
|
||||||
"pms.calendar.free.daily.rooms.by.type"
|
"pms.calendar.free.daily.rooms.by.type"
|
||||||
@@ -276,9 +272,7 @@ class PmsCalendarService(Component):
|
|||||||
date_from = datetime.strptime(
|
date_from = datetime.strptime(
|
||||||
pms_calendar_search_param.dateFrom, "%Y-%m-%d"
|
pms_calendar_search_param.dateFrom, "%Y-%m-%d"
|
||||||
).date()
|
).date()
|
||||||
date_to = datetime.strptime(
|
date_to = datetime.strptime(pms_calendar_search_param.dateTo, "%Y-%m-%d").date()
|
||||||
pms_calendar_search_param.dateTo, "%Y-%m-%d"
|
|
||||||
).date()
|
|
||||||
result = []
|
result = []
|
||||||
for day in (
|
for day in (
|
||||||
date_from + timedelta(d) for d in range((date_to - date_from).days + 1)
|
date_from + timedelta(d) for d in range((date_to - date_from).days + 1)
|
||||||
|
|||||||
73
pms_api_rest/services/pms_cancelation_rule_service.py
Normal file
73
pms_api_rest/services/pms_cancelation_rule_service.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
from odoo import _
|
||||||
|
from odoo.exceptions import MissingError
|
||||||
|
|
||||||
|
from odoo.addons.base_rest import restapi
|
||||||
|
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||||
|
from odoo.addons.component.core import Component
|
||||||
|
|
||||||
|
|
||||||
|
class PmsCancelationRuleService(Component):
|
||||||
|
_inherit = "base.rest.service"
|
||||||
|
_name = "pms.cancelation.rule.service"
|
||||||
|
_usage = "cancelation-rule"
|
||||||
|
_collection = "pms.services"
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.cancelation.rule.search.param"),
|
||||||
|
output_param=Datamodel("pms.cancelation.rule.info", is_list=True),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_cancelation_rules(self, cancelation_rule_search_param):
|
||||||
|
domain = []
|
||||||
|
|
||||||
|
if cancelation_rule_search_param.pricelistId:
|
||||||
|
domain.append(("pricelist_ids", "in", cancelation_rule_search_param.pricelistId))
|
||||||
|
if cancelation_rule_search_param.pmsPropertyId:
|
||||||
|
domain.append(("pms_property_ids", "in", cancelation_rule_search_param.pmsPropertyId))
|
||||||
|
|
||||||
|
result_cancelation_rules = []
|
||||||
|
PmsCancelationRuleInfo = self.env.datamodels["pms.cancelation.rule.info"]
|
||||||
|
for cancelation_rule in self.env["pms.cancelation.rule"].search(
|
||||||
|
domain,
|
||||||
|
):
|
||||||
|
result_cancelation_rules.append(
|
||||||
|
PmsCancelationRuleInfo(
|
||||||
|
id=cancelation_rule.id,
|
||||||
|
name=cancelation_rule.name,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return result_cancelation_rules
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:cancelation_rule_id>",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
output_param=Datamodel("pms.cancelation.rule.info", is_list=False),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_cancelation_rule(self, cancelation_rule_id):
|
||||||
|
cancelation_rule = self.env["pms.cancelation.rule"].search(
|
||||||
|
[("id", "=", cancelation_rule_id)]
|
||||||
|
)
|
||||||
|
if cancelation_rule:
|
||||||
|
PmsCancelationRuleInfo = self.env.datamodels["pms.cancelation.rule.info"]
|
||||||
|
return PmsCancelationRuleInfo(
|
||||||
|
id=cancelation_rule.id,
|
||||||
|
name=cancelation_rule.name,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise MissingError(_("Cancelation Rule not found"))
|
||||||
|
|
||||||
@@ -29,9 +29,7 @@ class PmsFolioService(Component):
|
|||||||
def get_folios(self, folio_search_param):
|
def get_folios(self, folio_search_param):
|
||||||
domain_fields = list()
|
domain_fields = list()
|
||||||
|
|
||||||
domain_fields.append(
|
domain_fields.append(("pms_property_id", "=", folio_search_param.pmsPropertyId))
|
||||||
("pms_property_id", "=", folio_search_param.pmsPropertyId)
|
|
||||||
)
|
|
||||||
|
|
||||||
if folio_search_param.dateTo and folio_search_param.dateFrom:
|
if folio_search_param.dateTo and folio_search_param.dateFrom:
|
||||||
reservation_lines = (
|
reservation_lines = (
|
||||||
@@ -75,7 +73,6 @@ class PmsFolioService(Component):
|
|||||||
for folio in self.env["pms.folio"].search(
|
for folio in self.env["pms.folio"].search(
|
||||||
[("id", "in", reservations_result)],
|
[("id", "in", reservations_result)],
|
||||||
):
|
):
|
||||||
reservations = []
|
|
||||||
for reservation in folio.reservation_ids:
|
for reservation in folio.reservation_ids:
|
||||||
reservation_lines = []
|
reservation_lines = []
|
||||||
for reservation_line in reservation.reservation_line_ids:
|
for reservation_line in reservation.reservation_line_ids:
|
||||||
@@ -90,8 +87,6 @@ class PmsFolioService(Component):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
result_folios.append(
|
result_folios.append(
|
||||||
PmsFolioInfo(
|
PmsFolioInfo(
|
||||||
id=folio.id,
|
id=folio.id,
|
||||||
@@ -205,8 +200,12 @@ class PmsFolioService(Component):
|
|||||||
boardServiceId=reservation.board_service_room_id.id or None,
|
boardServiceId=reservation.board_service_room_id.id or None,
|
||||||
saleChannelId=reservation.channel_type_id.id or None,
|
saleChannelId=reservation.channel_type_id.id or None,
|
||||||
agencyId=reservation.agency_id.id or None,
|
agencyId=reservation.agency_id.id or None,
|
||||||
checkin=datetime.combine(reservation.checkin, datetime.min.time()).isoformat(),
|
checkin=datetime.combine(
|
||||||
checkout=datetime.combine(reservation.checkout, datetime.min.time()).isoformat(),
|
reservation.checkin, datetime.min.time()
|
||||||
|
).isoformat(),
|
||||||
|
checkout=datetime.combine(
|
||||||
|
reservation.checkout, datetime.min.time()
|
||||||
|
).isoformat(),
|
||||||
arrivalHour=reservation.arrival_hour,
|
arrivalHour=reservation.arrival_hour,
|
||||||
departureHour=reservation.departure_hour,
|
departureHour=reservation.departure_hour,
|
||||||
roomTypeId=reservation.room_type_id.id or None,
|
roomTypeId=reservation.room_type_id.id or None,
|
||||||
@@ -221,9 +220,14 @@ class PmsFolioService(Component):
|
|||||||
allowedCheckout=reservation.allowed_checkout,
|
allowedCheckout=reservation.allowed_checkout,
|
||||||
isSplitted=reservation.splitted,
|
isSplitted=reservation.splitted,
|
||||||
pendingCheckinData=reservation.pending_checkin_data,
|
pendingCheckinData=reservation.pending_checkin_data,
|
||||||
createDate=datetime.combine(reservation.create_date , datetime.min.time()).isoformat(),
|
createDate=datetime.combine(
|
||||||
segmentationId=reservation.segmentation_ids[0].id if reservation.segmentation_ids else None,
|
reservation.create_date, datetime.min.time()
|
||||||
cancellationPolicyId=reservation.pricelist_id.cancelation_rule_id.id or None,
|
).isoformat(),
|
||||||
|
segmentationId=reservation.segmentation_ids[0].id
|
||||||
|
if reservation.segmentation_ids
|
||||||
|
else None,
|
||||||
|
cancellationPolicyId=reservation.pricelist_id.cancelation_rule_id.id
|
||||||
|
or None,
|
||||||
toAssign=reservation.to_assign,
|
toAssign=reservation.to_assign,
|
||||||
reservationType=reservation.reservation_type,
|
reservationType=reservation.reservation_type,
|
||||||
priceTotal=reservation.price_room_services_set,
|
priceTotal=reservation.price_room_services_set,
|
||||||
@@ -238,7 +242,6 @@ class PmsFolioService(Component):
|
|||||||
|
|
||||||
return reservations
|
return reservations
|
||||||
|
|
||||||
|
|
||||||
# @restapi.method(
|
# @restapi.method(
|
||||||
# [
|
# [
|
||||||
# (
|
# (
|
||||||
|
|||||||
89
pms_api_rest/services/pms_sale_channel_service.py
Normal file
89
pms_api_rest/services/pms_sale_channel_service.py
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
from odoo import _
|
||||||
|
from odoo.exceptions import MissingError
|
||||||
|
|
||||||
|
from odoo.addons.base_rest import restapi
|
||||||
|
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||||
|
from odoo.addons.component.core import Component
|
||||||
|
|
||||||
|
|
||||||
|
class PmsSaleChannelService(Component):
|
||||||
|
_inherit = "base.rest.service"
|
||||||
|
_name = "pms.sale.channel.service"
|
||||||
|
_usage = "sale-channel"
|
||||||
|
_collection = "pms.services"
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.sale.channel.search.param"),
|
||||||
|
output_param=Datamodel("pms.sale.channel.info", is_list=True),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_sale_channels(self, sale_channel_search_param):
|
||||||
|
sale_channels_all_properties = self.env["pms.sale.channel"].search(
|
||||||
|
[("pms_property_ids", "=", False)]
|
||||||
|
)
|
||||||
|
if sale_channel_search_param.pmsPropertyIds:
|
||||||
|
sale_channels = set()
|
||||||
|
for index, prop in enumerate(sale_channel_search_param.pmsPropertyIds):
|
||||||
|
sale_channels_with_query_property = self.env["pms.sale.channel"].search(
|
||||||
|
[("pms_property_ids", "=", prop)]
|
||||||
|
)
|
||||||
|
if index == 0:
|
||||||
|
sale_channels = set(sale_channels_with_query_property.ids)
|
||||||
|
else:
|
||||||
|
sale_channels = sale_channels.intersection(
|
||||||
|
set(sale_channels_with_query_property.ids)
|
||||||
|
)
|
||||||
|
sale_channels_total = list(
|
||||||
|
set(list(sale_channels) + sale_channels_all_properties.ids)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
sale_channels_total = list(sale_channels_all_properties.ids)
|
||||||
|
domain = [
|
||||||
|
("id", "in", sale_channels_total),
|
||||||
|
]
|
||||||
|
|
||||||
|
result_sale_channels = []
|
||||||
|
PmsSaleChannelInfo = self.env.datamodels["pms.sale.channel.info"]
|
||||||
|
for sale_channel in self.env["pms.sale.channel"].search(
|
||||||
|
domain,
|
||||||
|
):
|
||||||
|
result_sale_channels.append(
|
||||||
|
PmsSaleChannelInfo(
|
||||||
|
id=sale_channel.id,
|
||||||
|
name=sale_channel.name,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return result_sale_channels
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:sale_channel_id>",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
output_param=Datamodel("pms.sale.channel.info", is_list=False),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_sale_channel(self, sale_channel_id):
|
||||||
|
sale_channel = self.env["pms.sale.channel"].search(
|
||||||
|
[("id", "=", sale_channel_id)]
|
||||||
|
)
|
||||||
|
if sale_channel:
|
||||||
|
PmsSaleChannelInfo = self.env.datamodels["pms.sale.channel.info"]
|
||||||
|
return PmsSaleChannelInfo(
|
||||||
|
id=sale_channel.id,
|
||||||
|
name=sale_channel.name,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise MissingError(_("Sale Channel not found"))
|
||||||
Reference in New Issue
Block a user