diff --git a/app/controllers/admin/payroll_runs_controller.rb b/app/controllers/admin/payroll_runs_controller.rb index d1feac8886..415bc92bb4 100644 --- a/app/controllers/admin/payroll_runs_controller.rb +++ b/app/controllers/admin/payroll_runs_controller.rb @@ -11,19 +11,6 @@ def index def new @claims = Claim.payrollable.order(submitted_at: :asc) - # Due to limitations with the current payroll software we need a temporary - # cap on the number of claims that can enter payroll, especially expecting - # a high volume of approved claims in the first few months. - # - # Ideally, we should limit topups as well, as some may be related to claims - # paid in a previous payroll run, but we wouldn't have any topups at the beginning. - # - # TODO: Remove this capping once the payroll software is upgraded. - if @claims.size > PayrollRun::MAX_MONTHLY_PAYMENTS - flash[:notice] = "The number of payments entering this payrun will be capped to #{PayrollRun::MAX_MONTHLY_PAYMENTS}" - @claims = @claims.limit(PayrollRun::MAX_MONTHLY_PAYMENTS) - end - @topups = Topup.payrollable @total_award_amount = @claims.sum(&:award_amount) + @topups.sum(&:award_amount) end diff --git a/app/models/payroll_run.rb b/app/models/payroll_run.rb index d8b101865b..efe46dff20 100644 --- a/app/models/payroll_run.rb +++ b/app/models/payroll_run.rb @@ -1,7 +1,4 @@ class PayrollRun < ApplicationRecord - MAX_BATCH_SIZE = 1000 - MAX_MONTHLY_PAYMENTS = 3000 - has_many :payments, dependent: :destroy has_many :claims, through: :payments has_many :payment_confirmations, dependent: :destroy @@ -13,7 +10,6 @@ class PayrollRun < ApplicationRecord belongs_to :confirmation_report_uploaded_by, class_name: "DfeSignIn::User", optional: true validate :ensure_no_payroll_run_this_month, on: :create - validate :ensure_within_max_monthly_payments, on: :create scope :this_month, -> { where(created_at: DateTime.now.all_month) } @@ -35,10 +31,6 @@ def total_claim_amount_for_policy(policy, filter: :all) line_items(policy, filter: filter).sum(&:award_amount) end - def total_batches - (payments.count / MAX_BATCH_SIZE.to_f).ceil - end - def total_confirmed_payments payments.where.not(confirmation: nil).count end @@ -100,8 +92,4 @@ def line_items(policy, filter: :all) def ensure_no_payroll_run_this_month errors.add(:base, "There has already been a payroll run for #{Date.today.strftime("%B")}") if PayrollRun.this_month.any? end - - def ensure_within_max_monthly_payments - errors.add(:base, "This payroll run exceeds #{MAX_MONTHLY_PAYMENTS} payments") if payments.size > MAX_MONTHLY_PAYMENTS - end end diff --git a/spec/features/admin/admin_payroll_runs_spec.rb b/spec/features/admin/admin_payroll_runs_spec.rb index 29ba848608..997843d563 100644 --- a/spec/features/admin/admin_payroll_runs_spec.rb +++ b/spec/features/admin/admin_payroll_runs_spec.rb @@ -59,25 +59,6 @@ end end - scenario "Limiting the maximum number of claims entering payroll" do - click_on "Payroll" - - expected_claims = create_list(:claim, 3, :approved) - stubbed_max_payments = stub_const("PayrollRun::MAX_MONTHLY_PAYMENTS", 2) - - month_name = Date.today.strftime("%B") - click_on "Run #{month_name} payroll" - - expect(page).to have_content("The number of payments entering this payrun will be capped to #{stubbed_max_payments}") - - click_on "Confirm and submit" - - expect(page).to have_content("Approved claims 2") - - payroll_run = PayrollRun.order(:created_at).last - expect(payroll_run.claims).to match_array(expected_claims.first(stubbed_max_payments)) - end - scenario "Any claims approved in the meantime are not included" do click_on "Payroll" diff --git a/spec/models/payroll_run_spec.rb b/spec/models/payroll_run_spec.rb index 0e298dd1a0..18a212128c 100644 --- a/spec/models/payroll_run_spec.rb +++ b/spec/models/payroll_run_spec.rb @@ -23,35 +23,6 @@ end end - context "validating the number of payments entering payroll" do - let(:stubbed_max_payments) { 10 } - let(:payroll_run) { build(:payroll_run, :with_payments, count: payments_count) } - - before do - stub_const("PayrollRun::MAX_MONTHLY_PAYMENTS", stubbed_max_payments) - end - - context "when exceeding the number of maximum allowed payments" do - let(:payments_count) { stubbed_max_payments + 1 } - - it "returns a validation error", :aggregate_failures do - expect(payroll_run.valid?).to eq(false) - expect(payroll_run.errors[:base]).to eq(["This payroll run exceeds #{stubbed_max_payments} payments"]) - expect { payroll_run.save! }.to raise_error(ActiveRecord::RecordInvalid) - end - end - - context "when not exceeding the number of maximum allowed payments" do - let(:payments_count) { stubbed_max_payments } - - it "creates the payroll run", :aggregate_failures do - expect(payroll_run.valid?).to eq(true) - expect(payroll_run.errors[:base]).to be_empty - expect { payroll_run.save! }.to change { payroll_run.persisted? }.to(true) - end - end - end - describe "#total_award_amount" do it "returns the sum of the award amounts of its claims" do payment_1 = build(:payment, claims: [build(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 1500})]) @@ -159,19 +130,6 @@ end end - describe "#total_batches" do - subject(:total) { payroll_run.total_batches } - - let(:payroll_run) { create(:payroll_run, claims_counts: {Policies::StudentLoans => 5}) } - let(:batch_size) { 2 } - - before do - stub_const("#{described_class}::MAX_BATCH_SIZE", batch_size) - end - - it { is_expected.to eq(3) } - end - describe "#total_confirmed_payments" do subject(:total) { payroll_run.total_confirmed_payments } diff --git a/spec/requests/admin/admin_payroll_runs_spec.rb b/spec/requests/admin/admin_payroll_runs_spec.rb index ba603a0af4..b0539ecf2c 100644 --- a/spec/requests/admin/admin_payroll_runs_spec.rb +++ b/spec/requests/admin/admin_payroll_runs_spec.rb @@ -13,20 +13,6 @@ expect(response).to have_http_status(:ok) expect(response.body).to include("£100") end - - it "limits the number of claims entering payroll when exceeding the maximum allowed" do - stubbed_max_payments = stub_const("PayrollRun::MAX_MONTHLY_PAYMENTS", 2) - - create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 100}, submitted_at: 3.days.ago) - create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 50}, submitted_at: 1.days.ago) - create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 10}, submitted_at: 2.days.ago) - - get new_admin_payroll_run_path - - expect(response).to have_http_status(:ok) - expect(response.body).to include("The number of payments entering this payrun will be capped to #{stubbed_max_payments}") - expect(response.body).to include("£110") - end end describe "admin_payroll_runs#create" do