fix reported issues:

- wrong enterprise fees
- always 0 tax on fees
This commit is contained in:
Ahmed Ejaz
2024-11-01 20:13:06 +05:00
committed by Rachel Arnould
parent ed559b5257
commit 298c0e8d7f
3 changed files with 37 additions and 10 deletions

View File

@@ -109,9 +109,10 @@ module Reporting
proc do |line_item|
total_price = total_excl_vat_and_fees.call(line_item)
total_fees = total_fees_excl_vat.call(line_item)
total_fees_tax = total_vat_on_fees.call(line_item)
tax = total_tax.call(line_item)
total_price + total_fees + tax
total_price + total_fees + total_fees_tax + tax
end
end
end

View File

@@ -25,11 +25,22 @@ module Reporting
line_item.order_cycle
end
def suppliers_adjustments(line_item, adjustment_type = 'EnterpriseFee')
adjustments = line_item.adjustments
return adjustments if adjustment_type == 'Spree::TaxRate'
supplier_name = supplier(line_item).name
adjustments.select do |adjustment|
label = adjustment.label
label.include?('supplier') && label.include?(supplier_name)
end
end
def adjustments_by_type(line_item, type, included: false)
total_amount = 0.0
adjustment_type = type == :tax ? 'Spree::TaxRate' : 'EnterpriseFee'
adjustments = line_item.adjustments
adjustments.each do |adjustment|
suppliers_adjustments(line_item, adjustment_type).each do |adjustment|
if adjustment.originator_type == adjustment_type
amount = included == adjustment.included ? adjustment.amount : 0.0
total_amount += amount
@@ -41,13 +52,11 @@ module Reporting
def tax_on_fees(line_item, included: false)
total_amount = 0.0
adjustments = line_item.adjustments
adjustments.each do |adjustment|
suppliers_adjustments(line_item).each do |adjustment|
next unless adjustment.originator_type == 'EnterpriseFee'
adjustment.adjustments.each do |fee_adjustment|
next unless adjustment.originator_type == 'Spree::TaxRate'
next unless fee_adjustment.originator_type == 'Spree::TaxRate'
amount = included == fee_adjustment.included ? fee_adjustment.amount : 0.0
total_amount += amount

View File

@@ -49,12 +49,29 @@ RSpec.describe "Pay Your Suppliers Report" do
context "with taxes and fees" do
let(:line_item) { order.line_items.first }
let!(:enterprise_fee) do
create(:enterprise_fee, enterprise: supplier, inherits_tax_category: true, fee_type: 'sales')
end
let!(:fees_adjustment) do
create(:adjustment, originator_type: "EnterpriseFee", adjustable: line_item, amount: 0.1)
create(
:adjustment,
originator: enterprise_fee,
adjustable: line_item,
amount: 0.1,
label: "#{enterprise_fee.name} fee by supplier #{supplier.name}",
)
end
let!(:tax_adjustment) do
create(:adjustment, originator_type: "Spree::TaxRate", adjustable: line_item, amount: 0.1)
end
let!(:tax_on_fee) do
create(
:adjustment,
originator_type: "Spree::TaxRate",
adjustable: fees_adjustment,
amount: 0.01
)
end
it "Generates the report" do
expect(report_table_rows.length).to eq(1)
@@ -63,9 +80,9 @@ RSpec.describe "Pay Your Suppliers Report" do
expect(table_row.total_excl_vat_and_fees.to_f).to eq(10.0)
expect(table_row.total_excl_vat.to_f).to eq(10.1)
expect(table_row.total_fees_excl_vat.to_f).to eq(0.1)
expect(table_row.total_vat_on_fees.to_f).to eq(0.0)
expect(table_row.total_vat_on_fees.to_f).to eq(0.01)
expect(table_row.total_tax.to_f).to eq(0.1)
expect(table_row.total.to_f).to eq(10.2)
expect(table_row.total.to_f).to eq(10.21)
end
end
end