mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: add services in reservation service and service lines service
This commit is contained in:
@@ -42,3 +42,5 @@ from . import pms_product
|
|||||||
from . import pms_sale_channel
|
from . import pms_sale_channel
|
||||||
from . import pms_cancelation_rule
|
from . import pms_cancelation_rule
|
||||||
from . import pms_agency
|
from . import pms_agency
|
||||||
|
from . import pms_service
|
||||||
|
from . import pms_service_line
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class PmsReservationShortInfo(Datamodel):
|
|||||||
allowedCheckout = fields.Boolean(required=False, allow_none=True)
|
allowedCheckout = fields.Boolean(required=False, allow_none=True)
|
||||||
isSplitted = fields.Boolean(required=False, allow_none=True)
|
isSplitted = fields.Boolean(required=False, allow_none=True)
|
||||||
priceTotal = fields.Float(required=False, allow_none=True)
|
priceTotal = fields.Float(required=False, allow_none=True)
|
||||||
|
servicesCount = fields.Integer(required=False, allow_none=True)
|
||||||
|
|
||||||
|
|
||||||
class PmsReservationInfo(Datamodel):
|
class PmsReservationInfo(Datamodel):
|
||||||
|
|||||||
14
pms_api_rest/datamodels/pms_service.py
Normal file
14
pms_api_rest/datamodels/pms_service.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class PmsServiceInfo(Datamodel):
|
||||||
|
_name = "pms.service.info"
|
||||||
|
id = fields.Integer(required=False, allow_none=True)
|
||||||
|
name = fields.String(required=False, allow_none=True)
|
||||||
|
quantity = fields.Integer(required=False, allow_none=True)
|
||||||
|
priceTotal = fields.Float(required=False, allow_none=True)
|
||||||
|
priceSubtotal = fields.Float(required=False, allow_none=True)
|
||||||
|
priceTaxes = fields.Float(required=False, allow_none=True)
|
||||||
|
discount = fields.Float(required=False, allow_none=True)
|
||||||
14
pms_api_rest/datamodels/pms_service_line.py
Normal file
14
pms_api_rest/datamodels/pms_service_line.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class PmsServiceLineInfo(Datamodel):
|
||||||
|
_name = "pms.service.line.info"
|
||||||
|
id = fields.Integer(required=False, allow_none=True)
|
||||||
|
isBoardService = fields.Boolean(required=False, allow_none=True)
|
||||||
|
productId = fields.Integer(required=False,allow_none=True)
|
||||||
|
date = fields.String(required=False, allow_none=True)
|
||||||
|
priceUnit = fields.Float(required=False, allow_none=True)
|
||||||
|
priceTotal = fields.Float(required=False, allow_none=True)
|
||||||
|
discount = fields.Float(required=False, allow_none=True)
|
||||||
@@ -29,3 +29,4 @@ from . import pms_sale_channel_service
|
|||||||
from . import pms_cancelation_rule_service
|
from . import pms_cancelation_rule_service
|
||||||
|
|
||||||
from . import pms_agency_service
|
from . import pms_agency_service
|
||||||
|
from . import pms_service_line_service
|
||||||
|
|||||||
@@ -254,6 +254,11 @@ class PmsFolioService(Component):
|
|||||||
allowedCheckout=reservation.allowed_checkout,
|
allowedCheckout=reservation.allowed_checkout,
|
||||||
isSplitted=reservation.splitted,
|
isSplitted=reservation.splitted,
|
||||||
priceTotal=reservation.price_room_services_set,
|
priceTotal=reservation.price_room_services_set,
|
||||||
|
servicesCount=len(
|
||||||
|
reservation.service_ids.filtered(
|
||||||
|
lambda x: not x.is_board_service
|
||||||
|
)
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -249,6 +249,38 @@ class PmsReservationService(Component):
|
|||||||
)
|
)
|
||||||
return result_lines
|
return result_lines
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:reservation_id>/services",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
output_param=Datamodel("pms.service.info", is_list=True),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_reservation_services(self, reservation_id):
|
||||||
|
reservation = self.env["pms.reservation"].search([("id", "=", reservation_id)])
|
||||||
|
if not reservation:
|
||||||
|
raise MissingError(_("Reservation not found"))
|
||||||
|
result_services = []
|
||||||
|
PmsServiceInfo = self.env.datamodels["pms.service.info"]
|
||||||
|
for service in reservation.service_ids:
|
||||||
|
result_services.append(
|
||||||
|
PmsServiceInfo(
|
||||||
|
id=service.id,
|
||||||
|
name=service.name,
|
||||||
|
quantity=service.product_qty,
|
||||||
|
priceTotal=service.price_total,
|
||||||
|
priceSubtotal=service.price_subtotal,
|
||||||
|
priceTaxes=service.price_tax,
|
||||||
|
discount=service.discount,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return result_services
|
||||||
|
|
||||||
@restapi.method(
|
@restapi.method(
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
|
|||||||
52
pms_api_rest/services/pms_service_line_service.py
Normal file
52
pms_api_rest/services/pms_service_line_service.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
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 PmsServiceService(Component):
|
||||||
|
_inherit = "base.rest.service"
|
||||||
|
_name = "pms.reservation.line.service"
|
||||||
|
_usage = "service"
|
||||||
|
_collection = "pms.services"
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:service_id>/service-lines",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
output_param=Datamodel("pms.service.line.info", is_list=True),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_service_lines(self, service_id):
|
||||||
|
service = self.env["pms.service"].search(
|
||||||
|
[("id", "=", service_id)]
|
||||||
|
)
|
||||||
|
if not service:
|
||||||
|
raise MissingError(_("Service not found"))
|
||||||
|
result_service_lines = []
|
||||||
|
PmsServiceLineInfo = self.env.datamodels["pms.service.line.info"]
|
||||||
|
for service_line in service.service_line_ids:
|
||||||
|
result_service_lines.append(
|
||||||
|
PmsServiceLineInfo(
|
||||||
|
id=service_line.id,
|
||||||
|
isBoardService=service_line.is_board_service,
|
||||||
|
productId=service_line.product_id.id,
|
||||||
|
date=datetime.combine(
|
||||||
|
service_line.date, datetime.min.time()
|
||||||
|
).isoformat(),
|
||||||
|
priceUnit=service_line.price_unit,
|
||||||
|
priceTotal=service_line.price_day_total,
|
||||||
|
discount=service_line.discount,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return result_service_lines
|
||||||
|
|
||||||
Reference in New Issue
Block a user