add orders without billing address to SearchOrders#fetch_orders' results

This commit is contained in:
Mohamed ABDELLANI
2023-08-07 19:18:01 +01:00
committed by Maikel Linke
parent 7414b5cbc9
commit 04312b05c6
3 changed files with 39 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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