Skip to content

Commit

Permalink
Allow Global Billing admins to update actual cost
Browse files Browse the repository at this point in the history
  • Loading branch information
LeticiaErrandonea committed Feb 28, 2025
1 parent 0024a86 commit 4af885a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
16 changes: 14 additions & 2 deletions app/controllers/order_management/order_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OrderManagement::OrderDetailsController < ApplicationController
# We can't load through the facility because of cross-core orders
before_action :init_order_detail, only: [:files, :template_results]

helper_method :edit_disabled?
helper_method :edit_disabled?, :actual_cost_edit_disabled?

before_action :authorize_order_detail, except: %i(sample_results)
before_action :load_accounts, only: [:edit, :update]
Expand Down Expand Up @@ -117,7 +117,19 @@ def load_order_statuses
end

def edit_disabled?
@order_detail.in_open_journal? || @order_detail.reconciled?
in_open_journal_or_reconciled = @order_detail.in_open_journal? || @order_detail.reconciled?

if SettingsHelper.feature_on?(:allow_global_billing_admin_update_actual_prices)
in_open_journal_or_reconciled || (@order_detail.awaiting_payment? && !current_user.global_billing_administrator?)
else
in_open_journal_or_reconciled
end
end

def actual_cost_edit_disabled?
return true unless SettingsHelper.feature_on?(:allow_global_billing_admin_update_actual_prices)

@order_detail.awaiting_payment? && !current_user.global_billing_administrator?
end

def init_order_detail
Expand Down
2 changes: 1 addition & 1 deletion app/views/order_management/order_details/_costs.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- f.object.send(:extend, PriceDisplayment)
- if f.object.actual_cost?
.cost-table
.cost= f.input :actual_cost, as: :currency
.cost= f.input :actual_cost, as: :currency, disabled: actual_cost_edit_disabled?
.subsidy= f.input :actual_subsidy, as: :currency, disabled: !f.object.price_policy.try(:has_subsidy?), hint: "#{f.object.price_policy.try(:price_group)}"
.total= f.input :actual_total, as: :currency, disabled: true
- else
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ feature:
sanger_enabled_service: <%= ENV.fetch("SANGER_ENABLED_SERVICE", false) %>
well_plate_alternative_csv_format: <%= ENV.fetch("well_plate_alternative_csv_format", false) %>
disable_relay_synaccess_rev_a: false
allow_global_billing_admin_update_actual_prices: false

split_accounts:
# Roles are allowed to create Split Accounts
Expand Down
46 changes: 46 additions & 0 deletions spec/system/admin/manage_order_detail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,50 @@
end
end
end

shared_examples "does not allow to update actual cost" do
it "does not allow to update actual cost" do
expect(page).to have_field("order_detail[actual_cost]", disabled: true)
end
end

describe "updating actual cost" do
let(:statement) { create(:statement, facility:, created_by: 1) }

before do
start_at = Time.zone.parse("#{Date.today} 10:00:00") - 1.day
end_at = start_at + 1.hour

reservation.update!(actual_start_at: start_at, actual_end_at: end_at)
order_detail.update!(reviewed_at: 5.days.ago, statement:, actual_cost: 10)

visit manage_facility_order_order_detail_path(facility, order, order_detail)
end

context "with feature flag ON", feature_setting: { allow_global_billing_admin_update_actual_prices: true } do
context "as a global admin" do
it_behaves_like "does not allow to update actual cost"
end

context "as a global billing admin" do
let(:logged_in_user) { create(:user, :global_billing_administrator) }

it "allows to update actual cost" do
expect(page).to have_field("order_detail[actual_cost]", disabled: false)
end
end
end

context "with feature flag OFF", feature_setting: { allow_global_billing_admin_update_actual_prices: false } do
context "as a global admin" do
it_behaves_like "does not allow to update actual cost"
end

context "as a global billing admin" do
let(:logged_in_user) { create(:user, :global_billing_administrator) }

it_behaves_like "does not allow to update actual cost"
end
end
end
end

0 comments on commit 4af885a

Please sign in to comment.