Skip to content

Commit

Permalink
Don't generate packing reports unnecessarily when displaying the repo…
Browse files Browse the repository at this point in the history
…rt form
  • Loading branch information
Matt-Yorkley committed Mar 24, 2024
1 parent 26f3b56 commit fc1b686
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/reporting/report_headers_builder.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/reporting/report_template.rb
Expand Up @@ -54,6 +54,10 @@ def columns
raise NotImplementedError
end

def table_columns
columns
end

# Exple { total_price: :currency }
def columns_format
{}
Expand Down
11 changes: 8 additions & 3 deletions lib/reporting/reports/packing/customer.rb
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions lib/reporting/reports/packing/product.rb
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lib/reporting/reports/packing/supplier.rb
Expand Up @@ -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
Expand Down

0 comments on commit fc1b686

Please sign in to comment.