Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort correctly in Bulk Order Managment #10451

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/serializers/api/admin/order_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module Api
module Admin
class OrderSerializer < ActiveModel::Serializer
attributes :id, :number, :user_id, :full_name, :email, :phone, :completed_at, :display_total,
attributes :id, :number, :user_id, :full_name, :email, :phone, :completed_at,
:completed_at_utc_iso8601, :display_total,
:edit_path, :state, :payment_state, :shipment_state,
:payments_path, :ready_to_ship, :ready_to_capture, :created_at,
:distributor_name, :special_instructions, :display_outstanding_balance,
Expand Down Expand Up @@ -73,6 +74,10 @@ def item_count
object.line_items.count
end

def completed_at_utc_iso8601
object.completed_at.blank? ? "" : object.completed_at.utc.iso8601
end

private

def spree_routes_helper
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/orders/bulk_management.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
%a{ :href => '', 'ng-click' => "sorting.toggle('order.phone')" }
= t("admin.phone")
%th.date{ 'ng-show' => 'columns.order_date.visible' }
%a{ :href => '', 'ng-click' => "sorting.toggle('order.completed_at')" }
%a{ :href => '', 'ng-click' => "sorting.toggle('order.completed_at_utc_iso8601')" }
= t("admin.orders.bulk_management.order_date")
%th.producer{ 'ng-show' => 'columns.producer.visible' }
%a{ :href => '', 'ng-click' => "sorting.toggle('supplier.name')" }
Expand Down
21 changes: 19 additions & 2 deletions spec/system/admin/bulk_order_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,27 @@
context "displaying the list of line items" do
let!(:o1) {
create(:order_with_distributor, state: 'complete', shipment_state: 'ready',
completed_at: Time.zone.now )
completed_at: Time.zone.parse('2022-05-05 15:30:45'))
}
let!(:o2) {
create(:order_with_distributor, state: 'complete', shipment_state: 'ready',
completed_at: Time.zone.now )
completed_at: Time.zone.parse('2022-04-26 15:10:45'))
}
let!(:o21) {
create(:order_with_distributor, state: 'complete', shipment_state: 'ready',
completed_at: Time.zone.parse('2022-08-04 09:10:45'))
}
let!(:o22) {
create(:order_with_distributor, state: 'complete', shipment_state: 'ready',
completed_at: Time.zone.parse('2022-06-07 09:10:45'))
}
let!(:o3) { create(:order_with_distributor, state: 'address', completed_at: nil ) }
let!(:o4) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) }
let!(:o5) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) }
let!(:li1) { create(:line_item_with_shipment, order: o1) }
let!(:li2) { create(:line_item_with_shipment, order: o2) }
let!(:li21) { create(:line_item_with_shipment, order: o21) }
let!(:li22) { create(:line_item_with_shipment, order: o22) }
let!(:li3) { create(:line_item, order: o3 ) }
let!(:li4) { create(:line_item_with_shipment, order: o4) }
let!(:li5) { create(:line_item_with_shipment, order: o5) }
Expand All @@ -57,6 +67,13 @@
expect(page).to have_no_selector "tr#li_#{li4.id}"
expect(page).to have_no_selector "tr#li_#{li5.id}"
end

it "orders by completion date" do
find("a", text: 'COMPLETED AT').click # sets ascending ordering
expect(page).to have_content(/#{li2.product.name}.*#{li1.product.name}.*#{li22.product.name}.*#{li21.product.name}/m)
find("a", text: 'COMPLETED AT').click # sets descending ordering
expect(page).to have_content(/#{li21.product.name}.*#{li22.product.name}.*#{li1.product.name}.*#{li2.product.name}/m)
end
end

context "pagination" do
Expand Down