mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
So we only show the customer balance where really needed. Aggregating the balance can be costly. Also, we avoid defensive coding.
26 lines
528 B
Ruby
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
|