mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Move specific logic for Supplier Totals report to class
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require "open_food_network/reports/line_items"
|
||||
require "open_food_network/orders_and_fulfillments_report/supplier_totals_report"
|
||||
require 'open_food_network/orders_and_fulfillments_report/default_report'
|
||||
|
||||
include Spree::ReportsHelper
|
||||
@@ -17,9 +18,7 @@ module OpenFoodNetwork
|
||||
case options[:report_type]
|
||||
|
||||
when "order_cycle_supplier_totals"
|
||||
[I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_amount),
|
||||
I18n.t(:report_header_total_units), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
|
||||
I18n.t(:report_header_status), I18n.t(:report_header_incoming_transport)]
|
||||
SupplierTotalsReport.new(self).header
|
||||
when "order_cycle_supplier_totals_by_distributor"
|
||||
[I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_to_hub),
|
||||
I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
|
||||
@@ -59,20 +58,7 @@ module OpenFoodNetwork
|
||||
def rules
|
||||
case options[:report_type]
|
||||
when "order_cycle_supplier_totals"
|
||||
[
|
||||
{
|
||||
group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name }
|
||||
},
|
||||
{
|
||||
group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name }
|
||||
},
|
||||
{
|
||||
group_by: proc { |line_item| line_item.variant.full_name },
|
||||
sort_by: proc { |full_name| full_name }
|
||||
}
|
||||
]
|
||||
SupplierTotalsReport.new(self).rules
|
||||
when "order_cycle_supplier_totals_by_distributor"
|
||||
[
|
||||
{
|
||||
@@ -207,17 +193,7 @@ module OpenFoodNetwork
|
||||
def columns
|
||||
case options[:report_type]
|
||||
when "order_cycle_supplier_totals"
|
||||
[
|
||||
supplier_name,
|
||||
product_name,
|
||||
line_items_name,
|
||||
proc { |line_items| line_items.sum(&:quantity) },
|
||||
proc { |line_items| total_units(line_items) },
|
||||
proc { |line_items| line_items.first.price },
|
||||
proc { |line_items| line_items.sum(&:amount) },
|
||||
proc { |_line_items| "" },
|
||||
proc { |_line_items| I18n.t(:report_header_incoming_transport) }
|
||||
]
|
||||
SupplierTotalsReport.new(self).columns
|
||||
when "order_cycle_supplier_totals_by_distributor"
|
||||
[
|
||||
supplier_name,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
module OpenFoodNetwork
|
||||
class OrdersAndFulfillmentsReport
|
||||
class SupplierTotalsReport
|
||||
attr_reader :context
|
||||
|
||||
delegate :supplier_name, :product_name, :line_items_name, :total_units, to: :context
|
||||
|
||||
def initialize(context)
|
||||
@context = context
|
||||
end
|
||||
|
||||
def header
|
||||
[I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_amount),
|
||||
I18n.t(:report_header_total_units), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
|
||||
I18n.t(:report_header_status), I18n.t(:report_header_incoming_transport)]
|
||||
end
|
||||
|
||||
def rules
|
||||
[
|
||||
{
|
||||
group_by: proc { |line_item| line_item.variant.product.supplier },
|
||||
sort_by: proc { |supplier| supplier.name }
|
||||
},
|
||||
{
|
||||
group_by: proc { |line_item| line_item.variant.product },
|
||||
sort_by: proc { |product| product.name }
|
||||
},
|
||||
{
|
||||
group_by: proc { |line_item| line_item.variant.full_name },
|
||||
sort_by: proc { |full_name| full_name }
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
def columns
|
||||
[
|
||||
supplier_name,
|
||||
product_name,
|
||||
line_items_name,
|
||||
proc { |line_items| line_items.sum(&:quantity) },
|
||||
proc { |line_items| total_units(line_items) },
|
||||
proc { |line_items| line_items.first.price },
|
||||
proc { |line_items| line_items.sum(&:amount) },
|
||||
proc { |_line_items| "" },
|
||||
proc { |_line_items| I18n.t(:report_header_incoming_transport) }
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user