Skip to content

Commit

Permalink
13008: add tax category in all products report
Browse files Browse the repository at this point in the history
  • Loading branch information
chahmedejaz committed Dec 3, 2024
1 parent de938f6 commit 8da296d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
9 changes: 8 additions & 1 deletion lib/reporting/reports/products_and_inventory/all_products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +25,8 @@ def columns
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
Expand Down
22 changes: 17 additions & 5 deletions spec/lib/reports/products_and_inventory_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ module ProductsAndInventory
"Amount",
"SKU",
"On Demand?",
"On Hand"
"On Hand",
"Tax Category"
])
end

Expand All @@ -293,8 +294,8 @@ module ProductsAndInventory
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")
Expand All @@ -306,12 +307,23 @@ module ProductsAndInventory
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
Expand Down

0 comments on commit 8da296d

Please sign in to comment.