mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #5341 from mathewdbutton/5173-show-outstanding-order-balance-on-orders-page
Show outstanding balance on orders page
This commit is contained in:
@@ -3,7 +3,7 @@ class Api::Admin::OrderSerializer < ActiveModel::Serializer
|
||||
:edit_path, :state, :payment_state, :shipment_state,
|
||||
:payments_path, :ready_to_ship, :ready_to_capture, :created_at,
|
||||
:distributor_name, :special_instructions,
|
||||
:item_total, :adjustment_total, :payment_total, :total
|
||||
:item_total, :adjustment_total, :payment_total, :total, :display_outstanding_balance
|
||||
|
||||
has_one :distributor, serializer: Api::Admin::IdSerializer
|
||||
has_one :order_cycle, serializer: Api::Admin::IdSerializer
|
||||
@@ -16,6 +16,12 @@ class Api::Admin::OrderSerializer < ActiveModel::Serializer
|
||||
object.distributor.andand.name
|
||||
end
|
||||
|
||||
def display_outstanding_balance
|
||||
return "" if object.outstanding_balance.zero?
|
||||
|
||||
object.display_outstanding_balance.to_s
|
||||
end
|
||||
|
||||
def edit_path
|
||||
return '' unless object.id
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@
|
||||
%span.state{'ng-class' => 'order.payment_state', 'ng-if' => 'order.payment_state'}
|
||||
%a{'ng-href' => '{{order.payments_path}}' }
|
||||
{{'js.admin.orders.payment_states.' + order.payment_state | t}}
|
||||
%span{'ng-if' => 'order.display_outstanding_balance'}
|
||||
({{order.display_outstanding_balance}})
|
||||
%td.align-center
|
||||
%span.state{'ng-class' => 'order.shipment_state', 'ng-if' => 'order.shipment_state'}
|
||||
{{'js.admin.orders.shipment_states.' + order.shipment_state | t}}
|
||||
|
||||
@@ -46,8 +46,12 @@ FactoryBot.define do
|
||||
distributor { create(:distributor_enterprise) }
|
||||
order_cycle { create(:simple_order_cycle) }
|
||||
|
||||
after(:create) do |order|
|
||||
create(:payment, amount: order.total + 10_000, order: order, state: "completed")
|
||||
transient do
|
||||
credit_amount { 10_000 }
|
||||
end
|
||||
|
||||
after(:create) do |order, evaluator|
|
||||
create(:payment, amount: order.total + evaluator.credit_amount, order: order, state: "completed")
|
||||
order.reload
|
||||
end
|
||||
end
|
||||
@@ -56,8 +60,12 @@ FactoryBot.define do
|
||||
distributor { create(:distributor_enterprise) }
|
||||
order_cycle { create(:simple_order_cycle) }
|
||||
|
||||
after(:create) do |order|
|
||||
create(:payment, amount: order.total - 1, order: order, state: "completed")
|
||||
transient do
|
||||
unpaid_amount { 1 }
|
||||
end
|
||||
|
||||
after(:create) do |order, evaluator|
|
||||
create(:payment, amount: order.total - evaluator.unpaid_amount, order: order, state: "completed")
|
||||
order.reload
|
||||
end
|
||||
end
|
||||
|
||||
29
spec/serializers/api/admin/order_serializer_spec.rb
Normal file
29
spec/serializers/api/admin/order_serializer_spec.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Api::Admin::OrderSerializer do
|
||||
let(:serializer) { described_class.new order }
|
||||
|
||||
describe "#display_outstanding_balance" do
|
||||
let(:order) { create(:order) }
|
||||
|
||||
it "returns empty string" do
|
||||
expect(serializer.display_outstanding_balance).to eql("")
|
||||
end
|
||||
|
||||
context "with outstanding payments" do
|
||||
let(:order) { create(:order_without_full_payment, unpaid_amount: 10) }
|
||||
|
||||
it "generates the outstanding balance" do
|
||||
expect(serializer.display_outstanding_balance).to eql("$10.00")
|
||||
end
|
||||
end
|
||||
|
||||
context "with credit owed" do
|
||||
let(:order) { create(:order_with_credit_payment, credit_amount: 20) }
|
||||
|
||||
it "generates the outstanding balance" do
|
||||
expect(serializer.display_outstanding_balance).to eql("$-20.00")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user