From eafa6784a45e27430ad3dbf24f5a897878b56f0f Mon Sep 17 00:00:00 2001 From: Joaquin <20804419+joaquinco@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:41:36 -0300 Subject: [PATCH] [#162517][Daily Rate] Remove discounts for daily booking schedule rules (#4794) * Remove discounts for daily booking schedule rules --- app/models/instrument.rb | 4 ++ .../_schedule_rule_fields.html.haml | 2 +- app/views/schedule_rules/index.html.haml | 4 +- .../admin/instrument_scheduling_tab_spec.rb | 55 ++++++++++++++++++- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/app/models/instrument.rb b/app/models/instrument.rb index 613ff81d03..c19c2fc2c0 100644 --- a/app/models/instrument.rb +++ b/app/models/instrument.rb @@ -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 diff --git a/app/views/schedule_rules/_schedule_rule_fields.html.haml b/app/views/schedule_rules/_schedule_rule_fields.html.haml index 4defae763d..4ce0e9f89d 100644 --- a/app/views/schedule_rules/_schedule_rule_fields.html.haml +++ b/app/views/schedule_rules/_schedule_rule_fields.html.haml @@ -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") diff --git a/app/views/schedule_rules/index.html.haml b/app/views/schedule_rules/index.html.haml index 4137c9b0e2..1540d14fc8 100644 --- a/app/views/schedule_rules/index.html.haml +++ b/app/views/schedule_rules/index.html.haml @@ -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? @@ -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) diff --git a/spec/system/admin/instrument_scheduling_tab_spec.rb b/spec/system/admin/instrument_scheduling_tab_spec.rb index a2bd306620..dcccf0e9ca 100644 --- a/spec/system/admin/instrument_scheduling_tab_spec.rb +++ b/spec/system/admin/instrument_scheduling_tab_spec.rb @@ -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 @@ -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 @@ -109,4 +109,55 @@ 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") + within("table") do + expect(page).to have_content("Days of Week") + end + 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