mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Show distribution charge on report
This commit is contained in:
@@ -474,7 +474,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
table_items = @line_items
|
||||
@include_blank = 'All'
|
||||
|
||||
header = ["Hub", "Customer", "Email", "Phone", "Producer", "Product", "Variant", "Amount", "Item ($)", "Ship ($)", "Total ($)",
|
||||
header = ["Hub", "Customer", "Email", "Phone", "Producer", "Product", "Variant", "Amount", "Item ($)", "Dist ($)", "Ship ($)", "Total ($)",
|
||||
"Shipping", "Delivery?", "Ship street", "Ship street 2", "Ship city", "Ship postcode", "Ship state",
|
||||
"Paid?"]
|
||||
|
||||
@@ -491,6 +491,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.price } },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
|
||||
proc { |line_items| line_items.first.order.shipping_method.andand.name },
|
||||
proc { |line_items| rsa.call(line_items) ? 'Y' : 'N' },
|
||||
@@ -515,6 +516,7 @@ Spree::Admin::ReportsController.class_eval do
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| "" },
|
||||
proc { |line_items| line_items.sum { |li| li.quantity * li.price } },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.distribution_total } },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.ship_total } },
|
||||
proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.total } },
|
||||
|
||||
|
||||
@@ -127,7 +127,11 @@ Spree::Order.class_eval do
|
||||
end
|
||||
|
||||
def line_item_variants
|
||||
line_items.map { |li| li.variant }
|
||||
line_items.map(&:variant)
|
||||
end
|
||||
|
||||
def distribution_total
|
||||
adjustments.eligible.where(originator_type: 'EnterpriseFee').sum(&:amount)
|
||||
end
|
||||
|
||||
# Show payment methods for this distributor
|
||||
@@ -140,6 +144,8 @@ Spree::Order.class_eval do
|
||||
def available_shipping_methods(display_on = nil)
|
||||
Spree::ShippingMethod.all_available(self, display_on)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def shipping_address_from_distributor
|
||||
|
||||
@@ -141,6 +141,37 @@ describe Spree::Order do
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting the distribution charge" do
|
||||
let(:o) { create(:order) }
|
||||
let(:li) { create(:line_item, order: o) }
|
||||
|
||||
it "returns the sum of eligible enterprise fee adjustments" do
|
||||
ef = create(:enterprise_fee)
|
||||
ef.calculator.set_preference :amount, 123.45
|
||||
a = ef.create_locked_adjustment("adjustment", li.order, li, true)
|
||||
|
||||
o.distribution_total.should == 123.45
|
||||
end
|
||||
|
||||
it "does not include ineligible adjustments" do
|
||||
ef = create(:enterprise_fee)
|
||||
ef.calculator.set_preference :amount, 123.45
|
||||
a = ef.create_locked_adjustment("adjustment", li.order, li, true)
|
||||
|
||||
a.update_column :eligible, false
|
||||
|
||||
o.distribution_total.should == 0
|
||||
end
|
||||
|
||||
it "does not include adjustments that do not originate from enterprise fees" do
|
||||
sm = create(:shipping_method)
|
||||
sm.calculator.set_preference :amount, 123.45
|
||||
sm.create_adjustment("adjustment", li.order, li, true)
|
||||
|
||||
o.distribution_total.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe "setting the distributor" do
|
||||
it "sets the distributor when no order cycle is set" do
|
||||
d = create(:distributor_enterprise)
|
||||
|
||||
Reference in New Issue
Block a user