mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +00:00
Bulk coop allocation report uses unit value rather than variant weight
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require 'open_food_network/reports/bulk_coop_supplier_report'
|
||||
require 'open_food_network/reports/bulk_coop_allocation_report'
|
||||
|
||||
module OpenFoodNetwork
|
||||
class BulkCoopReport
|
||||
@@ -8,6 +9,7 @@ module OpenFoodNetwork
|
||||
@user = user
|
||||
|
||||
@supplier_report = OpenFoodNetwork::Reports::BulkCoopSupplierReport.new
|
||||
@allocation_report = OpenFoodNetwork::Reports::BulkCoopAllocationReport.new
|
||||
end
|
||||
|
||||
def header
|
||||
@@ -15,7 +17,7 @@ module OpenFoodNetwork
|
||||
when "bulk_coop_supplier_report"
|
||||
@supplier_report.header
|
||||
when "bulk_coop_allocation"
|
||||
["Customer", "Product", "Unit Size", "Variant", "Weight", "Sum Total", "Sum Max Total", "Total Allocated", "Remainder"]
|
||||
@allocation_report.header
|
||||
when "bulk_coop_packing_sheets"
|
||||
["Customer", "Product", "Variant", "Sum Total"]
|
||||
when "bulk_coop_customer_payments"
|
||||
@@ -40,23 +42,8 @@ module OpenFoodNetwork
|
||||
case params[:report_type]
|
||||
when "bulk_coop_supplier_report"
|
||||
@supplier_report.rules
|
||||
|
||||
when "bulk_coop_allocation"
|
||||
[ { group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name },
|
||||
summary_columns: [ proc { |lis| "TOTAL" },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy ? (lis.first.variant.product.group_buy_unit_size || 0.0) : "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| lis.sum { |li| li.quantity * (li.variant.weight || 0) } },
|
||||
proc { |lis| lis.sum { |li| (li.max_quantity || 0) * (li.variant.weight || 0) } },
|
||||
proc { |lis| ( (lis.first.variant.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } / lis.first.variant.product.group_buy_unit_size ) ).floor * (lis.first.variant.product.group_buy_unit_size || 0) },
|
||||
proc { |lis| lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } - ( ( (lis.first.variant.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) } / lis.first.variant.product.group_buy_unit_size ) ).floor * (lis.first.variant.product.group_buy_unit_size || 0) ) } ] },
|
||||
{ group_by: proc { |li| li.variant },
|
||||
sort_by: proc { |variant| variant.full_name } },
|
||||
{ group_by: proc { |li| li.order },
|
||||
sort_by: proc { |order| order.to_s } } ]
|
||||
@allocation_report.rules
|
||||
when "bulk_coop_packing_sheets"
|
||||
[ { group_by: proc { |li| li.variant.product },
|
||||
sort_by: proc { |product| product.name } },
|
||||
@@ -91,15 +78,7 @@ module OpenFoodNetwork
|
||||
when "bulk_coop_supplier_report"
|
||||
@supplier_report.columns
|
||||
when "bulk_coop_allocation"
|
||||
[ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
proc { |lis| lis.first.variant.product.group_buy ? (lis.first.variant.product.group_buy_unit_size || 0.0) : "" },
|
||||
proc { |lis| lis.first.variant.full_name },
|
||||
proc { |lis| lis.first.variant.weight || 0 },
|
||||
proc { |lis| lis.sum { |li| li.quantity } },
|
||||
proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
|
||||
proc { |lis| "" },
|
||||
proc { |lis| "" } ]
|
||||
@allocation_report.columns
|
||||
when "bulk_coop_packing_sheets"
|
||||
[ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
|
||||
proc { |lis| lis.first.variant.product.name },
|
||||
|
||||
@@ -45,24 +45,12 @@ module OpenFoodNetwork::Reports
|
||||
end
|
||||
end
|
||||
|
||||
def total_allocated(lis)
|
||||
# Proposed new factoring:
|
||||
# units_required * group_buy_unit_size
|
||||
|
||||
num_units = if (lis.first.variant.product.group_buy_unit_size || 0).zero?
|
||||
0
|
||||
else
|
||||
max_weight = lis.sum { |li| ( [li.max_quantity || 0, li.quantity || 0].max ) * (li.variant.weight || 0) }
|
||||
group_buy_unit_size = lis.first.variant.product.group_buy_unit_size
|
||||
|
||||
(max_weight / group_buy_unit_size).floor
|
||||
end
|
||||
|
||||
num_units * (lis.first.variant.product.group_buy_unit_size || 0)
|
||||
def total_available(lis)
|
||||
units_required(lis) * group_buy_unit_size(lis)
|
||||
end
|
||||
|
||||
def remainder(lis)
|
||||
(units_required(lis) * group_buy_unit_size(lis)) - max_quantity_amount(lis)
|
||||
total_available(lis) - max_quantity_amount(lis)
|
||||
end
|
||||
|
||||
def max_quantity_amount(lis)
|
||||
|
||||
Reference in New Issue
Block a user