Skip to content

Commit

Permalink
[NUOPEN-215][Shared dev] Show duration in days for Daily Rate Instrum…
Browse files Browse the repository at this point in the history
…ents (#5031)

* Show Days instead of hours in order receipt

* Show Days instead of hours in order

* Prefer try(:daily_booking?)
  • Loading branch information
LeticiaErrandonea authored Feb 19, 2025
1 parent 50de892 commit eb2fc37
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
19 changes: 18 additions & 1 deletion app/presenters/quantity_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ def html
end
end

DayQuantityDisplay = Struct.new(:value) do
include ActionView::Helpers::TagHelper

def csv
# equal sign and quotes prevent Excel from formatting as a date/time
%(="#{value}")
end

delegate :to_s, to: :value

def html
to_s
end
end

delegate :to_s, :csv, :html, to: :display

def initialize(product, quantity)
Expand All @@ -41,7 +56,9 @@ def initialize(product, quantity)
private

def display
@display ||= if @product.quantity_as_time?
@display ||= if @product.try(:daily_booking?)
DayQuantityDisplay.new(@quantity)
elsif @product.quantity_as_time?
TimeQuantityDisplay.new(@quantity)
else
QuantityDisplay.new(@quantity)
Expand Down
15 changes: 14 additions & 1 deletion app/support/price_displayment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,29 @@ def build_statement_quantity_presenter
end

def build_quantity_presenter
quantity_to_display = if time_data.try(:actual_duration_mins) && time_data.actual_duration_mins.to_i > 0
quantity_to_display = if product.try(:daily_booking?)
daily_booking_quantity
elsif time_data.try(:actual_duration_mins) && time_data.actual_duration_mins.to_i > 0
time_data.actual_duration_mins
elsif time_data.try(:duration_mins)
time_data.duration_mins
else
quantity
end

QuantityPresenter.new(product, quantity_to_display)
end

def daily_booking_quantity
if time_data.try(:actual_duration_days) && time_data.actual_duration_days.to_i > 0
time_data.actual_duration_days
elsif time_data.try(:duration_days)
time_data.duration_days
else
quantity
end
end

def empty_display
"Unassigned"
end
Expand Down
10 changes: 10 additions & 0 deletions app/support/reservations/date_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def actual_duration_mins(actual_end_fallback: nil)
end
end

def actual_duration_days(actual_end_fallback: nil)
if @actual_duration_days
@actual_duration_days.to_i
elsif actual_start_at
TimeRange.new(actual_start_at, actual_end_at || actual_end_fallback).duration_days
else
0
end
end

def actual_start_date
date_field(:actual_start)
end
Expand Down
14 changes: 12 additions & 2 deletions app/views/facility_orders/_order_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@
%td.order_date
= od.ordered_at&.strftime("%m/%d/%Y")
%td.currency.timeinput= od.reservation.try(:duration_mins)
- daily_booking_product = od.product.try(:daily_booking?)
- if daily_booking_product
%td.currency
= od.reservation.try(:duration_days)
- else
%td.currency.timeinput= od.reservation.try(:duration_mins)
- if od.time_data.present?
%td.currency{class: od.time_data.actual_duration_mins ? "timeinput" : ""}= od.time_data.actual_duration_mins || "???"
- if daily_booking_product
%td.currency
= od.time_data.actual_duration_days || "???"
- else
%td.currency{class: od.time_data.actual_duration_mins ? "timeinput" : ""}
= od.time_data.actual_duration_mins || "???"
- elsif od.quantity_as_time?
%td.currency.timeinput= od.quantity
- else
Expand Down
39 changes: 39 additions & 0 deletions spec/system/admin/order_show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Order show" do
let(:facility) { create(:setup_facility) }
let(:account) { create(:setup_account) }
let!(:instrument) { create(:setup_instrument, :always_available, :daily_booking, facility:) }
let(:reservation_order) { create(:setup_order, product: instrument, account:) }
let!(:reservation) do
create(
:purchased_reservation,
product: instrument,
order_detail: reservation_order.order_details.first,
reserve_start_at: 1.day.from_now,
reserve_end_at: 4.days.from_now
)
end
let(:facility_administrator) { create(:user, :facility_administrator, facility:) }

before do
login_as facility_administrator
visit facility_order_path(facility, reservation_order)
end

describe "reservation duration" do
it "is correctly displayed in days" do
# Reserved is the third column
expect(all("tbody tr").first.all("td")[2]).to have_text("3", exact: true)
end
end

describe "reservation actual" do
it "is correctly displayed in days" do
# Actual is the fourth column
expect(all("tbody tr").first.all("td")[3]).to have_text("0", exact: true)
end
end
end

0 comments on commit eb2fc37

Please sign in to comment.