Merge pull request #13018 from chahmedejaz/task/13008-add-tax-category-in-all-products-report

Add 'tax category' to the All Products report
This commit is contained in:
Filipe
2024-12-09 16:21:01 -06:00
committed by GitHub
2 changed files with 25 additions and 6 deletions

View File

@@ -4,6 +4,12 @@ module Reporting
module Reports
module ProductsAndInventory
class AllProducts < Base
def default_params
{
fields_to_hide: [:tax_category]
}
end
def message
I18n.t("spree.admin.reports.products_and_inventory.all_products.message")
end
@@ -19,7 +25,8 @@ module Reporting
super.merge(
{
on_demand: proc{ |variant| variant.on_demand },
on_hand: proc{ |variant| variant.on_demand ? I18n.t(:on_demand) : variant.on_hand }
on_hand: proc{ |variant| variant.on_demand ? I18n.t(:on_demand) : variant.on_hand },
tax_category: proc { |variant| variant.tax_category_id && variant.tax_category.name }
}
)
end

View File

@@ -283,7 +283,8 @@ module Reporting
"Amount",
"SKU",
"On Demand?",
"On Hand"
"On Hand",
"Tax Category"
])
end
@@ -293,8 +294,8 @@ module Reporting
variant.save!
last_row = report.table_rows.last
on_demand_column = last_row[-2]
on_hand_column = last_row[-1]
on_demand_column = last_row[-3]
on_hand_column = last_row[-2]
expect(on_demand_column).to eq("Yes")
expect(on_hand_column).to eq("On demand")
@@ -306,12 +307,23 @@ module Reporting
variant.save!
last_row = report.table_rows.last
on_demand_column = last_row[-2]
on_hand_column = last_row[-1]
on_demand_column = last_row[-3]
on_hand_column = last_row[-2]
expect(on_demand_column).to eq("No")
expect(on_hand_column).to eq(22)
end
it "renders tax category if present, otherwise none" do
variant.update!(tax_category: create(:tax_category, name: 'Test Category'))
table_rows = report.table_rows
first_row = table_rows.first # row for default variant, as result of product creation
last_row = table_rows.last # row for the variant created/updated above
expect(first_row.last).to eq('none')
expect(last_row.last).to eq('Test Category')
end
end
end
end