mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Add label to customer balance so it's clear to the manager what's the balance status: credit owed or balance due
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class Api::Admin::CustomerSerializer < ActiveModel::Serializer
|
||||
attributes :id, :email, :enterprise_id, :user_id, :code, :tags, :tag_list, :name,
|
||||
:allow_charges, :default_card_present?, :balance
|
||||
:allow_charges, :default_card_present?, :balance, :balance_status
|
||||
|
||||
has_one :ship_address, serializer: Api::AddressSerializer
|
||||
has_one :bill_address, serializer: Api::AddressSerializer
|
||||
@@ -14,8 +14,17 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def balance
|
||||
balance = OpenFoodNetwork::UserBalanceCalculator.new(object.email, object.enterprise).balance
|
||||
Spree::Money.new(balance, { currency: Spree::Config[:currency] }).to_s
|
||||
Spree::Money.new(balance_value, { currency: Spree::Config[:currency] }).to_s
|
||||
end
|
||||
|
||||
def balance_status
|
||||
if balance_value > 0
|
||||
"credit_owed"
|
||||
elsif balance_value < 0
|
||||
"balance_due"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def tags
|
||||
@@ -38,4 +47,8 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer
|
||||
|
||||
options[:customer_tags].andand[object.id] || []
|
||||
end
|
||||
|
||||
def balance_value
|
||||
@balance_value ||= OpenFoodNetwork::UserBalanceCalculator.new(object.email, object.enterprise).balance
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user