Skip to content

Commit

Permalink
bug - Fix check for invoice.closed? in `Invoices::AdvanceChargesServi…
Browse files Browse the repository at this point in the history
…ce` (#2572)

## Description

This check returns true if the invoice is nil, this is not intended.
  • Loading branch information
nudded authored Sep 12, 2024
1 parent 36110b5 commit 4f2c57c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 3 additions & 4 deletions app/services/invoices/advance_charges_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call

invoice = create_group_invoice

unless invoice&.closed?
if invoice && !invoice.closed?
SendWebhookJob.perform_later('invoice.created', invoice)
Invoices::GeneratePdfAndNotifyJob.perform_later(invoice:, email: false)
Integrations::Aggregator::Invoices::CreateJob.perform_later(invoice:) if invoice.should_sync_invoice?
Expand Down Expand Up @@ -55,9 +55,8 @@ def create_group_invoice
end

if invoice.fees.empty?
invoice.invoice_subscriptions.destroy_all
invoice.destroy!
return nil
invoice = nil
raise ActiveRecord::Rollback
end

Invoices::ComputeAmountsFromFees.call(invoice:)
Expand Down
13 changes: 13 additions & 0 deletions spec/services/invoices/advance_charges_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ def fee_boundaries
expect(result).to be_success
expect(result.invoice).to be_nil
end

context "when there is a pay in advance charge" do
before do
create(:standard_charge, :regroup_paid_fees, plan: subscription.plan)
end

it 'does not create an invoice' do
result = invoice_service.call

expect(result).to be_success
expect(result.invoice).to be_nil
end
end
end

context 'with integration requiring sync' do
Expand Down

0 comments on commit 4f2c57c

Please sign in to comment.