From c331d57cdb383d62e1a08aa03b66edfc3164f274 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Wed, 4 Dec 2024 03:36:42 +0500 Subject: [PATCH] 13008: add tax category in all products report --- .../products_and_inventory/all_products.rb | 9 +++++++- .../products_and_inventory_report_spec.rb | 22 ++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/reporting/reports/products_and_inventory/all_products.rb b/lib/reporting/reports/products_and_inventory/all_products.rb index 2471e4c6731..0d71b99d25b 100644 --- a/lib/reporting/reports/products_and_inventory/all_products.rb +++ b/lib/reporting/reports/products_and_inventory/all_products.rb @@ -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 @@ 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 diff --git a/spec/lib/reports/products_and_inventory_report_spec.rb b/spec/lib/reports/products_and_inventory_report_spec.rb index 19a7024bb17..4962220a941 100644 --- a/spec/lib/reports/products_and_inventory_report_spec.rb +++ b/spec/lib/reports/products_and_inventory_report_spec.rb @@ -283,7 +283,8 @@ module ProductsAndInventory "Amount", "SKU", "On Demand?", - "On Hand" + "On Hand", + "Tax Category" ]) end @@ -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") @@ -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