Move report list to own class

This commit is contained in:
Kristina Lim
2018-11-26 13:32:43 +08:00
committed by luisramos0
parent b78e2b4720
commit 552bf1b9f7
2 changed files with 82 additions and 32 deletions

View File

@@ -1,4 +1,6 @@
require 'csv'
require 'open_food_network/reports/list'
require 'open_food_network/order_and_distributor_report'
require 'open_food_network/products_and_inventory_report'
require 'open_food_network/lettuce_share_report'
@@ -24,38 +26,7 @@ Spree::Admin::ReportsController.class_eval do
before_filter :load_data, only: [:customers, :products_and_inventory, :order_cycle_management, :packing]
def report_types
{
orders_and_fulfillment: [
[I18n.t('admin.reports.supplier_totals'), :order_cycle_supplier_totals],
[I18n.t('admin.reports.supplier_totals_by_distributor'), :order_cycle_supplier_totals_by_distributor],
[I18n.t('admin.reports.totals_by_supplier'), :order_cycle_distributor_totals_by_supplier],
[I18n.t('admin.reports.customer_totals'), :order_cycle_customer_totals]
],
products_and_inventory: [
[I18n.t('admin.reports.all_products'), :all_products],
[I18n.t('admin.reports.inventory'), :inventory],
[I18n.t('admin.reports.lettuce_share'), :lettuce_share]
],
customers: [
[I18n.t('admin.reports.mailing_list'), :mailing_list],
[I18n.t('admin.reports.addresses'), :addresses]
],
enterprise_fee_summary: [
[I18n.t("admin.reports.enterprise_fee_summary"), :enterprise_fee_summary]
],
order_cycle_management: [
[I18n.t('admin.reports.payment_methods'), :payment_methods],
[I18n.t('admin.reports.delivery'), :delivery]
],
sales_tax: [
[I18n.t('admin.reports.tax_types'), :tax_types],
[I18n.t('admin.reports.tax_rates'), :tax_rates]
],
packing: [
[I18n.t('admin.reports.pack_by_customer'), :pack_by_customer],
[I18n.t('admin.reports.pack_by_supplier'), :pack_by_supplier]
]
}
OpenFoodNetwork::Reports::List.all
end
# Override spree reports list.

View File

@@ -0,0 +1,79 @@
module OpenFoodNetwork
module Reports
class List
def self.all
new.all
end
def all
{
orders_and_fulfillment: orders_and_fulfillment_report_types,
products_and_inventory: products_and_inventory_report_types,
customers: customers_report_types,
enterprise_fee_summary: enterprise_fee_summary_report_types,
order_cycle_management: order_cycle_management_report_types,
sales_tax: sales_tax_report_types,
packing: packing_report_types
}
end
protected
def orders_and_fulfillment_report_types
[
[i18n_translate("supplier_totals"), :order_cycle_supplier_totals],
[i18n_translate("supplier_totals_by_distributor"),
:order_cycle_supplier_totals_by_distributor],
[i18n_translate("totals_by_supplier"), :order_cycle_distributor_totals_by_supplier],
[i18n_translate("customer_totals"), :order_cycle_customer_totals]
]
end
def products_and_inventory_report_types
[
[i18n_translate("all_products"), :all_products],
[i18n_translate("inventory"), :inventory],
[i18n_translate("lettuce_share"), :lettuce_share]
]
end
def customers_report_types
[
[i18n_translate("mailing_list"), :mailing_list],
[i18n_translate("addresses"), :addresses]
]
end
def enterprise_fee_summary_report_types
[
[i18n_translate("enterprise_fee_summary"), :enterprise_fee_summary]
]
end
def order_cycle_management_report_types
[
[i18n_translate("payment_methods"), :payment_methods],
[i18n_translate("delivery"), :delivery]
]
end
def sales_tax_report_types
[
[i18n_translate("tax_types"), :tax_types],
[i18n_translate("tax_rates"), :tax_rates]
]
end
def packing_report_types
[
[i18n_translate("pack_by_customer"), :pack_by_customer],
[i18n_translate("pack_by_supplier"), :pack_by_supplier]
]
end
def i18n_translate(key)
I18n.t(key, scope: "admin.reports")
end
end
end
end