feat: Captain::Reservation callback cria nota interna automaticamente
Cobre ambos os caminhos (generate_pix_tool e PublicReservationsController): toda reserva criada recebe um after_create_commit que posta uma mensagem privada na conversa com os detalhes (suite, check-in, valores, ID). Remove a criacao duplicada do PublicReservationsController.
This commit is contained in:
parent
f8d64b6992
commit
996704350b
@ -56,13 +56,8 @@ class Public::Api::V1::Captain::PublicReservationsController < ActionController:
|
||||
contact_inbox: contact_inbox
|
||||
).perform
|
||||
|
||||
initial_note = build_initial_note(params)
|
||||
|
||||
Messages::MessageBuilder.new(
|
||||
nil,
|
||||
conversation,
|
||||
{ content: initial_note, message_type: 'outgoing', private: true }
|
||||
).perform
|
||||
# Nota: o model Captain::Reservation#post_internal_reservation_note ja cria
|
||||
# a nota interna automaticamente via after_create_commit. Nao duplicamos aqui.
|
||||
|
||||
reservation = Captain::Reservation.create!(
|
||||
account: account,
|
||||
|
||||
@ -89,6 +89,7 @@ class Captain::Reservation < ApplicationRecord
|
||||
before_validation :set_captain_unit_id, on: :create
|
||||
after_commit :sync_conversation_marker_snapshot
|
||||
after_create_commit :update_contact_reservation_metadata
|
||||
after_create_commit :post_internal_reservation_note
|
||||
|
||||
def ui_status
|
||||
Captain::Reservations::MarkerBuilder.ui_status(status)
|
||||
@ -127,6 +128,38 @@ class Captain::Reservation < ApplicationRecord
|
||||
Rails.logger.error("[Captain::Reservation] failed to sync conversation marker: #{e.class} - #{e.message}")
|
||||
end
|
||||
|
||||
# Cria uma nota interna (privada) na conversa com os detalhes da reserva
|
||||
# recem criada. A atendente humana ve tudo em um so lugar.
|
||||
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
||||
def post_internal_reservation_note
|
||||
return if conversation.blank?
|
||||
|
||||
meta = metadata.to_h
|
||||
deposit = meta['deposit_amount'].to_f
|
||||
deposit = (total_amount.to_f / 2.0) if deposit <= 0
|
||||
|
||||
check_in_fmt = check_in_at&.strftime('%d/%m/%Y %H:%M') || '—'
|
||||
category = meta['category'].presence || suite_identifier
|
||||
|
||||
content = [
|
||||
'🛎️ *Nova reserva criada*',
|
||||
"Suíte: #{category}",
|
||||
"Check-in: #{check_in_fmt}",
|
||||
"Valor total: R$ #{format('%.2f', total_amount.to_f)}",
|
||||
"Sinal (PIX 50%): R$ #{format('%.2f', deposit)}",
|
||||
"Reserva ##{id}"
|
||||
].join("\n")
|
||||
|
||||
Messages::MessageBuilder.new(
|
||||
nil,
|
||||
conversation,
|
||||
{ content: content, message_type: 'outgoing', private: true }
|
||||
).perform
|
||||
rescue StandardError => e
|
||||
Rails.logger.warn("[Captain::Reservation] failed to post internal note: #{e.class} - #{e.message}")
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength
|
||||
|
||||
# Atualiza campos visiveis no painel lateral do Chatwoot (custom_attributes)
|
||||
# pra que a recepcionista veja num relance:
|
||||
# ultima_suite, ultima_permanencia, ultima_reserva_em, total_reservas
|
||||
|
||||
Loading…
Reference in New Issue
Block a user