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

Needed to set to draft when editing r & t quantities. #809

Merged
merged 1 commit into from
Dec 13, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/dashboard/visits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class Dashboard::VisitsController < Dashboard::BaseController
# Used for x-editable update and validations
def update
@visit = Visit.find( params[:id] )
admin = params[:service_request_id] ? false : true

if @visit.update_attributes( params[:visit] )
@visit.line_items_visit.sub_service_request.set_to_draft(@admin)
render nothing: true
else
render json: @visit.errors, status: :unprocessable_entity
Expand Down
8 changes: 1 addition & 7 deletions app/controllers/service_calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def update
@consolidated = false
@pages = eval(params[:pages])

update_sub_service_request_status(visit.line_items_visit.sub_service_request, @admin)
visit.line_items_visit.sub_service_request.set_to_draft(@admin)

if params[:checked] == 'true'
unit_minimum = visit.line_items_visit.line_item.service.displayed_pricing_map.unit_minimum
Expand Down Expand Up @@ -236,10 +236,4 @@ def setup_calendar_pages
@pages[arm.id] = @service_request.set_visit_page(new_page, arm)
end
end

def update_sub_service_request_status(sub_service_request, admin)
if !admin && sub_service_request.status != 'draft'
sub_service_request.update_attributes(status: 'draft')
end
end
end
6 changes: 6 additions & 0 deletions app/models/sub_service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ def find_editable_id(id)
end
end

def set_to_draft(admin)
if !admin && status != 'draft'
self.update_attributes(status: 'draft')
end
end

# If the ssr can't be edited AND it's a request that restricts editing AND there are multiple ssrs under it's service request
# (no need to create a new sr if there's only one ssr) AND it's previous status was an editable one
# AND it's new status is an uneditable one, then create a new sr and place the ssr under it. Probably don't need the last condition.
Expand Down