Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'tax category' to the All Products report #13018

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tax_category returns the default TaxCategory if the variant doesn't have one.
That's why we need to ensure that this tax category value maps to the variant's assigned tax category, rather than the default one.
This is the whole purpose of the addition of this field in the report.

}
)
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
Loading