mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #5573 from Matt-Yorkley/payment-report-500
Fix fatal error in reports helper for orders without payments
This commit is contained in:
@@ -11,10 +11,13 @@ module Spree
|
||||
end
|
||||
|
||||
def report_payment_method_options(orders)
|
||||
orders.map do |o|
|
||||
pm = o.payments.first.payment_method
|
||||
[pm.andand.name, pm.andand.id]
|
||||
end.uniq
|
||||
orders.map do |order|
|
||||
payment_method = order.payments.first.andand.payment_method
|
||||
|
||||
next unless payment_method
|
||||
|
||||
[payment_method.name, payment_method.id]
|
||||
end.compact.uniq
|
||||
end
|
||||
|
||||
def report_shipping_method_options(orders)
|
||||
|
||||
@@ -69,15 +69,15 @@ module OpenFoodNetwork
|
||||
|
||||
def payment_method_row(order)
|
||||
ba = order.billing_address
|
||||
[ba.firstname,
|
||||
ba.lastname,
|
||||
[ba.andand.firstname,
|
||||
ba.andand.lastname,
|
||||
order.distributor.andand.name,
|
||||
customer_code(order.email),
|
||||
order.email,
|
||||
ba.phone,
|
||||
ba.andand.phone,
|
||||
order.shipping_method.andand.name,
|
||||
order.payments.first.andand.payment_method.andand.name,
|
||||
order.payments.first.amount,
|
||||
order.payments.first.andand.amount,
|
||||
OpenFoodNetwork::UserBalanceCalculator.new(order.email, order.distributor).balance]
|
||||
end
|
||||
|
||||
@@ -92,7 +92,7 @@ module OpenFoodNetwork
|
||||
sa.phone,
|
||||
order.shipping_method.andand.name,
|
||||
order.payments.first.andand.payment_method.andand.name,
|
||||
order.payments.first.amount,
|
||||
order.payments.first.andand.amount,
|
||||
OpenFoodNetwork::UserBalanceCalculator.new(order.email, order.distributor).balance,
|
||||
has_temperature_controlled_items?(order),
|
||||
order.special_instructions]
|
||||
|
||||
25
spec/helpers/spree/admin/reports_helper_spec.rb
Normal file
25
spec/helpers/spree/admin/reports_helper_spec.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
|
||||
describe Spree::ReportsHelper, type: :helper do
|
||||
describe "#report_payment_method_options" do
|
||||
let(:order_with_payments) { create(:order_ready_to_ship) }
|
||||
let(:order_without_payments) { create(:order_with_line_items) }
|
||||
let(:orders) { [order_with_payments, order_without_payments] }
|
||||
let(:payment_method) { order_with_payments.payments.first.payment_method }
|
||||
|
||||
it "returns payment method select options for given orders" do
|
||||
select_options = helper.report_payment_method_options([order_with_payments])
|
||||
|
||||
expect(select_options).to eq [[payment_method.name, payment_method.id]]
|
||||
end
|
||||
|
||||
it "handles orders that don't have payments, without error" do
|
||||
select_options = helper.report_payment_method_options(orders)
|
||||
|
||||
expect(select_options).to eq [[payment_method.name, payment_method.id]]
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user