Add nil safety in reports for zero priced orders with no payment method

This commit is contained in:
Matt-Yorkley
2023-06-08 22:31:00 +01:00
parent 2aa3f8eb89
commit ad6d0c1c73
2 changed files with 2 additions and 2 deletions

View File

@@ -23,7 +23,7 @@ module Reporting
def total_by_payment_method(orders, pay_method)
orders.map(&:payments).flatten.select { |payment|
payment.completed? && payment.payment_method.name.to_s.include?(pay_method)
payment.completed? && payment.payment_method&.name.to_s.include?(pay_method)
}.sum(&:amount)
end
end

View File

@@ -17,7 +17,7 @@ module Reporting
{
payment_state: proc { |payments| payment_state(payments.first.order) },
distributor: proc { |payments| payments.first.order.distributor.name },
payment_type: proc { |payments| payments.first.payment_method.name },
payment_type: proc { |payments| payments.first.payment_method&.name },
total_price: proc { |payments| payments.sum(&:amount) }
}
end