mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Packing Report: add price and reorder columns
Adds price column last_name column first because it's used for ordering
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
d53d38906a
commit
213c0dd060
@@ -12,7 +12,7 @@ module Admin
|
||||
|
||||
@report = report_class.new(spree_current_user, ransack_params, report_options)
|
||||
|
||||
if export_spreadsheet?
|
||||
if report_format.present?
|
||||
export_report
|
||||
else
|
||||
render_report
|
||||
@@ -22,14 +22,12 @@ module Admin
|
||||
private
|
||||
|
||||
def export_report
|
||||
render report_format.to_sym => @report.public_send("to_#{report_format}"),
|
||||
:filename => report_filename
|
||||
send_data @report.public_send("to_#{report_format}"), filename: report_filename
|
||||
end
|
||||
|
||||
def render_report
|
||||
assign_view_data
|
||||
load_form_options
|
||||
|
||||
render "show"
|
||||
end
|
||||
|
||||
|
||||
@@ -39,10 +39,6 @@ module ReportsActions
|
||||
params[:report_format]
|
||||
end
|
||||
|
||||
def export_spreadsheet?
|
||||
['xlsx', 'ods', 'csv'].include?(report_format)
|
||||
end
|
||||
|
||||
def form_options_required?
|
||||
[:packing, :customers, :products_and_inventory, :order_cycle_management].
|
||||
include? report_type.to_sym
|
||||
|
||||
@@ -8,7 +8,12 @@
|
||||
.alpha.two.columns
|
||||
= label_tag :report_format, t(".generate_report")
|
||||
.omega.fourteen.columns
|
||||
= select_tag :report_format, options_for_select({t('.on_screen') => '', t('.csv_spreadsheet') => 'csv', t('.excel_spreadsheet') => 'xlsx', t('.openoffice_spreadsheet') => 'ods'})
|
||||
= select_tag :report_format, options_for_select({ |
|
||||
t('.on_screen') => '', |
|
||||
t('.pdf') => 'pdf', |
|
||||
t('.csv_spreadsheet') => 'csv', |
|
||||
t('.excel_spreadsheet') => 'xlsx', |
|
||||
t('.openoffice_spreadsheet') => 'ods'})
|
||||
|
||||
-#.inline-checkbox
|
||||
-# = check_box_tag "options[exclude_summaries]", true, params[:options].andand[:exclude_summaries]
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
- if params[:q].present?
|
||||
%table.report__table
|
||||
%thead
|
||||
%tr
|
||||
- @report.table_headers.each do |heading|
|
||||
%th
|
||||
= t("admin.reports.table.headings.#{heading}")
|
||||
%tbody
|
||||
- @report.table_rows.each do |row|
|
||||
- if row
|
||||
%tr
|
||||
- row.each do |cell|
|
||||
%td
|
||||
= cell
|
||||
- if @report.table_rows.empty?
|
||||
- report ||= @report
|
||||
|
||||
%table.report__table
|
||||
%thead
|
||||
%tr
|
||||
- report.table_headers.each do |heading|
|
||||
%th
|
||||
= t("admin.reports.table.headings.#{heading}")
|
||||
%tbody
|
||||
- report.table_rows.each do |row|
|
||||
- if row
|
||||
%tr
|
||||
%td{colspan: @report.table_headers.count}= t(:none)
|
||||
- row.each do |cell|
|
||||
%td
|
||||
= cell
|
||||
- if report.table_rows.empty?
|
||||
%tr
|
||||
%td{colspan: report.table_headers.count}= t(:none)
|
||||
|
||||
0
app/views/admin/reports/filters/_packing.html.haml
Normal file → Executable file
0
app/views/admin/reports/filters/_packing.html.haml
Normal file → Executable file
@@ -13,4 +13,5 @@
|
||||
- if @report_message.present?
|
||||
%p.report__message= @report_message
|
||||
|
||||
= render "table"
|
||||
- if params[:q].present?
|
||||
= render "table"
|
||||
|
||||
32
app/views/layouts/pdf.html.haml
Normal file
32
app/views/layouts/pdf.html.haml
Normal file
@@ -0,0 +1,32 @@
|
||||
!!!
|
||||
%html
|
||||
%head
|
||||
%meta{:content => "charset=UTF-8"}
|
||||
-# Using wicked_pdf_stylesheet_pack_tag with a new pdf pack was not working when using
|
||||
-# WickedPdf.new.pdf_from_string cause the css file reference was not absolute
|
||||
-# So I ended up putting inline css here, so it's included for sure in the PDF
|
||||
:css
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
th {
|
||||
text-align: left;
|
||||
}
|
||||
th, td {
|
||||
padding: 5px;
|
||||
}
|
||||
thead {
|
||||
background-color: #f6f6f6;
|
||||
border-bottom: 1px solid grey;
|
||||
}
|
||||
|
||||
%body
|
||||
= yield
|
||||
@@ -1329,9 +1329,11 @@ en:
|
||||
quantity: "Quantity"
|
||||
is_temperature_controlled: "TempControlled?"
|
||||
temp_controlled: "TempControlled?"
|
||||
price: "Price"
|
||||
rendering_options:
|
||||
generate_report: "Generate report"
|
||||
on_screen: "On screen"
|
||||
pdf: PDF
|
||||
csv_spreadsheet: "CSV Spreadsheet"
|
||||
excel_spreadsheet: "Excel Spreadsheet"
|
||||
openoffice_spreadsheet: "OpenOffice Spreadsheet"
|
||||
|
||||
@@ -84,7 +84,7 @@ module Reporting
|
||||
end
|
||||
|
||||
def summary_row_title
|
||||
I18n.t("total_items", scope: i18n_scope)
|
||||
I18n.t("total", scope: i18n_scope)
|
||||
end
|
||||
|
||||
def i18n_scope
|
||||
|
||||
@@ -35,5 +35,15 @@ module Reporting
|
||||
def to_xlsx
|
||||
SpreadsheetArchitect.to_xlsx(headers: table_headers, data: table_rows)
|
||||
end
|
||||
|
||||
def to_pdf
|
||||
WickedPdf.new.pdf_from_string(
|
||||
ActionController::Base.new.render_to_string(
|
||||
template: 'admin/reports/_table',
|
||||
layout: 'pdf',
|
||||
locals: { report: self }
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module Reporting
|
||||
class ReportTemplate
|
||||
delegate :as_json, :as_arrays, :table_headers, :table_rows,
|
||||
:to_csv, :to_xlsx, :to_ods, :to_json, to: :renderer
|
||||
:to_csv, :to_xlsx, :to_ods, :to_pdf, :to_json, to: :renderer
|
||||
|
||||
attr_reader :options
|
||||
|
||||
|
||||
@@ -9,12 +9,13 @@ module Reporting
|
||||
{
|
||||
hub: default_blank(distributor_alias[:name]),
|
||||
customer_code: default_blank(masked(customer_table[:code])),
|
||||
first_name: default_blank(masked(bill_address_alias[:firstname])),
|
||||
last_name: default_blank(masked(bill_address_alias[:lastname])),
|
||||
first_name: default_blank(masked(bill_address_alias[:firstname])),
|
||||
supplier: default_blank(supplier_alias[:name]),
|
||||
product: default_string(product_table[:name], summary_row_title),
|
||||
variant: default_blank(variant_full_name),
|
||||
quantity: sum_values(line_item_table[:quantity]),
|
||||
price: sum_values(line_item_table[:quantity] * line_item_table[:price]),
|
||||
temp_controlled: boolean_blank(shipping_category_table[:temperature_controlled]),
|
||||
}
|
||||
end
|
||||
|
||||
@@ -4,21 +4,24 @@ module Reporting
|
||||
module Reports
|
||||
module Packing
|
||||
class Supplier < Base
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def select_fields
|
||||
lambda do
|
||||
{
|
||||
hub: default_blank(distributor_alias[:name]),
|
||||
supplier: default_blank(supplier_alias[:name]),
|
||||
customer_code: default_blank(customer_table[:code]),
|
||||
first_name: default_blank(masked(bill_address_alias[:firstname])),
|
||||
last_name: default_blank(masked(bill_address_alias[:lastname])),
|
||||
first_name: default_blank(masked(bill_address_alias[:firstname])),
|
||||
product: default_string(product_table[:name], summary_row_title),
|
||||
variant: default_blank(variant_full_name),
|
||||
quantity: sum_values(line_item_table[:quantity]),
|
||||
price: sum_values(line_item_table[:quantity] * line_item_table[:price]),
|
||||
temp_controlled: boolean_blank(shipping_category_table[:temperature_controlled]),
|
||||
}
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def group_sets
|
||||
lambda do
|
||||
|
||||
@@ -69,6 +69,7 @@ describe Api::V0::ReportsController, type: :controller do
|
||||
"product" => line_item.product.name,
|
||||
"variant" => line_item.full_name,
|
||||
"quantity" => line_item.quantity,
|
||||
"price" => (line_item.quantity * line_item.price).to_s,
|
||||
"temp_controlled" =>
|
||||
line_item.product.shipping_category&.temperature_controlled ? I18n.t(:yes) : I18n.t(:no)
|
||||
}
|
||||
@@ -84,6 +85,7 @@ describe Api::V0::ReportsController, type: :controller do
|
||||
"product" => line_item.product.name,
|
||||
"variant" => line_item.full_name,
|
||||
"quantity" => line_item.quantity,
|
||||
"price" => (line_item.quantity * line_item.price).to_s,
|
||||
"temp_controlled" =>
|
||||
line_item.product.shipping_category&.temperature_controlled ? I18n.t(:yes) : I18n.t(:no)
|
||||
}
|
||||
@@ -96,9 +98,10 @@ describe Api::V0::ReportsController, type: :controller do
|
||||
"first_name" => "",
|
||||
"last_name" => "",
|
||||
"supplier" => "",
|
||||
"product" => I18n.t("total_items", scope: i18n_scope),
|
||||
"product" => I18n.t("total", scope: i18n_scope),
|
||||
"variant" => "",
|
||||
"quantity" => order.line_items.sum(&:quantity),
|
||||
"price" => order.line_items.sum(&:price).to_s,
|
||||
"temp_controlled" => "",
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user