[WIP] pms-api-rest: wip PATCH/POST services problem

This commit is contained in:
miguelpadin
2023-03-14 12:16:00 +00:00
committed by Darío Lodeiros
parent ce7ea67374
commit e348a4293f
6 changed files with 75 additions and 19 deletions

View File

@@ -17,3 +17,4 @@ class PmsBoardServiceInfo(Datamodel):
roomTypeId = fields.Integer(required=True, allow_none=False)
amount = fields.Float(required=False, allow_none=False)
boardServiceId = fields.Integer(required=False, allow_none=False)
productIds = fields.List(fields.Integer(required=False, allow_none=False))

View File

@@ -24,6 +24,8 @@ class PmsReservationShortInfo(Datamodel):
priceTotal = fields.Float(required=False, allow_none=True)
servicesCount = fields.Integer(required=False, allow_none=True)
folioSequence = fields.Integer(required=False, allow_none=True)
pricelistId = fields.Integer(required=False, allow_none=True)
class PmsReservationInfo(Datamodel):
@@ -34,6 +36,7 @@ class PmsReservationInfo(Datamodel):
folioSequence = fields.Integer(required=False, allow_none=True)
partnerName = fields.String(required=False, allow_none=True)
boardServiceId = fields.Integer(required=False, allow_none=True)
boardServices = fields.List(NestedModel("pms.service.info"), required=False, allow_none=True)
saleChannelId = fields.Integer(required=False, allow_none=True)
agencyId = fields.Integer(required=False, allow_none=True)
userId = fields.Integer(required=False, allow_none=True)

View File

@@ -52,6 +52,7 @@ class PmsBoardServiceService(Component):
roomTypeId=board_service.pms_room_type_id.id,
amount=round(board_service.amount, 2),
boardServiceId=board_service.pms_board_service_id,
productIds=board_service.board_service_line_ids.mapped("product_id.id"),
)
)
return result_board_services
@@ -79,6 +80,7 @@ class PmsBoardServiceService(Component):
name=board_service.pms_board_service_id.display_name,
roomTypeId=board_service.pms_room_type_id.id,
amount=round(board_service.amount),
productIds=board_service.board_service_line_ids.mapped("product_id.id"),
)
else:
raise MissingError(_("Board Service not found"))

View File

@@ -435,6 +435,7 @@ class PmsFolioService(Component):
folioSequence=reservation.folio_sequence
if reservation.folio_sequence
else None,
pricelistId=reservation.pricelist_id,
servicesCount=sum(
reservation.service_ids.filtered(
lambda x: not x.is_board_service

View File

@@ -33,19 +33,25 @@ class PmsPriceService(Component):
room_type = self.env["pms.room.type"].search(
[("id", "=", prices_search_param.roomTypeId)]
)
if prices_search_param.productId:
elif prices_search_param.productId and prices_search_param.boardServiceId:
product = self.env["product.product"].search(
[("id", "=", prices_search_param.productId)]
)
if prices_search_param.boardServiceId:
board_service = self.env["pms.board.service.room.type"].search(
[("id", "=", prices_search_param.boardServiceId)]
)
if sum([var is not False for var in [product, room_type, board_service]]) != 1:
elif prices_search_param.productId:
product = self.env["product.product"].search(
[("id", "=", prices_search_param.productId)]
)
elif prices_search_param.boardServiceId:
board_service = self.env["pms.board.service.room.type"].search(
[("id", "=", prices_search_param.boardServiceId)]
)
else:
raise MissingError(
_(
"It is necessary to indicate one and only one product,"
" board service or room type"
"Wrong input param"
)
)
@@ -72,6 +78,7 @@ class PmsPriceService(Component):
partner_id=prices_search_param.partnerId,
product_qty=prices_search_param.productQty,
date_consumption=price_date,
product_id=product.id if product else False,
),
2,
),
@@ -143,9 +150,14 @@ class PmsPriceService(Component):
partner_id=False,
product_qty=False,
date_consumption=False,
product_id=False,
):
price = 0
for product in board_service.board_service_line_ids.mapped("product_id"):
if product_id:
products = self.env['product.product'].browse(product_id)
else:
products = board_service.board_service_line_ids.mapped("product_id")
for product in products:
price += self._get_product_price(
product=product,
pms_property_id=pms_property_id,

View File

@@ -120,7 +120,7 @@ class PmsReservationService(Component):
)
return res
def _create_vals_from_params(self, reservation_vals, reservation_data):
def _create_vals_from_params(self, reservation_vals, reservation_data, reservation_id):
if reservation_data.preferredRoomId:
reservation_vals.update(
{"preferred_room_id": reservation_data.preferredRoomId}
@@ -139,6 +139,12 @@ class PmsReservationService(Component):
reservation_vals.update(
{"segmentation_ids": [(6, 0, [reservation_data.segmentationId])]}
)
if reservation_data.checkin:
reservation_vals.update({"checkin": reservation_data.checkin})
if reservation_data.checkout:
reservation_vals.update({"checkout": reservation_data.checkout})
return reservation_vals
@restapi.method(
@@ -203,25 +209,56 @@ class PmsReservationService(Component):
reservation.confirm()
if reservation_data.toCheckout is not None and reservation_data.toCheckout:
reservation.action_reservation_checkout()
if (
reservation_data.roomTypeId
and reservation.room_type_id.id != reservation_data.roomTypeId
):
reservation.room_type_id = reservation_data.roomTypeId
reservation_vals = self._create_vals_from_params(
reservation_vals,
reservation_data,
reservation_id,
)
# TODO: this should be @ pms core
if (
reservation_data.boardServiceId is not None
and reservation_data.boardServiceId != reservation.board_service_room_id
):
reservation.service_ids.filtered(lambda x: x.is_board_service).unlink()
service_cmds = []
if reservation_data.boardServiceId is not None or reservation_data.boardServices is not None:
for service in reservation.service_ids.filtered(lambda x: x.is_board_service):
service_cmds.append((2, service.id))
if reservation_data.boardServices is not None:
for bs in reservation_data.boardServices:
service_line_cmds = []
for line in bs.serviceLines:
service_line_cmds.append(
(
0,
False,
{
"price_unit": line.priceUnit,
"date": line.date,
"discount": line.discount,
"day_qty": line.quantity,
"auto_qty": True,
},
)
)
service_cmds.append(
(
0,
False,
{
"product_id": bs.productId,
"is_board_service": True,
"reservation_id": reservation_id,
"service_line_ids": service_line_cmds,
}
)
)
if service_cmds:
reservation_vals.update({"service_ids": service_cmds})
if reservation_vals:
reservation.write(reservation_vals)
if reservation_data.boardServices:
reservation.with_context(skip_compute_service_ids=True).write(reservation_vals)
else:
reservation.write(reservation_vals)
print(reservation.service_ids.mapped("name"))
def _get_reservation_lines_mapped(self, origin_data, reservation_line=False):
# Return dict witch reservation.lines values (only modified if line exist,