mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Hide new report's balance under toggle
This commit is contained in:
@@ -46,21 +46,34 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def search
|
||||
Spree::Order.
|
||||
finalized.
|
||||
where.not(spree_orders: { state: :canceled }).
|
||||
distributed_by_user(@user).
|
||||
managed_by(@user).
|
||||
search(params[:q])
|
||||
if FeatureToggle.enabled?(:customer_balance, @user)
|
||||
Spree::Order.
|
||||
finalized.
|
||||
where.not(spree_orders: { state: :canceled }).
|
||||
distributed_by_user(@user).
|
||||
managed_by(@user).
|
||||
search(params[:q])
|
||||
else
|
||||
Spree::Order.
|
||||
complete.
|
||||
where("spree_orders.state != ?", :canceled).
|
||||
distributed_by_user(@user).
|
||||
managed_by(@user).
|
||||
search(params[:q])
|
||||
end
|
||||
end
|
||||
|
||||
def orders
|
||||
search_result = search.result.order(:id)
|
||||
orders_with_balance = OutstandingBalance.new(search_result).
|
||||
query.
|
||||
select('spree_orders.*')
|
||||
if FeatureToggle.enabled?(:customer_balance, @user)
|
||||
search_result = search.result.order(:id)
|
||||
orders_with_balance = OutstandingBalance.new(search_result).
|
||||
query.
|
||||
select('spree_orders.*')
|
||||
|
||||
filter(orders_with_balance)
|
||||
filter(orders_with_balance)
|
||||
else
|
||||
filter search.result
|
||||
end
|
||||
end
|
||||
|
||||
def table_items
|
||||
@@ -79,6 +92,14 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def balance(order)
|
||||
if FeatureToggle.enabled?(:customer_balance, @user)
|
||||
order.balance_value
|
||||
else
|
||||
UserBalanceCalculator.new(order.email, order.distributor).balance
|
||||
end
|
||||
end
|
||||
|
||||
def payment_method_row(order)
|
||||
ba = order.billing_address
|
||||
[ba.andand.firstname,
|
||||
@@ -90,7 +111,7 @@ module OpenFoodNetwork
|
||||
order.shipping_method.andand.name,
|
||||
order.payments.first.andand.payment_method.andand.name,
|
||||
order.payments.first.andand.amount,
|
||||
order.balance_value]
|
||||
balance(order)]
|
||||
end
|
||||
|
||||
def delivery_row(order)
|
||||
@@ -105,7 +126,7 @@ module OpenFoodNetwork
|
||||
order.shipping_method.andand.name,
|
||||
order.payments.first.andand.payment_method.andand.name,
|
||||
order.payments.first.andand.amount,
|
||||
order.balance_value,
|
||||
balance(order),
|
||||
has_temperature_controlled_items?(order),
|
||||
order.special_instructions]
|
||||
end
|
||||
|
||||
@@ -27,11 +27,28 @@ module OpenFoodNetwork
|
||||
expect(subject.orders).to eq([order])
|
||||
end
|
||||
|
||||
it 'calls OutstandingBalance query object' do
|
||||
outstanding_balance = instance_double(OutstandingBalance, query: Spree::Order.none)
|
||||
expect(OutstandingBalance).to receive(:new).and_return(outstanding_balance)
|
||||
context 'when the customer_balance feature is enabled' do
|
||||
let(:customers_with_balance) { instance_double(CustomersWithBalance) }
|
||||
|
||||
subject.orders
|
||||
before do
|
||||
allow(OpenFoodNetwork::FeatureToggle)
|
||||
.to receive(:enabled?).with(:customer_balance, anything) { true }
|
||||
end
|
||||
|
||||
it 'calls OutstandingBalance query object' do
|
||||
outstanding_balance = instance_double(OutstandingBalance, query: Spree::Order.none)
|
||||
expect(OutstandingBalance).to receive(:new).and_return(outstanding_balance)
|
||||
|
||||
subject.orders
|
||||
end
|
||||
|
||||
it 'orders them by id' do
|
||||
result = instance_double(ActiveRecord::Relation)
|
||||
allow_any_instance_of(Ransack::Search).to receive(:result).and_return(result)
|
||||
expect(result).to receive(:order).with(:id) { Spree::Order.none }
|
||||
|
||||
subject.orders
|
||||
end
|
||||
end
|
||||
|
||||
it "does not show cancelled orders" do
|
||||
@@ -40,14 +57,6 @@ module OpenFoodNetwork
|
||||
expect(subject.orders).to eq([o2])
|
||||
end
|
||||
|
||||
it 'orders them by id' do
|
||||
result = instance_double(ActiveRecord::Relation)
|
||||
allow_any_instance_of(Ransack::Search).to receive(:result).and_return(result)
|
||||
expect(result).to receive(:order).with(:id) { Spree::Order.none }
|
||||
|
||||
subject.orders
|
||||
end
|
||||
|
||||
context "default date range" do
|
||||
it "fetches orders completed in the past month" do
|
||||
o1 = create(:order, state: 'complete', completed_at: 1.month.ago - 1.day)
|
||||
|
||||
Reference in New Issue
Block a user