mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
add orders without billing address to SearchOrders#fetch_orders' results
This commit is contained in:
committed by
Maikel Linke
parent
7414b5cbc9
commit
04312b05c6
@@ -19,7 +19,17 @@ class SearchOrders
|
||||
includes(:payments, :subscription, :shipments, :bill_address, :distributor, :order_cycle).
|
||||
ransack(params[:q])
|
||||
|
||||
@search.result(distinct: true).joins(:bill_address)
|
||||
@search = @search.result(distinct: true)
|
||||
|
||||
if ['bill_address',
|
||||
'billing_address'].any?{ |param|
|
||||
params.dig(:q, :s)&.starts_with?(param)
|
||||
}
|
||||
@search = @search.left_joins(:bill_address).
|
||||
select('spree_addresses.*, spree_orders.*')
|
||||
end
|
||||
|
||||
@search
|
||||
end
|
||||
|
||||
def search_query
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
%a{ href: "mailto:#{order.email}", target: "_blank" }
|
||||
= order.email
|
||||
%td
|
||||
= order.bill_address.full_name_for_sorting
|
||||
= order&.bill_address.full_name_for_sorting
|
||||
%td.align-center
|
||||
%span
|
||||
= order.display_total
|
||||
|
||||
@@ -149,6 +149,33 @@ module Api
|
||||
.map{ |o| o[:id] }).to eq serialized_orders([order2, order3, order1, order4])
|
||||
.map{ |o| o["id"] }
|
||||
end
|
||||
|
||||
context "with an order without billing address" do
|
||||
let!(:order7) {
|
||||
create(:order_with_line_items, billing_address: nil, order_cycle: order_cycle,
|
||||
distributor: distributor)
|
||||
}
|
||||
|
||||
it 'can show orders without bill address' do
|
||||
get :index, params: { q: {} },
|
||||
as: :json
|
||||
|
||||
expect(json_response['orders']
|
||||
.map{ |o| o[:id] }).to match_array serialized_orders([order2, order3, order1, order4,
|
||||
order7])
|
||||
.map{ |o|
|
||||
o["id"]
|
||||
}
|
||||
end
|
||||
|
||||
it 'can sort orders by bill_address.lastname' do
|
||||
get :index, params: { q: { s: 'bill_address_lastname ASC' } },
|
||||
as: :json
|
||||
expect(json_response['orders']
|
||||
.map{ |o| o[:id] }).to eq serialized_orders([order2, order3, order1, order4, order7])
|
||||
.map{ |o| o["id"] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with pagination' do
|
||||
|
||||
Reference in New Issue
Block a user