From f694d8c23800785d994696514e808ac590433ed3 Mon Sep 17 00:00:00 2001 From: Louis Knapp Date: Sat, 5 Dec 2015 17:01:57 -0600 Subject: [PATCH] lk | client completion date is merged into client pickup date --- app/controllers/bikes_controller.rb | 7 ------- app/controllers/clients_controller.rb | 7 +++++-- app/models/bike.rb | 5 ----- app/models/client.rb | 4 ++-- app/views/clients/_fields.html.haml | 5 ----- app/views/freecyclery/closed_applications.html.haml | 2 +- app/views/freecyclery/ready_for_pickup.html.haml | 2 -- config/routes.rb | 1 - .../20151205223152_remove_completion_date_from_client.rb | 5 +++++ db/schema.rb | 2 +- lib/tasks/dummydata.rake | 1 - spec/models/client_spec.rb | 2 +- 12 files changed, 15 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20151205223152_remove_completion_date_from_client.rb diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index ae25673..aa64556 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -67,13 +67,6 @@ class BikesController < ApplicationController end end - def mark_picked_up - @bike = Bike.find(params[:id]) - @bike.mark_picked_up - flash[:notice] = @bike.name + ' was marked as picked up' - redirect_to action: "ready_for_pickup", controller: "freecyclery" - end - private def set_bike @bike = Bike.find(params[:id]) diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 9cfcb8f..d65e6ed 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -24,7 +24,11 @@ class ClientsController < ApplicationController def update if @client.update(client_params) - redirect_to edit_client_url(@client), notice: 'Client was successfully updated.' + notice = 'Client was successfully updated.' + unless @client.bike.update_attribute(:date_sold, @client.pickup_date) + notice = "Unable to update client's bike sale date" + end + redirect_to edit_client_url(@client), notice: notice else render action: 'edit' end @@ -46,7 +50,6 @@ class ClientsController < ApplicationController :weight, :helmet, :lock, - :completion_date, :bike_id, :will_pay, :bike_type_requested, diff --git a/app/models/bike.rb b/app/models/bike.rb index f5a54ae..e124093 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -43,11 +43,6 @@ class Bike < ActiveRecord::Base all_freecyclery_bikes - assigned_bikes end - def mark_picked_up - current_date = Time.new.strftime("%Y-%m-%d") - self.update_attribute(:date_sold, current_date) - end - def post_to_bike_index return true if self.bike_index_id.present? BikeIndexLogger.perform_async(self.id) diff --git a/app/models/client.rb b/app/models/client.rb index 151119e..a5b523a 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -7,7 +7,7 @@ class Client < ActiveRecord::Base def self.waiting_list clients = Client.all non_voided_clients = clients.select{|client| !client.application_voided} - waiting_list_with_null_application_dates = non_voided_clients.select{|client| !client.completion_date} + waiting_list_with_null_application_dates = non_voided_clients.select{|client| !client.pickup_date} clients_with_bikes = Client.all.select{|c| !c.bike_id.nil?} waiting_list = waiting_list_with_null_application_dates.select{|client| !client.application_date.nil?} - clients_with_bikes waiting_list.sort_by!{|client| client.application_date} @@ -18,7 +18,7 @@ class Client < ActiveRecord::Base end def self.closed_applications - Client.all.select{|client| client.application_voided || client.completion_date} + Client.all.select{|client| client.application_voided || client.pickup_date} end def bike diff --git a/app/views/clients/_fields.html.haml b/app/views/clients/_fields.html.haml index 67d5ff9..7784e9c 100644 --- a/app/views/clients/_fields.html.haml +++ b/app/views/clients/_fields.html.haml @@ -60,11 +60,6 @@ .col-sm-10 = f.check_box :lock, disabled: disabled - .form-group - = f.label "Completion Date:", class: "col-sm-2 control-label" - .col-sm-10 - = f.text_field :completion_date, class: "form-control datepicker", disabled: disabled - .form-group = f.label "Bike:", class: "col-sm-2 control-label" .col-sm-10 diff --git a/app/views/freecyclery/closed_applications.html.haml b/app/views/freecyclery/closed_applications.html.haml index 2535fff..cdbd65f 100644 --- a/app/views/freecyclery/closed_applications.html.haml +++ b/app/views/freecyclery/closed_applications.html.haml @@ -14,6 +14,6 @@ %tr %td= client.name %td= client.application_voided - %td= client.completion_date + %td= client.pickup_date %td= link_to 'Edit', edit_client_path(client) %br diff --git a/app/views/freecyclery/ready_for_pickup.html.haml b/app/views/freecyclery/ready_for_pickup.html.haml index 4ea2d4c..2891f95 100644 --- a/app/views/freecyclery/ready_for_pickup.html.haml +++ b/app/views/freecyclery/ready_for_pickup.html.haml @@ -7,11 +7,9 @@ %tr %th Bike %th Client - %th %tbody - @bikes_for_pickup.each do |bike| %tr %td= bike.name %td= bike.client.name - %td= button_to "Mark as picked up", {controller: "bikes", action: "mark_picked_up", id: bike.id}, method: :patch, class: "btn btn-default" diff --git a/config/routes.rb b/config/routes.rb index c97c09a..f2c2701 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,6 @@ Bikedb::Application.routes.draw do get 'print_labels' => 'bikes#print_labels', on: :collection get 'freecyclery_pickup' => 'bikes#freecyclery_pickup', on: :collection patch 'mark_as_sold' => 'bikes#mark_as_sold', on: :member - patch 'mark_picked_up' => 'bikes#mark_picked_up', on: :member end resources :volunteers diff --git a/db/migrate/20151205223152_remove_completion_date_from_client.rb b/db/migrate/20151205223152_remove_completion_date_from_client.rb new file mode 100644 index 0000000..6bc272f --- /dev/null +++ b/db/migrate/20151205223152_remove_completion_date_from_client.rb @@ -0,0 +1,5 @@ +class RemoveCompletionDateFromClient < ActiveRecord::Migration + def change + remove_column :clients, :completion_date + end +end diff --git a/db/schema.rb b/db/schema.rb index 7960cc3..12dfe27 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151013231450) do +ActiveRecord::Schema.define(version: 20151205223152) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/lib/tasks/dummydata.rake b/lib/tasks/dummydata.rake index 7cec439..6d562c7 100644 --- a/lib/tasks/dummydata.rake +++ b/lib/tasks/dummydata.rake @@ -35,7 +35,6 @@ namespace :db do weight: rand(100) + 100, helmet: [true, false].sample, lock: [true, false].sample, - completion_date: [rand(30.days).ago, nil].sample, bike_type_requested: ["Cruiser", "Road", "Mountain"].sample, will_pay: [true, false].sample, notes: "A great client!", diff --git a/spec/models/client_spec.rb b/spec/models/client_spec.rb index 5bb82ab..7f9bf56 100644 --- a/spec/models/client_spec.rb +++ b/spec/models/client_spec.rb @@ -14,7 +14,7 @@ describe Client do end it "does not include completed clients" do - create(:client, completion_date: 1.week.ago) + create(:client, pickup_date: 1.week.ago) expect(Client.waiting_list).to be_empty end end