Merge pull request #13037 from chahmedejaz/task/13013-add-columns-supplier-report

Add columns to "pay your supplier" report
This commit is contained in:
Filipe
2025-02-07 10:04:52 -06:00
committed by GitHub
6 changed files with 42 additions and 16 deletions

View File

@@ -3320,6 +3320,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
report_header_item_fees_price: "Item + Fees (%{currency})"
report_header_admin_handling_fees: "Admin & Handling (%{currency})"
report_header_ship_price: "Ship (%{currency})"
report_header_producer_charges_gst: Producer charges GST?
report_header_total_tax_on_product: "Total tax on product (%{currency})"
report_header_pay_fee_price: "Pay fee (%{currency})"
report_header_total_price: "Total (%{currency})"
report_header_product_total_price: "Product Total (%{currency})"

View File

@@ -28,6 +28,7 @@ module Reporting
producer:,
producer_address:,
producer_abn_acn:,
producer_charges_gst:,
email:,
hub:,
hub_address:,
@@ -43,6 +44,7 @@ module Reporting
total_excl_fees_and_tax:,
total_excl_vat:,
total_fees_excl_tax:,
total_tax_on_product:,
total_tax_on_fees:,
total_tax:,
total:,
@@ -64,6 +66,7 @@ module Reporting
summary_hash[:total_tax_on_fees] += total_tax_on_fees.call(line_item)
summary_hash[:total_tax] += total_tax.call(line_item)
summary_hash[:total] += total.call(line_item)
summary_hash[:total_tax_on_product] += total_tax_on_product.call(line_item)
end
summary_hash

View File

@@ -23,6 +23,12 @@ module Reporting
end
end
def producer_charges_gst
proc do |line_items|
supplier(line_items).charges_sales_tax
end
end
def email
proc { |line_item| supplier(line_item).email_address }
end
@@ -80,8 +86,7 @@ module Reporting
def total_excl_vat
proc do |line_item|
total_fees = adjustments_by_type(line_item, :fees)
total_excl_fees_and_tax.call(line_item) + total_fees
total_excl_fees_and_tax.call(line_item) + total_fees_excl_tax.call(line_item)
end
end
@@ -92,11 +97,7 @@ module Reporting
end
end
def total_tax_on_fees
proc { |line_item| tax_on_fees(line_item) + tax_on_fees(line_item, included: true) }
end
def total_tax
def total_tax_on_product
proc do |line_item|
excluded_tax = adjustments_by_type(line_item, :tax)
included_tax = adjustments_by_type(line_item, :tax, included: true)
@@ -105,14 +106,19 @@ module Reporting
end
end
def total_tax_on_fees
proc { |line_item| tax_on_fees(line_item) + tax_on_fees(line_item, included: true) }
end
def total_tax
proc do |line_item|
total_tax_on_product.call(line_item) + total_tax_on_fees.call(line_item)
end
end
def total
proc do |line_item|
total_price = total_excl_fees_and_tax.call(line_item)
total_fees = total_fees_excl_tax.call(line_item)
total_fees_tax = total_tax_on_fees.call(line_item)
tax = total_tax.call(line_item)
total_price + total_fees + total_fees_tax + tax
total_excl_vat.call(line_item) + total_tax.call(line_item)
end
end
end

View File

@@ -38,8 +38,11 @@ module Reporting
end
def adjustments_by_type(line_item, type, included: false)
is_tax = type == :tax
return 0.0 if is_tax && !supplier(line_item).charges_sales_tax
total_amount = 0.0
adjustment_type = type == :tax ? 'Spree::TaxRate' : 'EnterpriseFee'
adjustment_type = is_tax ? 'Spree::TaxRate' : 'EnterpriseFee'
suppliers_adjustments(line_item, adjustment_type).each do |adjustment|
amount = included == adjustment.included ? adjustment.amount : 0.0
total_amount += amount
@@ -49,6 +52,8 @@ module Reporting
end
def tax_on_fees(line_item, included: false)
return 0.0 unless supplier(line_item).charges_sales_tax
total_amount = 0.0
suppliers_adjustments(line_item).each do |adjustment|
adjustment.adjustments.tax.each do |fee_adjustment|

View File

@@ -24,6 +24,7 @@ RSpec.describe "Pay Your Suppliers Report" do
expect(table_row.producer).to eq(supplier.name)
expect(table_row.producer_address).to eq(supplier.address.full_address)
expect(table_row.producer_abn_acn).to eq("none")
expect(table_row.producer_charges_gst).to eq("No")
expect(table_row.email).to eq("none")
expect(table_row.hub).to eq(hub.name)
expect(table_row.hub_address).to eq(hub.address.full_address)
@@ -42,6 +43,7 @@ RSpec.describe "Pay Your Suppliers Report" do
expect(table_row.total_excl_vat.to_f).to eq(10.0)
expect(table_row.total_fees_excl_tax.to_f).to eq(0.0)
expect(table_row.total_tax_on_fees.to_f).to eq(0.0)
expect(table_row.total_tax_on_product.to_f).to eq(0.0)
expect(table_row.total_tax.to_f).to eq(0.0)
expect(table_row.total.to_f).to eq(10.0)
end
@@ -94,11 +96,13 @@ RSpec.describe "Pay Your Suppliers Report" do
expect(report_table_rows.length).to eq(1)
table_row = report_table_rows.first
expect(table_row.producer_charges_gst).to eq('Yes')
expect(table_row.total_excl_fees_and_tax.to_f).to eq(10.0)
expect(table_row.total_excl_vat.to_f).to eq(10.1)
expect(table_row.total_fees_excl_tax.to_f).to eq(0.1)
expect(table_row.total_tax_on_fees.to_f).to eq(0.01)
expect(table_row.total_tax.to_f).to eq(1.0)
expect(table_row.total_tax_on_product.to_f).to eq(1.0)
expect(table_row.total_tax.to_f).to eq(1.01)
expect(table_row.total.to_f).to eq(11.11)
end
end

View File

@@ -48,6 +48,7 @@ RSpec.describe "Pay Your Suppliers Report" do
"Producer",
"Producer Address",
"Producer ABN/ACN",
"Producer charges GST?",
"Email",
"Hub",
"Hub Address",
@@ -63,6 +64,7 @@ RSpec.describe "Pay Your Suppliers Report" do
"Total excl. fees and tax ($)",
"Total excl. tax ($)",
"Total fees excl. tax ($)",
"Total tax on product ($)",
"Total tax on fees ($)",
"Total Tax ($)",
"Total ($)"
@@ -83,6 +85,7 @@ RSpec.describe "Pay Your Suppliers Report" do
supplier.name,
supplier.address.full_address,
"none",
"No",
"none",
hub1.name,
hub1.address.full_address,
@@ -100,6 +103,7 @@ RSpec.describe "Pay Your Suppliers Report" do
0.0,
0.0,
0.0,
0.0,
10.0,
].compact.join(" "))
end
@@ -115,6 +119,7 @@ RSpec.describe "Pay Your Suppliers Report" do
supplier.name,
supplier.address.full_address,
"none",
"No",
"none",
hub2.name,
hub2.address.full_address,
@@ -132,12 +137,13 @@ RSpec.describe "Pay Your Suppliers Report" do
0.0,
0.0,
0.0,
0.0,
10.0,
].compact.join(" "))
end
# summary row
expect(lines.last).to have_content("TOTAL 50.0 50.0 0.0 0.0 0.0 50.0")
expect(lines.last).to have_content("TOTAL 50.0 50.0 0.0 0.0 0.0 0.0 50.0")
end
end