From 541e11b5fc5bc0295d262d351b7c3ce2fdc21f21 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 8 Nov 2024 12:27:03 +0100 Subject: [PATCH 1/7] do not return tax brakdown if client facing taxes sum is 0 --- app/services/fees/apply_provider_taxes_service.rb | 3 +++ .../integrations/aggregator/taxes/base_service.rb | 11 ++++++++--- app/services/invoices/apply_provider_taxes_service.rb | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/services/fees/apply_provider_taxes_service.rb b/app/services/fees/apply_provider_taxes_service.rb index 7b4c8e11768..52aab03ceb9 100644 --- a/app/services/fees/apply_provider_taxes_service.rb +++ b/app/services/fees/apply_provider_taxes_service.rb @@ -12,6 +12,9 @@ def initialize(fee:, fee_taxes:) def call result.applied_taxes = [] return result if fee.applied_taxes.any? + # fee_taxes.tax_amount_cents represents how much the customer should pay, + # so if they should pay nothing, we don't need to create any client-facing taxes + return result if fee_taxes.tax_amount_cents.zero? applied_taxes_amount_cents = 0 applied_precise_taxes_amount_cents = 0.to_d diff --git a/app/services/integrations/aggregator/taxes/base_service.rb b/app/services/integrations/aggregator/taxes/base_service.rb index 15620fece03..9947003c22f 100644 --- a/app/services/integrations/aggregator/taxes/base_service.rb +++ b/app/services/integrations/aggregator/taxes/base_service.rb @@ -45,12 +45,14 @@ def process_response(body) if fees result.fees = fees.map do |fee| + taxes_to_pay = fee['tax_amount_cents'] + OpenStruct.new( item_id: fee['item_id'], item_code: fee['item_code'], amount_cents: fee['amount_cents'], - tax_amount_cents: fee['tax_amount_cents'], - tax_breakdown: tax_breakdown(fee['tax_breakdown']) + tax_amount_cents: taxes_to_pay, + tax_breakdown: tax_breakdown(fee['tax_breakdown'], taxes_to_pay) ) end result.succeeded_id = body['succeededInvoices'].first['id'] @@ -62,7 +64,10 @@ def process_response(body) end end - def tax_breakdown(breakdown) + def tax_breakdown(breakdown, taxes_to_pay) + # If there are no taxes to pay, we don't need to create any client-facing taxes + return [] if taxes_to_pay.zero? + breakdown.map do |b| if SPECIAL_TAXATION_TYPES.include?(b['type']) OpenStruct.new( diff --git a/app/services/invoices/apply_provider_taxes_service.rb b/app/services/invoices/apply_provider_taxes_service.rb index 32ba78a0cf6..0a4611b76fc 100644 --- a/app/services/invoices/apply_provider_taxes_service.rb +++ b/app/services/invoices/apply_provider_taxes_service.rb @@ -59,6 +59,10 @@ def applicable_taxes output = {} provider_taxes.each do |fee_taxes| + # fee_taxes.tax_amount_cents represents how much the customer should pay, + # so if they should pay nothing, we don't need to create any client-facing taxes + next if fee_taxes.tax_amount_cents.zero? + fee_taxes.tax_breakdown.each do |tax| key = calculate_key(tax) From bd13c1ab74bd85f1a6a8cb29b770013ed5b092a1 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 8 Nov 2024 13:12:25 +0100 Subject: [PATCH 2/7] fix linter, add tests --- .../fees/apply_provider_taxes_service.rb | 4 +- .../aggregator/taxes/base_service.rb | 12 +++--- .../invoices/apply_provider_taxes_service.rb | 2 +- .../success_response_seller_pays_taxes.json | 37 +++++++++++++++++++ .../fees/apply_provider_taxes_service_spec.rb | 33 ++++++++++++++++- .../invoices/create_draft_service_spec.rb | 18 +++++++++ 6 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json diff --git a/app/services/fees/apply_provider_taxes_service.rb b/app/services/fees/apply_provider_taxes_service.rb index 52aab03ceb9..45ccd0180f5 100644 --- a/app/services/fees/apply_provider_taxes_service.rb +++ b/app/services/fees/apply_provider_taxes_service.rb @@ -12,9 +12,9 @@ def initialize(fee:, fee_taxes:) def call result.applied_taxes = [] return result if fee.applied_taxes.any? - # fee_taxes.tax_amount_cents represents how much the customer should pay, + # fee_taxes.tax_breakdown would only include client-facing tax breakdowns, # so if they should pay nothing, we don't need to create any client-facing taxes - return result if fee_taxes.tax_amount_cents.zero? + return result if fee_taxes.tax_breakdown.empty? applied_taxes_amount_cents = 0 applied_precise_taxes_amount_cents = 0.to_d diff --git a/app/services/integrations/aggregator/taxes/base_service.rb b/app/services/integrations/aggregator/taxes/base_service.rb index 9947003c22f..415d0855688 100644 --- a/app/services/integrations/aggregator/taxes/base_service.rb +++ b/app/services/integrations/aggregator/taxes/base_service.rb @@ -52,7 +52,7 @@ def process_response(body) item_code: fee['item_code'], amount_cents: fee['amount_cents'], tax_amount_cents: taxes_to_pay, - tax_breakdown: tax_breakdown(fee['tax_breakdown'], taxes_to_pay) + tax_breakdown: tax_breakdown(fee['tax_breakdown'], taxes_to_pay) ) end result.succeeded_id = body['succeededInvoices'].first['id'] @@ -64,10 +64,7 @@ def process_response(body) end end - def tax_breakdown(breakdown, taxes_to_pay) - # If there are no taxes to pay, we don't need to create any client-facing taxes - return [] if taxes_to_pay.zero? - + def tax_breakdown(breakdown, taxes_to_pay) breakdown.map do |b| if SPECIAL_TAXATION_TYPES.include?(b['type']) OpenStruct.new( @@ -77,6 +74,9 @@ def tax_breakdown(breakdown, taxes_to_pay) type: b['type'] ) elsif b['rate'] + # If there are taxes, that client shouldn't pay, we don't need to show them + next if taxes_to_pay.zero? + OpenStruct.new( name: b['name'], rate: b['rate'], @@ -91,7 +91,7 @@ def tax_breakdown(breakdown, taxes_to_pay) type: b['type'] || 'unknown_taxation' ) end - end + end.compact end def retrieve_error_details(validation_error) diff --git a/app/services/invoices/apply_provider_taxes_service.rb b/app/services/invoices/apply_provider_taxes_service.rb index 0a4611b76fc..457116dca22 100644 --- a/app/services/invoices/apply_provider_taxes_service.rb +++ b/app/services/invoices/apply_provider_taxes_service.rb @@ -61,7 +61,7 @@ def applicable_taxes provider_taxes.each do |fee_taxes| # fee_taxes.tax_amount_cents represents how much the customer should pay, # so if they should pay nothing, we don't need to create any client-facing taxes - next if fee_taxes.tax_amount_cents.zero? + next if fee_taxes.tax_breakdown.empty? fee_taxes.tax_breakdown.each do |tax| key = calculate_key(tax) diff --git a/spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json b/spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json new file mode 100644 index 00000000000..4e9150aaff9 --- /dev/null +++ b/spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json @@ -0,0 +1,37 @@ +{ + "succeededInvoices": [ + { + "issuing_date": "2024-03-07", + "sub_total_excluding_taxes": 9900, + "taxes_amount_cents": 0, + "currency": "USD", + "contact": { + "external_id": "cus_lago_12345", + "name": "John Doe", + "taxable": true, + "tax_number": "1234567890" + }, + "fees": [ + { + "item_id": "lago_fee_id", + "item_code": "lago_default_b2b", + "amount_cents": 9900, + "tax_amount_cents": 0, + "tax_breakdown": [ + { + "name": "GST/HST", + "rate": "0.10", + "tax_amount": 990, + "type": "tax_exempt" + }, + { + "reason": "reverseCharge", + "type": "exempt" + } + ] + } + ] + } + ], + "failedInvoices": [] +} diff --git a/spec/services/fees/apply_provider_taxes_service_spec.rb b/spec/services/fees/apply_provider_taxes_service_spec.rb index 52031cc1d8e..31f6bd7a296 100644 --- a/spec/services/fees/apply_provider_taxes_service_spec.rb +++ b/spec/services/fees/apply_provider_taxes_service_spec.rb @@ -10,11 +10,13 @@ let(:invoice) { create(:invoice, organization:, customer:) } - let(:fee) { create(:fee, invoice:, amount_cents: 1000, precise_amount_cents: 1000.0, precise_coupons_amount_cents:) } + let(:fee) { create(:fee, invoice:, amount_cents: 1000, precise_amount_cents: 1000.0, precise_coupons_amount_cents:, + taxes_amount_cents: 0, taxes_precise_amount_cents: 0.0, taxes_rate: 0, taxes_base_rate: 0.0) } let(:precise_coupons_amount_cents) { 0 } let(:fee_taxes) do OpenStruct.new( + tax_amount_cents: 170, tax_breakdown: [ OpenStruct.new(name: 'tax 2', type: 'type2', rate: '0.12', tax_amount: 120), OpenStruct.new(name: 'tax 3', type: 'type3', rate: '0.05', tax_amount: 50) @@ -45,6 +47,7 @@ context 'when there is tax deduction' do let(:fee_taxes) do OpenStruct.new( + tax_amount_cents: 136, tax_breakdown: [ OpenStruct.new(name: 'tax 2', type: 'type2', rate: '0.12', tax_amount: 96), OpenStruct.new(name: 'tax 3', type: 'type3', rate: '0.05', tax_amount: 40) @@ -71,6 +74,33 @@ end end end + + context 'when taxes are paid by the seller' do + let(:fee_taxes) do + OpenStruct.new( + tax_amount_cents: 0, + tax_breakdown: [] + ) + end + + it 'does not create applied_taxes' do + result = apply_service.call + + aggregate_failures do + expect(result).to be_success + + applied_taxes = result.applied_taxes + expect(applied_taxes.count).to eq(0) + expect(fee).to have_attributes( + taxes_amount_cents: 0, + taxes_precise_amount_cents: 0.0, + taxes_rate: 0, + taxes_base_rate: 0.0 + ) + end + end + + end end context 'when fee already have taxes' do @@ -96,6 +126,7 @@ context "when tax provider returned specific rule applied to fees - #{applied_rule[:expected_name]}" do let(:fee_taxes) do OpenStruct.new( + tax_amount_cents: 0, tax_breakdown: [ OpenStruct.new(name: applied_rule[:expected_name], type: applied_rule[:received_type], rate: '0.00', tax_amount: 0) ] diff --git a/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb b/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb index 3c5903948dc..faa9b6c743a 100644 --- a/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb +++ b/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb @@ -172,8 +172,26 @@ end end end + + context 'when taxes are paid by seller' do + let(:body) do + path = Rails.root.join('spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json') + File.read(path) + end + + it 'returns fee object with empty tax breakdown' do + result = service_call + aggregate_failures do + expect(result).to be_success + expect(result.fees.first['tax_breakdown']).to be_empty + expect(result.fees.first['tax_amount_cents']).to eq(0) + end + end + + end end + context 'when taxes are not successfully fetched' do let(:body) do path = Rails.root.join('spec/fixtures/integration_aggregator/taxes/invoices/failure_response.json') From dc9618aea251c0116dc2139d3912adb14e8e6cb1 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 8 Nov 2024 13:26:09 +0100 Subject: [PATCH 3/7] more tests --- .../invoices/apply_provider_taxes_service.rb | 2 +- .../success_response_seller_pays_taxes.json | 4 --- .../invoices/create_draft_service_spec.rb | 1 + .../apply_provider_taxes_service_spec.rb | 30 +++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/services/invoices/apply_provider_taxes_service.rb b/app/services/invoices/apply_provider_taxes_service.rb index 457116dca22..fe9b44cebae 100644 --- a/app/services/invoices/apply_provider_taxes_service.rb +++ b/app/services/invoices/apply_provider_taxes_service.rb @@ -59,7 +59,7 @@ def applicable_taxes output = {} provider_taxes.each do |fee_taxes| - # fee_taxes.tax_amount_cents represents how much the customer should pay, + # fee_taxes.tax_breakdown would only include client-facing tax breakdowns, # so if they should pay nothing, we don't need to create any client-facing taxes next if fee_taxes.tax_breakdown.empty? diff --git a/spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json b/spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json index 4e9150aaff9..df9b7b284a6 100644 --- a/spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json +++ b/spec/fixtures/integration_aggregator/taxes/invoices/success_response_seller_pays_taxes.json @@ -23,10 +23,6 @@ "rate": "0.10", "tax_amount": 990, "type": "tax_exempt" - }, - { - "reason": "reverseCharge", - "type": "exempt" } ] } diff --git a/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb b/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb index faa9b6c743a..28c94c90a0a 100644 --- a/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb +++ b/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb @@ -137,6 +137,7 @@ context 'when special rules applied' do before do parsed_body = JSON.parse(body) + parsed_body['succeededInvoices'].first['fees'].first['tax_amount_cents'] = 0 parsed_body['succeededInvoices'].first['fees'].first['tax_breakdown'] = [ { reason: "", diff --git a/spec/services/invoices/apply_provider_taxes_service_spec.rb b/spec/services/invoices/apply_provider_taxes_service_spec.rb index bab4034cd28..dce5d5a0396 100644 --- a/spec/services/invoices/apply_provider_taxes_service_spec.rb +++ b/spec/services/invoices/apply_provider_taxes_service_spec.rb @@ -234,12 +234,14 @@ let(:fee_taxes) do [ OpenStruct.new( + tax_amount_cents: 0, tax_breakdown: [ OpenStruct.new(name: applied_rule[:expected_name], type: applied_rule[:received_type], rate: '0.00', tax_amount: 0) ] ), OpenStruct.new( + tax_amount_cents: 0, tax_breakdown: [ OpenStruct.new(name: applied_rule[:expected_name], type: applied_rule[:received_type], rate: '0.00', tax_amount: 0) @@ -282,6 +284,34 @@ end end end + + context 'with seller paying taxes' do + let(:fee_taxes) do + [ + OpenStruct.new( + tax_amount_cents: 0, + tax_breakdown: [] + ), + OpenStruct.new( + tax_amount_cents: 0, + tax_breakdown: [] + ) + ] + end + let(:fee1) { create(:fee, invoice:, amount_cents: 1000, precise_coupons_amount_cents: 0) } + let(:fee2) { create(:fee, invoice:, amount_cents: 2000, precise_coupons_amount_cents: 0) } + + it "does not create taxes" do + result = apply_service.call + + aggregate_failures do + expect(result).to be_success + + applied_taxes = result.applied_taxes + expect(applied_taxes.count).to eq(0) + end + end + end end end From cfc331480d011bb3e00518150b0690bc1d80870a Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 8 Nov 2024 14:12:57 +0100 Subject: [PATCH 4/7] fix linter --- .../aggregator/taxes/base_service.rb | 2 +- .../fees/apply_provider_taxes_service_spec.rb | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/services/integrations/aggregator/taxes/base_service.rb b/app/services/integrations/aggregator/taxes/base_service.rb index 415d0855688..2c3adfc2108 100644 --- a/app/services/integrations/aggregator/taxes/base_service.rb +++ b/app/services/integrations/aggregator/taxes/base_service.rb @@ -74,7 +74,7 @@ def tax_breakdown(breakdown, taxes_to_pay) type: b['type'] ) elsif b['rate'] - # If there are taxes, that client shouldn't pay, we don't need to show them + # If there are taxes, that client shouldn't pay, we don't need to show them next if taxes_to_pay.zero? OpenStruct.new( diff --git a/spec/services/fees/apply_provider_taxes_service_spec.rb b/spec/services/fees/apply_provider_taxes_service_spec.rb index 31f6bd7a296..6fc223a3867 100644 --- a/spec/services/fees/apply_provider_taxes_service_spec.rb +++ b/spec/services/fees/apply_provider_taxes_service_spec.rb @@ -10,8 +10,10 @@ let(:invoice) { create(:invoice, organization:, customer:) } - let(:fee) { create(:fee, invoice:, amount_cents: 1000, precise_amount_cents: 1000.0, precise_coupons_amount_cents:, - taxes_amount_cents: 0, taxes_precise_amount_cents: 0.0, taxes_rate: 0, taxes_base_rate: 0.0) } + let(:fee) do + create(:fee, invoice:, amount_cents: 1000, precise_amount_cents: 1000.0, precise_coupons_amount_cents:, + taxes_amount_cents: 0, taxes_precise_amount_cents: 0.0, taxes_rate: 0, taxes_base_rate: 0.0) + end let(:precise_coupons_amount_cents) { 0 } let(:fee_taxes) do @@ -78,8 +80,8 @@ context 'when taxes are paid by the seller' do let(:fee_taxes) do OpenStruct.new( - tax_amount_cents: 0, - tax_breakdown: [] + tax_amount_cents: 0, + tax_breakdown: [] ) end @@ -92,14 +94,13 @@ applied_taxes = result.applied_taxes expect(applied_taxes.count).to eq(0) expect(fee).to have_attributes( - taxes_amount_cents: 0, - taxes_precise_amount_cents: 0.0, - taxes_rate: 0, - taxes_base_rate: 0.0 - ) + taxes_amount_cents: 0, + taxes_precise_amount_cents: 0.0, + taxes_rate: 0, + taxes_base_rate: 0.0 + ) end end - end end From 812d44e0ab9f76f8ac76b81826996e29e611cfd6 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 8 Nov 2024 14:17:36 +0100 Subject: [PATCH 5/7] other linter fixes --- .../aggregator/taxes/invoices/create_draft_service_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb b/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb index 28c94c90a0a..898144ef68a 100644 --- a/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb +++ b/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb @@ -188,11 +188,9 @@ expect(result.fees.first['tax_amount_cents']).to eq(0) end end - end end - context 'when taxes are not successfully fetched' do let(:body) do path = Rails.root.join('spec/fixtures/integration_aggregator/taxes/invoices/failure_response.json') From 11250c0dc105eb7526c332a79a914ef1bffadb4a Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 8 Nov 2024 15:25:09 +0100 Subject: [PATCH 6/7] instead of skipping tax breakdown when there are no taxes, create zero-tax --- .../fees/apply_provider_taxes_service.rb | 3 -- .../aggregator/taxes/base_service.rb | 27 ++++++++++------- .../invoices/apply_provider_taxes_service.rb | 4 --- .../fees/apply_provider_taxes_service_spec.rb | 7 ++--- .../invoices/create_draft_service_spec.rb | 6 ++-- .../apply_provider_taxes_service_spec.rb | 29 ++++++++++++++++--- 6 files changed, 49 insertions(+), 27 deletions(-) diff --git a/app/services/fees/apply_provider_taxes_service.rb b/app/services/fees/apply_provider_taxes_service.rb index 45ccd0180f5..7b4c8e11768 100644 --- a/app/services/fees/apply_provider_taxes_service.rb +++ b/app/services/fees/apply_provider_taxes_service.rb @@ -12,9 +12,6 @@ def initialize(fee:, fee_taxes:) def call result.applied_taxes = [] return result if fee.applied_taxes.any? - # fee_taxes.tax_breakdown would only include client-facing tax breakdowns, - # so if they should pay nothing, we don't need to create any client-facing taxes - return result if fee_taxes.tax_breakdown.empty? applied_taxes_amount_cents = 0 applied_precise_taxes_amount_cents = 0.to_d diff --git a/app/services/integrations/aggregator/taxes/base_service.rb b/app/services/integrations/aggregator/taxes/base_service.rb index 2c3adfc2108..4158720f741 100644 --- a/app/services/integrations/aggregator/taxes/base_service.rb +++ b/app/services/integrations/aggregator/taxes/base_service.rb @@ -74,15 +74,22 @@ def tax_breakdown(breakdown, taxes_to_pay) type: b['type'] ) elsif b['rate'] - # If there are taxes, that client shouldn't pay, we don't need to show them - next if taxes_to_pay.zero? - - OpenStruct.new( - name: b['name'], - rate: b['rate'], - tax_amount: b['tax_amount'], - type: b['type'] - ) + # If there are taxes, that client shouldn't pay, we nullify the taxes + if taxes_to_pay.zero? + OpenStruct.new( + name: 'Tax', + rate: '0.00', + tax_amount: 0, + type: 'tax' + ) + else + OpenStruct.new( + name: b['name'], + rate: b['rate'], + tax_amount: b['tax_amount'], + type: b['type'] + ) + end else OpenStruct.new( name: humanize_tax_name(b['reason'].presence || b['type'] || 'unknown_taxation'), @@ -91,7 +98,7 @@ def tax_breakdown(breakdown, taxes_to_pay) type: b['type'] || 'unknown_taxation' ) end - end.compact + end end def retrieve_error_details(validation_error) diff --git a/app/services/invoices/apply_provider_taxes_service.rb b/app/services/invoices/apply_provider_taxes_service.rb index fe9b44cebae..32ba78a0cf6 100644 --- a/app/services/invoices/apply_provider_taxes_service.rb +++ b/app/services/invoices/apply_provider_taxes_service.rb @@ -59,10 +59,6 @@ def applicable_taxes output = {} provider_taxes.each do |fee_taxes| - # fee_taxes.tax_breakdown would only include client-facing tax breakdowns, - # so if they should pay nothing, we don't need to create any client-facing taxes - next if fee_taxes.tax_breakdown.empty? - fee_taxes.tax_breakdown.each do |tax| key = calculate_key(tax) diff --git a/spec/services/fees/apply_provider_taxes_service_spec.rb b/spec/services/fees/apply_provider_taxes_service_spec.rb index 6fc223a3867..201a55b6b6b 100644 --- a/spec/services/fees/apply_provider_taxes_service_spec.rb +++ b/spec/services/fees/apply_provider_taxes_service_spec.rb @@ -81,7 +81,7 @@ let(:fee_taxes) do OpenStruct.new( tax_amount_cents: 0, - tax_breakdown: [] + tax_breakdown: [ OpenStruct.new(name: 'Tax', type: 'tax', rate: '0.00', tax_amount: 0) ] ) end @@ -92,12 +92,11 @@ expect(result).to be_success applied_taxes = result.applied_taxes - expect(applied_taxes.count).to eq(0) + expect(applied_taxes.count).to eq(1) expect(fee).to have_attributes( taxes_amount_cents: 0, taxes_precise_amount_cents: 0.0, - taxes_rate: 0, - taxes_base_rate: 0.0 + taxes_rate: 0 ) end end diff --git a/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb b/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb index 898144ef68a..8d9cd22ca15 100644 --- a/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb +++ b/spec/services/integrations/aggregator/taxes/invoices/create_draft_service_spec.rb @@ -184,8 +184,10 @@ result = service_call aggregate_failures do expect(result).to be_success - expect(result.fees.first['tax_breakdown']).to be_empty - expect(result.fees.first['tax_amount_cents']).to eq(0) + expect(result.fees.first['tax_breakdown'].last['name']).to eq('Tax') + expect(result.fees.first['tax_breakdown'].last['type']).to eq('tax') + expect(result.fees.first['tax_breakdown'].last['rate']).to eq('0.00') + expect(result.fees.first['tax_breakdown'].last['tax_amount']).to eq(0) end end end diff --git a/spec/services/invoices/apply_provider_taxes_service_spec.rb b/spec/services/invoices/apply_provider_taxes_service_spec.rb index dce5d5a0396..369feb5bb0e 100644 --- a/spec/services/invoices/apply_provider_taxes_service_spec.rb +++ b/spec/services/invoices/apply_provider_taxes_service_spec.rb @@ -290,25 +290,46 @@ [ OpenStruct.new( tax_amount_cents: 0, - tax_breakdown: [] + tax_breakdown: [OpenStruct.new(name: 'Tax', type: 'tax', rate: '0.00', tax_amount: 0)] ), OpenStruct.new( tax_amount_cents: 0, - tax_breakdown: [] + tax_breakdown: [OpenStruct.new(name: 'Tax', type: 'tax', rate: '0.00', tax_amount: 0)] ) ] end let(:fee1) { create(:fee, invoice:, amount_cents: 1000, precise_coupons_amount_cents: 0) } let(:fee2) { create(:fee, invoice:, amount_cents: 2000, precise_coupons_amount_cents: 0) } + let(:fee1_applied_tax) do + create(:fee_applied_tax, fee: fee1, amount_cents: 0, tax_name: 'Tax', tax_code: 'tax', tax_rate: 0.0, tax_description: 'tax') + end + let(:fee2_applied_tax) do + create(:fee_applied_tax, fee: fee2, amount_cents: 0, tax_name: 'Tax', tax_code: 'tax', tax_rate: 0.0, tax_description: 'tax') + end + + before do + fee1_applied_tax + fee2_applied_tax + end - it "does not create taxes" do + it "does creates zero-tax" do result = apply_service.call aggregate_failures do expect(result).to be_success applied_taxes = result.applied_taxes - expect(applied_taxes.count).to eq(0) + expect(applied_taxes.count).to eq(1) + expect(applied_taxes.find { |item| item.tax_code == 'tax' }).to have_attributes( + invoice:, + tax_description: 'tax', + tax_code: 'tax', + tax_name: 'Tax', + tax_rate: 0, + amount_currency: invoice.currency, + amount_cents: 0, + fees_amount_cents: 3000 + ) end end end From b6d7564bedd96db797c6f52b1c1de6c8e8bcc004 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Fri, 8 Nov 2024 15:28:54 +0100 Subject: [PATCH 7/7] fix linter --- spec/services/fees/apply_provider_taxes_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/fees/apply_provider_taxes_service_spec.rb b/spec/services/fees/apply_provider_taxes_service_spec.rb index 201a55b6b6b..bf006a25cf0 100644 --- a/spec/services/fees/apply_provider_taxes_service_spec.rb +++ b/spec/services/fees/apply_provider_taxes_service_spec.rb @@ -81,7 +81,7 @@ let(:fee_taxes) do OpenStruct.new( tax_amount_cents: 0, - tax_breakdown: [ OpenStruct.new(name: 'Tax', type: 'tax', rate: '0.00', tax_amount: 0) ] + tax_breakdown: [OpenStruct.new(name: 'Tax', type: 'tax', rate: '0.00', tax_amount: 0)] ) end