From 86c25e1d48045d4c93238d52011fece6d7373ee7 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 23 Nov 2022 12:12:07 +0100 Subject: [PATCH 1/4] add on_demand/on_hand columns to all products_and_inventory/all_products report --- config/locales/en.yml | 3 +++ .../products_and_inventory/all_products.rb | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 9c38d6b867..5ba6475874 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4080,6 +4080,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using select_and_search: "Select filters and click on %{option} to access your data." customer_names_message: customer_names_tip: "If customer names are hidden for orders you have supplied, you can contact the distributor and ask if they can update their shop preferences to allow their suppliers to view customer names." + products_and_inventory: + all_products: + message: "Note that stock levels reported are from supplier product lists only. If you are using Inventory to manage your stock quantities these values will be ignored in this report." users: index: listing_users: "Listing Users" diff --git a/lib/reporting/reports/products_and_inventory/all_products.rb b/lib/reporting/reports/products_and_inventory/all_products.rb index f433f83287..8ec06fded7 100644 --- a/lib/reporting/reports/products_and_inventory/all_products.rb +++ b/lib/reporting/reports/products_and_inventory/all_products.rb @@ -4,6 +4,30 @@ module Reporting module Reports module ProductsAndInventory class AllProducts < Base + def default_params + { fields_to_hide: [:on_demand, :on_hand] } + end + + def message + I18n.t("spree.admin.reports.products_and_inventory.all_products.message") + end + + def custom_headers + { + on_demand: I18n.t("admin.on_demand?"), + on_hand: I18n.t("admin.on_hand") + } + end + + 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 } + } + ) + end + def filter_on_hand(variants) variants # do not filter end From 11ea6b39cfb6bba0fbac45f1330e61712abed786 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 24 Nov 2022 09:18:45 +0100 Subject: [PATCH 2/4] test if All products report returns on_hand and on_demand --- .../products_and_inventory_report_spec.rb | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/spec/lib/reports/products_and_inventory_report_spec.rb b/spec/lib/reports/products_and_inventory_report_spec.rb index 87739af47e..39b9cfb3a2 100644 --- a/spec/lib/reports/products_and_inventory_report_spec.rb +++ b/spec/lib/reports/products_and_inventory_report_spec.rb @@ -266,6 +266,64 @@ module Reporting end end end + + describe AllProducts do + let(:user) do + user = create(:user) + user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin') + user + end + let(:report) do + AllProducts.new user, { fields_to_hide: [] } + end + + it "Should return headers" do + expect(report.table_headers).to eq([ + "Supplier", + "Producer Suburb", + "Product", + "Product Properties", + "Taxons", + "Variant Value", + "Price", + "Group Buy Unit Quantity", + "Amount", + "SKU", + "On Demand?", + "On Hand" + ]) + end + + it "Should render 'On demand' when the product is available on demand" do + product = create(:product) + variant = product.variants.first + variant.on_demand = true + variant.on_hand = 15 + variant.save! + + first_row = report.table_rows.first + on_demand_column = first_row[-2] + on_hand_column = first_row[-1] + + expect(on_demand_column).to eq("Yes") + expect(on_hand_column).to eq("On demand") + end + + it "Should render the on hand count when the product is not available on demand" do + product = create(:product) + variant = product.variants.first + variant.on_demand = false + variant.on_hand = 22 + variant.save! + + first_row = report.table_rows.first + on_demand_column = first_row[-2] + on_hand_column = first_row[-1] + + expect(on_demand_column).to eq("No") + expect(on_hand_column).to eq(22) + end + end end end end From 155b8ed7258983b9c02bc28244439427e3fd3bdd Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 21 Dec 2022 07:09:39 +0100 Subject: [PATCH 3/4] subtract fields_to_hide when the fields_to_show are calculated --- lib/reporting/report_headers_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/reporting/report_headers_builder.rb b/lib/reporting/report_headers_builder.rb index 29291ac56b..971e90700b 100644 --- a/lib/reporting/report_headers_builder.rb +++ b/lib/reporting/report_headers_builder.rb @@ -36,7 +36,7 @@ module Reporting else [] end - params_fields_to_show - fields_in_headers + params_fields_to_show - fields_in_headers - fields_to_hide end private From 0d0c568b1051c277da3627f3374bbd680892e188 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 21 Dec 2022 07:25:51 +0100 Subject: [PATCH 4/4] overwrite the default fields_to_hide to [] on OrderCycleSupplierTotals tests --- .../orders_cycle_supplier_totals_report_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb index 6f68c7f8dc..634c57eda8 100644 --- a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb @@ -13,7 +13,7 @@ module Reporting end let(:current_user) { distributor.owner } - let(:params) { { display_summary_row: false } } + let(:params) { { display_summary_row: false, fields_to_hide: [] } } let(:report) do OrderCycleSupplierTotals.new(current_user, params) end