From fc1b686938f4e7b2efd7663d1ae3e4b48e792502 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Mar 2024 02:11:23 +0000 Subject: [PATCH] Don't generate packing reports unnecessarily when displaying the report form --- lib/reporting/report_headers_builder.rb | 4 ++-- lib/reporting/report_template.rb | 4 ++++ lib/reporting/reports/packing/customer.rb | 11 ++++++++--- lib/reporting/reports/packing/product.rb | 11 ++++++++--- lib/reporting/reports/packing/supplier.rb | 10 ++++++++-- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/reporting/report_headers_builder.rb b/lib/reporting/report_headers_builder.rb index 37b85d3629d..ef129bedc8d 100644 --- a/lib/reporting/report_headers_builder.rb +++ b/lib/reporting/report_headers_builder.rb @@ -11,13 +11,13 @@ def initialize(report, current_user) def table_headers filter = proc { |key| key.to_sym.in?(fields_to_show) } - report.columns.keys.filter { |key| filter.call(key) }.map do |key| + report.table_columns.keys.filter { |key| filter.call(key) }.map do |key| translate_header(key) end end def available_headers - report.columns.keys.map { |key| [translate_header(key), key] } + report.table_columns.keys.map { |key| [translate_header(key), key] } end def fields_to_hide diff --git a/lib/reporting/report_template.rb b/lib/reporting/report_template.rb index 5c295ae553c..3567e779e5f 100644 --- a/lib/reporting/report_template.rb +++ b/lib/reporting/report_template.rb @@ -54,6 +54,10 @@ def columns raise NotImplementedError end + def table_columns + columns + end + # Exple { total_price: :currency } def columns_format {} diff --git a/lib/reporting/reports/packing/customer.rb b/lib/reporting/reports/packing/customer.rb index a5609725a2b..65622639b46 100644 --- a/lib/reporting/reports/packing/customer.rb +++ b/lib/reporting/reports/packing/customer.rb @@ -4,11 +4,16 @@ module Reporting module Reports module Packing class Customer < Base + def table_columns + Struct.new(:keys).new( + [:hub, :customer_code, :first_name, :last_name, :phone, :supplier, :product, + :variant, :weight, :height, :width, :depth, :quantity, :price, :temp_controlled] + ) + end + def columns # Reorder default columns - super.slice(:hub, :customer_code, :first_name, :last_name, :phone, - :supplier, :product, :variant, :weight, :height, :width, :depth, :quantity, - :price, :temp_controlled) + super.slice(*table_columns.keys) end def rules diff --git a/lib/reporting/reports/packing/product.rb b/lib/reporting/reports/packing/product.rb index e219fc2c88f..63990f3ad4d 100644 --- a/lib/reporting/reports/packing/product.rb +++ b/lib/reporting/reports/packing/product.rb @@ -4,11 +4,16 @@ module Reporting module Reports module Packing class Product < Base + def table_columns + Struct.new(:keys).new( + [:hub, :supplier, :product, :variant, :customer_code, :first_name, + :last_name, :phone, :quantity, :price, :temp_controlled] + ) + end + def columns # Reorder default columns - super.slice(:hub, :supplier, :product, :variant, - :customer_code, :first_name, :last_name, :phone, - :quantity, :price, :temp_controlled) + super.slice(*table_columns.keys) end def rules diff --git a/lib/reporting/reports/packing/supplier.rb b/lib/reporting/reports/packing/supplier.rb index cca255786b0..d1f6861ff9c 100644 --- a/lib/reporting/reports/packing/supplier.rb +++ b/lib/reporting/reports/packing/supplier.rb @@ -4,10 +4,16 @@ module Reporting module Reports module Packing class Supplier < Base + def table_columns + Struct.new(:keys).new( + [:hub, :supplier, :customer_code, :first_name, :last_name, :phone, + :product, :variant, :quantity, :price, :temp_controlled] + ) + end + def columns # Reorder default columns - super.slice(:hub, :supplier, :customer_code, :first_name, :last_name, :phone, - :product, :variant, :quantity, :price, :temp_controlled) + super.slice(*table_columns.keys) end def rules