-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert 1550 refactor/create distributions (#1580)
* refactor: show the items that exceed available inventory (#1550) * Revert "refactor: show the items that exceed available inventory (#1550)" This reverts commit 9b065ea. * Re-enable distribution storage location totals, which weren't working. Makes JS slightly easier to read by removing ES shorthand. Uses sanitize instead of raw for alert output. Make error alerts not auto-hide. * Fix #update action. Extracts some insufficiency language to a method. Slight refactoring of the Service objects. Add better UI feedback to the edit & new actions, which required a tweaks to #update and #create * Minor style fixes in flash and redirects in distributions controller * Fixes several failing specs. * Adds ADRs. Creates an ADR about making the application fully-public * Fixes failing specs. Had to make a bunch pending because of capybara weirdness not being able to click on buttons. * Rubocop fixes. Specs are passing now after a rebase. Updates annotations. * Removes unnecessary requirements from the beginnings of some specs. Creates a new spec for the Distribution creation service. * Changes map...to_h to index_by to satisfy rubocop * Whitespace removal * Removes ADR files (wrong app) and fixes whitespace in JS * Update rubocop YML not to follow a cop that violates something we need, fixes whitespace. * Removes 2 unused methods from DistributionsController * Adds newline to .rspec. Removes a commented out line from distributions controller * Adds a space for styling to application.js * Fix wording in distribution system spec Co-authored-by: Gabriel Belgamo <[email protected]>
- Loading branch information
Showing
33 changed files
with
206 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--color | ||
--require rails_helper | ||
--format=documentation | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,44 @@ | ||
class DistributionUpdateService | ||
attr_reader :distribution, :error | ||
|
||
def initialize(old_distribution, new_distribution_params) | ||
@distribution = old_distribution | ||
@params = new_distribution_params | ||
@organization = @distribution.organization | ||
@error = nil | ||
end | ||
|
||
# FIXME: This doesn't allow for the storage location to be changed. | ||
def call | ||
@distribution.transaction do | ||
old_issued_at = @distribution.issued_at | ||
@old_issued_at = @distribution.issued_at | ||
@distribution.storage_location.increase_inventory(@distribution.to_a) | ||
|
||
# Delete the line items -- they'll be replaced later | ||
@distribution.line_items.each(&:destroy!) | ||
@distribution.reload | ||
|
||
# Replace the current distribution with the new parameters | ||
@distribution.update! @params | ||
@distribution.reload | ||
new_issued_at = @distribution.issued_at | ||
@new_issued_at = @distribution.issued_at | ||
# Apply the new changes to the storage location inventory | ||
@distribution.storage_location.decrease_inventory(@distribution.to_a) | ||
OpenStruct.new(success?: true, distribution: @distribution, | ||
resend_notification?: resend_notification?(old_issued_at, new_issued_at)) | ||
end | ||
rescue Errors::InsufficientAllotment => e | ||
@distribution.line_items.assign_insufficiency_errors(e.insufficient_items) | ||
Rails.logger.error "[!] DistributionsController#update failed because of Insufficient Allotment #{@organization.short_name}: #{@distribution.errors.full_messages} [#{e.message}]" | ||
@error = e | ||
rescue StandardError => e | ||
Rails.logger.error "[!] DistributionsController#update failed to update distribution for #{@distribution.organization.short_name}: #{@distribution.errors.full_messages} [#{e.inspect}]" | ||
OpenStruct.new(success: false, distribution: @distribution, error: e) | ||
ensure | ||
return self | ||
end | ||
|
||
private | ||
def success? | ||
@error.nil? | ||
end | ||
|
||
def resend_notification?(old_issued_at, new_issued_at) | ||
old_issued_at.to_date != new_issued_at.to_date | ||
def resend_notification? | ||
@old_issued_at.to_date != @new_issued_at.to_date | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.