Files
openfoodnetwork/app/serializers/api/admin/customer_with_balance_serializer.rb
Pau Perez 96a91969c9 Extract balance-specific serializer
So we only show the customer balance where really needed. Aggregating
the balance can be costly. Also, we avoid defensive coding.
2021-01-11 15:50:19 +01:00

26 lines
528 B
Ruby

# frozen_string_literal: true
module Api
module Admin
class CustomerWithBalanceSerializer < CustomerSerializer
attributes :balance, :balance_status
delegate :balance_value, to: :object
def balance
Spree::Money.new(balance_value, currency: Spree::Config[:currency]).to_s
end
def balance_status
if balance_value.positive?
"credit_owed"
elsif balance_value.negative?
"balance_due"
else
""
end
end
end
end
end