mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[RFC]pms_api_rest: refactoring PATCH services
This commit is contained in:
@@ -504,21 +504,21 @@ class PmsCalendarService(Component):
|
||||
reservation_vals.update(
|
||||
{"preferred_room_id": reservation_lines_changes.preferredRoomId}
|
||||
)
|
||||
if reservation_lines_changes.boardServiceId:
|
||||
if reservation_lines_changes.boardServiceId is not None:
|
||||
reservation_vals.update(
|
||||
{"board_service_room_id": reservation_lines_changes.boardServiceId}
|
||||
)
|
||||
if reservation_lines_changes.pricelistId:
|
||||
if reservation_lines_changes.pricelistId is not None:
|
||||
reservation_vals.update(
|
||||
{"pricelist_id": reservation_lines_changes.pricelistId}
|
||||
)
|
||||
if reservation_lines_changes.adults:
|
||||
reservation_vals.update({"adults": reservation_lines_changes.adults})
|
||||
if reservation_lines_changes.children:
|
||||
if reservation_lines_changes.children is not None:
|
||||
reservation_vals.update(
|
||||
{"children": reservation_lines_changes.children}
|
||||
)
|
||||
if reservation_lines_changes.segmentationId:
|
||||
if reservation_lines_changes.segmentationId is not None:
|
||||
reservation_vals.update(
|
||||
{
|
||||
"segmentation_ids": [
|
||||
|
||||
@@ -477,11 +477,16 @@ class PmsFolioService(Component):
|
||||
)
|
||||
def update_folio(self, folio_id, pms_folio_info):
|
||||
folio = self.env["pms.folio"].browse(folio_id)
|
||||
folio_vals = {}
|
||||
if folio:
|
||||
folio.write({"internal_comment": pms_folio_info.internalComment})
|
||||
else:
|
||||
raise MissingError(_("Folio not found"))
|
||||
|
||||
if pms_folio_info.internalComment is not None:
|
||||
folio_vals["internal_comment"]: pms_folio_info.internalComment
|
||||
|
||||
if folio_vals:
|
||||
folio.write(folio_vals)
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
|
||||
@@ -33,12 +33,12 @@ class PmsInvoiceService(Component):
|
||||
raise UserError(_("You can't update a reversed invoice"))
|
||||
new_vals = {}
|
||||
if (
|
||||
pms_invoice_info.partnerId
|
||||
pms_invoice_info.partnerId is not None
|
||||
and pms_invoice_info.partnerId != invoice.partner_id.id
|
||||
):
|
||||
new_vals["partner_id"] = pms_invoice_info.partnerId
|
||||
|
||||
if pms_invoice_info.date:
|
||||
if pms_invoice_info.date is not None:
|
||||
invoice_date_info = fields.Date.from_string(pms_invoice_info.date)
|
||||
if invoice_date_info != invoice.invoice_date:
|
||||
new_vals["invoice_date"] = invoice_date_info
|
||||
@@ -46,7 +46,7 @@ class PmsInvoiceService(Component):
|
||||
# If invoice lines are updated, we expect that all lines will be
|
||||
# send to service, the lines that are not sent we assume that
|
||||
# they have been eliminated
|
||||
if pms_invoice_info.moveLines and pms_invoice_info.moveLines is not None:
|
||||
if pms_invoice_info.moveLines is not None:
|
||||
cmd_invoice_lines = self._get_invoice_lines_commands(
|
||||
invoice, pms_invoice_info
|
||||
)
|
||||
|
||||
@@ -568,6 +568,6 @@ class PmsPartnerService(Component):
|
||||
birthdate = birthdate.strftime("%Y-%m-%d")
|
||||
vals.update({"birthdate_date": birthdate})
|
||||
for k, v in partner_fields.items():
|
||||
if v:
|
||||
if v is not None:
|
||||
vals.update({k: v})
|
||||
return vals
|
||||
|
||||
@@ -118,11 +118,11 @@ class PmsReservationLineService(Component):
|
||||
)
|
||||
vals = dict()
|
||||
if reservation_line:
|
||||
if reservation_line_info.price:
|
||||
if reservation_line_info.price is not None:
|
||||
vals["price"] = reservation_line_info.price
|
||||
if reservation_line_info.discount:
|
||||
if reservation_line_info.discount is not None:
|
||||
vals["discount"] = reservation_line_info.discount
|
||||
if reservation_line_info.cancelDiscount:
|
||||
if reservation_line_info.cancelDiscount is not None:
|
||||
vals["cancel_discount"] = reservation_line_info.cancelDiscount
|
||||
if reservation_line_info.roomId:
|
||||
vals["room_id"] = reservation_line_info.roomId
|
||||
|
||||
@@ -122,15 +122,15 @@ class PmsReservationService(Component):
|
||||
reservation_vals.update(
|
||||
{"preferred_room_id": reservation_data.preferredRoomId}
|
||||
)
|
||||
if reservation_data.boardServiceId:
|
||||
if reservation_data.boardServiceId is not None:
|
||||
reservation_vals.update(
|
||||
{"board_service_room_id": reservation_data.boardServiceId}
|
||||
{"board_service_room_id": reservation_data.boardServiceId or False}
|
||||
)
|
||||
if reservation_data.pricelistId:
|
||||
reservation_vals.update({"pricelist_id": reservation_data.pricelistId})
|
||||
if reservation_data.adults:
|
||||
reservation_vals.update({"adults": reservation_data.adults})
|
||||
if reservation_data.children:
|
||||
if reservation_data.children is not None:
|
||||
reservation_vals.update({"children": reservation_data.children})
|
||||
if reservation_data.segmentationId:
|
||||
reservation_vals.update(
|
||||
@@ -554,17 +554,16 @@ class PmsReservationService(Component):
|
||||
checkin_partner = self.env["pms.checkin.partner"].search(
|
||||
[("id", "=", checkin_partner_id), ("reservation_id", "=", reservation_id)]
|
||||
)
|
||||
if not checkin_partner:
|
||||
raise MissingError(_("Checkin partner not found"))
|
||||
if (
|
||||
pms_checkin_partner_info.actionOnBoard
|
||||
and pms_checkin_partner_info.actionOnBoard is not None
|
||||
and pms_checkin_partner_info.actionOnBoard
|
||||
and checkin_partner
|
||||
):
|
||||
checkin_partner.action_on_board()
|
||||
if checkin_partner:
|
||||
checkin_partner.write(
|
||||
self.mapping_checkin_partner_values(pms_checkin_partner_info)
|
||||
)
|
||||
checkin_partner.write(
|
||||
self.mapping_checkin_partner_values(pms_checkin_partner_info)
|
||||
)
|
||||
return checkin_partner.id
|
||||
|
||||
@restapi.method(
|
||||
|
||||
@@ -136,11 +136,16 @@ class PmsRoomService(Component):
|
||||
)
|
||||
def update_room(self, room_id, pms_room_info_data):
|
||||
room = self.env["pms.room"].search([("id", "=", room_id)])
|
||||
if room:
|
||||
room.name = pms_room_info_data.name
|
||||
else:
|
||||
room_vals = {}
|
||||
if not room:
|
||||
raise MissingError(_("Room not found"))
|
||||
|
||||
if pms_room_info_data.name:
|
||||
room_vals["name"] = pms_room_info_data.name
|
||||
|
||||
if room_vals:
|
||||
room.write(room_vals)
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
|
||||
@@ -64,11 +64,11 @@ class PmsServiceLineService(Component):
|
||||
vals["date"] = datetime.strptime(
|
||||
pms_service_line_info_data.date, "%Y-%m-%d"
|
||||
).date()
|
||||
if pms_service_line_info_data.discount:
|
||||
if pms_service_line_info_data.discount is not None:
|
||||
vals["discount"] = pms_service_line_info_data.discount
|
||||
if pms_service_line_info_data.quantity:
|
||||
if pms_service_line_info_data.quantity is not None:
|
||||
vals["day_qty"] = pms_service_line_info_data.quantity
|
||||
if pms_service_line_info_data.priceUnit:
|
||||
if pms_service_line_info_data.priceUnit is not None:
|
||||
vals["price_unit"] = pms_service_line_info_data.priceUnit
|
||||
service_line.write(vals)
|
||||
else:
|
||||
|
||||
@@ -311,17 +311,17 @@ class PmsTransactionService(Component):
|
||||
counterpart_transaction = False
|
||||
# TODO: Downpayment invoiced (search invoice, reverse it and create a new one)
|
||||
# Get generic update vals
|
||||
if pms_transaction_info.amount and round(
|
||||
if pms_transaction_info.amount is not None and round(
|
||||
pms_transaction_info.amount, 2
|
||||
) != round(transaction.amount, 2):
|
||||
vals["amount"] = pms_transaction_info.amount
|
||||
if (
|
||||
pms_transaction_info.partnerId
|
||||
pms_transaction_info.partnerId is not None
|
||||
and pms_transaction_info.partnerId != transaction.partner_id.id
|
||||
):
|
||||
vals["partner_id"] = pms_transaction_info.partnerId
|
||||
if (
|
||||
pms_transaction_info.reference
|
||||
pms_transaction_info.reference is not None
|
||||
and pms_transaction_info.reference != transaction.ref
|
||||
):
|
||||
vals["ref"] = pms_transaction_info.reference
|
||||
|
||||
Reference in New Issue
Block a user