From b259f59d1ed27f58b7813f4b39c01cb8de7900a1 Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Wed, 6 Apr 2022 11:06:55 +0200 Subject: [PATCH] Packing Report: Adds new subreport "Pack by product" --- config/locales/en.yml | 1 + lib/reporting/reports/list.rb | 3 +- lib/reporting/reports/packing/product.rb | 51 ++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 lib/reporting/reports/packing/product.rb diff --git a/config/locales/en.yml b/config/locales/en.yml index 3b9088eb2b..7224a5d9da 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1272,6 +1272,7 @@ en: tax_rates: Tax Rates pack_by_customer: Pack By Customer pack_by_supplier: Pack By Supplier + pack_by_product: Pack By Product orders_and_distributors: name: Orders And Distributors description: Orders with distributor details diff --git a/lib/reporting/reports/list.rb b/lib/reporting/reports/list.rb index 6a7400e5cd..f43e61debd 100644 --- a/lib/reporting/reports/list.rb +++ b/lib/reporting/reports/list.rb @@ -76,7 +76,8 @@ module Reporting def packing_report_types [ [i18n_translate("pack_by_customer"), :customer], - [i18n_translate("pack_by_supplier"), :supplier] + [i18n_translate("pack_by_supplier"), :supplier], + [i18n_translate("pack_by_product"), :product] ] end diff --git a/lib/reporting/reports/packing/product.rb b/lib/reporting/reports/packing/product.rb new file mode 100644 index 0000000000..639061f875 --- /dev/null +++ b/lib/reporting/reports/packing/product.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module Reporting + module Reports + module Packing + class Product < Base + def columns + # Reorder default columns + super.slice(:hub, :supplier, :product, :variant, + :customer_code, :last_name, :first_name, :phone, + :quantity, :price, :temp_controlled) + end + + def rules + [ + { + group_by: :hub, + header: true, + header_class: "h1 with-background text-center", + }, + { + group_by: :supplier, + header: true, + header_class: "h1", + }, + { + group_by: proc { |_item, row| "#{row.product} - #{row.variant}" }, + header: true, + fields_used_in_header: [:product, :variant], + summary_row: summary_row, + header_class: "h3", + } + ] + end + + def ordering_fields + lambda do + [ + distributor_alias[:name], + Arel.sql("supplier"), + Arel.sql("product"), + Arel.sql("variant"), + bill_address_alias[:lastname], + order_table[:id], + ] + end + end + end + end + end +end