Skip to content

Commit

Permalink
Merge pull request #5659 from dmarcoux/issue-5555
Browse files Browse the repository at this point in the history
Filter orders on inclusive dates in admin/orders
  • Loading branch information
luisramos0 authored Jul 9, 2020
2 parents ed91500 + 3dfabdc commit cc3361a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, Reque
$scope.fetchResults()

$scope.fetchResults = (page=1) ->
startDateWithTime = $scope.appendStringIfNotEmpty($scope['q']['completed_at_gteq'], ' 00:00:00')
endDateWithTime = $scope.appendStringIfNotEmpty($scope['q']['completed_at_lteq'], ' 23:59:59')

$scope.resetSelected()
params = {
'q[completed_at_lt]': $scope['q']['completed_at_lt'],
'q[completed_at_gt]': $scope['q']['completed_at_gt'],
'q[completed_at_gteq]': startDateWithTime,
'q[completed_at_lteq]': endDateWithTime,
'q[state_eq]': $scope['q']['state_eq'],
'q[number_cont]': $scope['q']['number_cont'],
'q[email_cont]': $scope['q']['email_cont'],
Expand All @@ -43,6 +46,11 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, Reque
}
RequestMonitor.load(Orders.index(params).$promise)

$scope.appendStringIfNotEmpty = (baseString, stringToAppend) ->
return baseString unless baseString

baseString + stringToAppend

$scope.resetSelected = ->
$scope.selected_orders.length = 0
$scope.selected = false
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/orders/_filters.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
.date-range-filter.field
= label_tag nil, t(:date_range)
.date-range-fields
= text_field_tag "q[completed_at_gt]", nil, class: 'datepicker', datepicker: 'q.completed_at_gt', 'ng-model' => 'q.completed_at_gt', :placeholder => t(:start)
= text_field_tag "q[completed_at_gteq]", nil, class: 'datepicker', datepicker: 'q.completed_at_gteq', 'ng-model' => 'q.completed_at_gteq', :placeholder => t(:start)
%span.range-divider
%i.icon-arrow-right
= text_field_tag "q[completed_at_lt]", nil, class: 'datepicker', datepicker: 'q.completed_at_lt', 'ng-model' => 'q.completed_at_lt', :placeholder => t(:stop)
= text_field_tag "q[completed_at_lteq]", nil, class: 'datepicker', datepicker: 'q.completed_at_lteq', 'ng-model' => 'q.completed_at_lteq', :placeholder => t(:stop)
.field
= label_tag nil, t(:status)
= select_tag("q[state_eq]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ describe "ordersCtrl", ->
expect(Orders.index).toHaveBeenCalledWith(jasmine.objectContaining({
'q[order_cycle_id_in][]': ['4', '5']
}))

it "filters orders on inclusive dates", ->
$scope['q']['completed_at_gteq'] = '2020-06-08'
$scope['q']['completed_at_lteq'] = '2020-06-09'

$scope.fetchResults()

expect(Orders.index).toHaveBeenCalledWith(jasmine.objectContaining({
'q[completed_at_gteq]': '2020-06-08 00:00:00'
'q[completed_at_lteq]': '2020-06-09 23:59:59'
}))

0 comments on commit cc3361a

Please sign in to comment.