Skip to content

Commit

Permalink
fix: update regrouped invoice pdf with percentage details on fees (#2941
Browse files Browse the repository at this point in the history
)

## Context

When charge has filters, fee details are not displayed for percentage
charge model in the invoice PDF

## Description

This PR ensures that fee details are properly displayed in the invoice
PDF
  • Loading branch information
lovrocolic authored Dec 12, 2024
1 parent 5c0b397 commit a32a07a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 21 deletions.
6 changes: 0 additions & 6 deletions app/models/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ def supports_grouped_by?
standard? || dynamic?
end

def basic_rate_percentage?
return false unless percentage?

properties.keys == ['rate']
end

def equal_properties?(charge)
charge_model == charge.charge_model && properties == charge.properties
end
Expand Down
11 changes: 11 additions & 0 deletions app/models/fee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ def currency
amount_currency
end

def basic_rate_percentage?
return false unless charge?
return false unless charge.percentage?

if charge_filter
charge_filter.properties.keys == ['rate']
else
charge.properties.keys == ['rate']
end
end

def sub_total_excluding_taxes_amount_cents
amount_cents - precise_coupons_amount_cents
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/templates/invoices/v4/charge.slim
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ html
- fees.order(:succeeded_at, :created_at).each do |fee|
tr
- if fee.charge.percentage? && fee.amount_details.present?
- if fee.charge.basic_rate_percentage?
- if fee.basic_rate_percentage?
tr
td.body-1
= fee.invoice_name + FeeDisplayHelper.grouped_by_display(fee)
Expand Down
14 changes: 0 additions & 14 deletions spec/models/charge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,20 +546,6 @@
end
end

describe '#basic_rate_percentage?' do
it 'returns false if charge model is not percentage' do
expect(build(:standard_charge)).not_to be_basic_rate_percentage
end

it 'returns false if charge model is percentage but has other properties except rate' do
expect(build(:charge, charge_model: 'percentage', properties: {fixed_amount: '20'})).not_to be_basic_rate_percentage
end

it 'returns true only if properties of percentage charge contain only rate' do
expect(build(:charge, charge_model: 'percentage', properties: {rate: '0.20'})).to be_basic_rate_percentage
end
end

describe '#equal_properties?' do
let(:charge1) { build(:standard_charge, properties: {amount: 100}) }

Expand Down
47 changes: 47 additions & 0 deletions spec/models/fee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,51 @@
end
end
end

describe '#basic_rate_percentage?' do
let(:fee) { create(:fee, fee_type: :charge, charge:, amount_cents: 1000, total_aggregated_units: 1) }
let(:charge) { create(:standard_charge) }

it 'returns false if charge model is not percentage' do
expect(fee).not_to be_basic_rate_percentage
end

context 'when charge model is percentage but has other properties except rate' do
let(:charge) { create(:charge, charge_model: 'percentage', properties: {rate: '0', fixed_amount: '20'}) }

it 'returns false' do
expect(fee).not_to be_basic_rate_percentage
end
end

context 'when properties of percentage charge contain only rate' do
let(:charge) { create(:charge, charge_model: 'percentage', properties: {rate: '0'}) }

it 'returns true' do
expect(fee).to be_basic_rate_percentage
end
end

context 'when charge is percentage and there are charge filters' do
let(:charge) { create(:charge, charge_model: 'percentage', properties: {rate: '0'}) }

before { fee.update!(charge_filter:) }

context 'when filter has other properties except rate' do
let(:charge_filter) { create(:charge_filter, charge:, properties: {rate: '0', fixed_amount: '20'}) }

it 'returns false' do
expect(fee).not_to be_basic_rate_percentage
end
end

context 'when filter properties contain only rate' do
let(:charge_filter) { create(:charge_filter, charge:, properties: {rate: '0'}) }

it 'returns true' do
expect(fee).to be_basic_rate_percentage
end
end
end
end
end

0 comments on commit a32a07a

Please sign in to comment.