Skip to content

Commit

Permalink
Remove discounts for daily booking schedule rules
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinco committed Nov 28, 2024
1 parent 7516235 commit fcbcee4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/models/instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def daily_booking?
pricing_mode == Pricing::SCHEDULE_DAILY
end

def can_apply_discounts?
!(duration_pricing_mode? || daily_booking?)
end

private

def minimum_reservation_is_multiple_of_interval
Expand Down
2 changes: 1 addition & 1 deletion app/views/schedule_rules/_schedule_rule_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
= f.label :end_time
= time_select24(f, :end, hours: (0..24), minute_step: @product.reserve_interval)

- unless @product.duration_pricing_mode?
- if @product.can_apply_discounts?
%h3= t("views.schedule_rules.discount")

%p= t("views.schedule_rules.discount_hint")
Expand Down
4 changes: 2 additions & 2 deletions app/views/schedule_rules/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
%th Days of Week
%th Start Time
%th End Time
- unless @product.duration_pricing_mode?
- if @product.can_apply_discounts?
- PriceGroup.globals.each do |price_group|
%th.currency= "#{price_group.name} Discount (%)"
- if @product.product_access_groups.to_a.any?
Expand All @@ -47,7 +47,7 @@
%td= schedule_rule.days_string
%td= human_time(Time.zone.parse(schedule_rule.start_time))
%td= human_time(Time.zone.parse(schedule_rule.end_time))
- unless @product.duration_pricing_mode?
- if @product.can_apply_discounts?
- PriceGroup.globals.each do |price_group|
- discount = schedule_rule.discount_for_price_group(price_group)
%td.currency= number_to_percentage(discount, strip_insignificant_zeros: true)
Expand Down
52 changes: 50 additions & 2 deletions spec/system/admin/instrument_scheduling_tab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

context "when the instrument has duration pricing mode" do
let!(:instrument) do
FactoryBot.create(:setup_instrument, pricing_mode: "Duration", facility: facility)
FactoryBot.create(:setup_instrument, pricing_mode: "Duration", facility:)
end

context "new schedule rule" do
Expand Down Expand Up @@ -65,7 +65,7 @@

context "when the instrument has schedule pricing mode" do
let!(:instrument) do
FactoryBot.create(:setup_instrument, pricing_mode: "Schedule Rule", facility: facility)
FactoryBot.create(:setup_instrument, pricing_mode: "Schedule Rule", facility:)
end

context "new schedule rule" do
Expand Down Expand Up @@ -109,4 +109,52 @@
end
end

describe "daily booking instrument" do
let(:instrument) { create :setup_instrument, :daily_booking }
let(:facility) { instrument.facility }

before do
login_as user
end

it "does not show discounts in index table" do
expect(instrument.schedule_rules).to_not be_empty

visit facility_instrument_schedule_rules_path(facility, instrument)

expect(page).to_not have_content("Discount")
end

it "works as expected on create" do
# Destroy other rules so we don't deal with conflicts
instrument.schedule_rules.destroy_all

visit new_facility_instrument_schedule_rule_path(facility, instrument)

expect(page).to_not have_content("Discount")

check("Tue")
click_button("Create")

expect(page).to have_content(I18n.t("controllers.schedule_rules.create"))
end

it "works as expected on edit" do
schedule_rule = instrument.schedule_rules.last
# Destroy other rules so we don't deal with conflicts
instrument.schedule_rules.where.not(id: schedule_rule.id).destroy_all

visit edit_facility_instrument_schedule_rule_path(facility, instrument, schedule_rule)

expect(page).to_not have_content("Discount")

check("Mon")
check("Tue")
check("Wed")

click_button("Update")

expect(page).to have_content(I18n.t("controllers.schedule_rules.update"))
end
end
end

0 comments on commit fcbcee4

Please sign in to comment.