diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6476dd4b70..7babb1147a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -198,7 +198,7 @@ Only take multiple issues if they are related and you can solve all of them at t Users that are frequent contributors and are involved in discussion (join the slack channel! :)) may be given direct Contributor access to the Repo so they can submit Pull Requests directly instead of Forking first. ## Debugging -If starting server directly, via `rail s` or `rail console`, or built-in debugger in RubyMine, or running `bundle exec rspec path/to/spec.rb:line_no`, then you can use `binding.pry` to debug. Drop the pry where you want the execution to pause. +If starting server directly, via `rails s` or `rails console`, or built-in debugger in RubyMine, or running `bundle exec rspec path/to/spec.rb:line_no`, then you can use `binding.pry` to debug. Drop the pry where you want the execution to pause. If starting via Procfile with `bin/start`, then drop a ``binding.remote_pry`` into the line where you want execution to pause at. Then run ``pry-remote`` in the terminal to connect to it. https://github.com/Mon-Ouie/pry-remote diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index ce5677da0c..2315a67486 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -8,6 +8,11 @@ def index .undiscarded .during(helpers.selected_range) .class_filter(filter_params) + + if params[:include_cancelled] + @requests = @requests.with_discarded + end + @unfulfilled_requests_count = current_organization.requests.where(status: [:pending, :started]).during(helpers.selected_range).class_filter(filter_params).count @paginated_requests = @requests.includes(:partner).page(params[:page]) @calculate_product_totals = RequestsTotalItemsService.new(requests: @requests).calculate @@ -20,6 +25,7 @@ def index @selected_request_item = filter_params[:by_request_item_id] @selected_partner = filter_params[:by_partner] @selected_status = filter_params[:by_status] + @include_cancelled = params[:include_cancelled] respond_to do |format| format.html diff --git a/app/models/request.rb b/app/models/request.rb index 9d54f11fab..6c4590975b 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -31,13 +31,15 @@ class Request < ApplicationRecord accepts_nested_attributes_for :item_requests, allow_destroy: true, reject_if: proc { |attributes| attributes["quantity"].blank? } has_many :child_item_requests, through: :item_requests - enum :status, { pending: 0, started: 1, fulfilled: 2, discarded: 3 }, prefix: true + enum :status, { pending: 0, started: 1, fulfilled: 2, cancelled: 3 }, prefix: true enum :request_type, %w[quantity individual child].map { |v| [v, v] }.to_h validates :distribution_id, uniqueness: true, allow_nil: true validate :item_requests_uniqueness_by_item_id validate :not_completely_empty - validate :cannot_change_status_once_fulfilled, on: :update + validate :cannot_change_status_once_fulfilled, + :cannot_change_status_once_cancelled, + on: :update after_validation :sanitize_items_data @@ -93,4 +95,10 @@ def cannot_change_status_once_fulfilled errors.add(:status, "cannot be changed once fulfilled") end end + + def cannot_change_status_once_cancelled + if status_changed? && status_was == "cancelled" + errors.add(:status, "cannot be changed once cancelled") + end + end end diff --git a/app/services/request_destroy_service.rb b/app/services/request_destroy_service.rb index 1aeb9d6019..09e8b33f6a 100644 --- a/app/services/request_destroy_service.rb +++ b/app/services/request_destroy_service.rb @@ -11,7 +11,7 @@ def call request.discarded_at = Time.current request.discard_reason = reason - request.status = :discarded + request.status = :cancelled request.save! unless request.partner.deactivated? @@ -29,7 +29,7 @@ def valid? if request.blank? errors.add(:base, 'request_id is invalid') elsif request.discarded_at.present? - errors.add(:base, 'request already discarded') + errors.add(:base, 'request already cancelled') end errors.none? diff --git a/app/views/requests/_request_row.html.erb b/app/views/requests/_request_row.html.erb index 58b4fdc3df..66af59903d 100644 --- a/app/views/requests/_request_row.html.erb +++ b/app/views/requests/_request_row.html.erb @@ -22,7 +22,9 @@