Compare commits

...

4 Commits

Author SHA1 Message Date
Rachel Arnould
7caaeffe80 Merge pull request #12206 from cyrillefr/Invoices-Several-tax-rates-are-showing-up-on-the-invoice-for-the-same-product
Fix incorrect results for multiple tax rates in report
2024-03-11 10:31:09 +01:00
cyrillefr
7d99197dde Requested changes: original fix moved up in code
- instead of selecting out unapplied tax rates in the total tax
    method, did it in the query_result instead. Reverted the
    total_excl_tax method to its initial state.
  - spec and logic of testing affected also.
2024-03-11 10:13:46 +01:00
cyrillefr
62739c0458 Requested changes in spec
- use of new service instead of manually advancing an order
2024-03-11 10:13:46 +01:00
cyrillefr
7fdf1a110d Fix incorrect results for multiple tax rates in report
- total_excl_tax would sum amounts and taxes without
    knowledge if taxes rates were really applied or not
  - spec shows use case described in issue 12066
2024-03-11 10:13:46 +01:00
2 changed files with 56 additions and 15 deletions

View File

@@ -24,9 +24,9 @@ module Reporting
# [tax_rate, supplier_id, distributor_id and order_cycle_id]
report_line_items.list
.flat_map do |line_item|
line_item.tax_rates.map do |tax_rate|
line_item.adjustments.eligible.tax.map do |tax_rate|
{
tax_rate_id: tax_rate.id,
tax_rate_id: tax_rate.originator_id,
line_item:
}
end

View File

@@ -3,7 +3,7 @@
require 'system_helper'
describe "Sales Tax Totals By Producer" do
# Scenarion 1: added tax
# Scenario 1: added tax
# 1 producer
# 1 distributor
# 1 product that costs 100$
@@ -30,6 +30,7 @@ describe "Sales Tax Totals By Producer" do
let!(:state_tax_rate){ create(:tax_rate, zone: state_zone, tax_category:) }
let!(:country_tax_rate){ create(:tax_rate, zone: country_zone, tax_category:) }
let!(:ship_address){ create(:ship_address) }
let(:another_state){ create(:state, name: 'Another state', country: ship_address.country) }
let!(:variant){ create(:variant) }
let!(:product){ variant.product }
@@ -69,9 +70,7 @@ describe "Sales Tax Totals By Producer" do
ship_address_id: ship_address.id
})
while !order.completed?
break unless order.next!
end
OrderWorkflow.new(order).complete!
end
it "generates the report" do
@@ -119,6 +118,54 @@ describe "Sales Tax Totals By Producer" do
end
end
context 'Order not to be shipped in a state affected by state tax rate' do
# Therefore, do not apply both tax rates here, only country one
before do
ship_address.update!({ state_id: another_state.id })
order.line_items.create({ variant:, quantity: 1, price: 100 })
order.update!({
order_cycle_id: order_cycle.id,
ship_address_id: ship_address.id
})
OrderWorkflow.new(order).complete!
end
it 'generates the report' do
login_as admin
visit admin_reports_path
click_on 'Sales Tax Totals By Producer'
run_report
expect(page.find("table.report__table thead tr").text).to have_content(table_header)
expect(page.find("table.report__table tbody").text).to have_content([
"Distributor",
"Yes",
"Supplier",
"Yes",
"oc1",
"tax_category",
"Country",
"2.5 %",
"100.0",
"2.5",
"102.5"
].join(" "))
expect(page.find("table.report__table tbody").text).to have_content([
"TOTAL",
"100.0",
"2.5",
"102.5"
].join(" "))
# Even though 2 tax rates exist (but only one has been applied), we should get only 2 lines:
# one line item + total
expect(page.all("table.report__table tbody tr").count).to eq(2)
end
end
context 'included tax' do
before do
state_tax_rate.update!({ included_in_price: true })
@@ -130,9 +177,7 @@ describe "Sales Tax Totals By Producer" do
ship_address_id: ship_address.id
})
while !order.completed?
break unless order.next!
end
OrderWorkflow.new(order).complete!
end
it "generates the report" do
login_as admin
@@ -308,9 +353,7 @@ describe "Sales Tax Totals By Producer" do
ship_address_id: customer1.bill_address_id,
customer_id: customer1.id
})
while !order.completed?
break unless order.next!
end
OrderWorkflow.new(order).complete!
order2.line_items.create({ variant:, quantity: 1, price: 200 })
order2.update!({
@@ -318,9 +361,7 @@ describe "Sales Tax Totals By Producer" do
ship_address_id: customer2.bill_address_id,
customer_id: customer2.id
})
while !order2.completed?
break unless order2.next!
end
OrderWorkflow.new(order2).complete!
login_as admin
visit admin_reports_path
click_on 'Sales Tax Totals By Producer'