Browse Source

lk | client completion date is merged into client pickup date

master
Louis Knapp 9 years ago
parent
commit
f694d8c238
  1. 7
      app/controllers/bikes_controller.rb
  2. 7
      app/controllers/clients_controller.rb
  3. 5
      app/models/bike.rb
  4. 4
      app/models/client.rb
  5. 5
      app/views/clients/_fields.html.haml
  6. 2
      app/views/freecyclery/closed_applications.html.haml
  7. 2
      app/views/freecyclery/ready_for_pickup.html.haml
  8. 1
      config/routes.rb
  9. 5
      db/migrate/20151205223152_remove_completion_date_from_client.rb
  10. 2
      db/schema.rb
  11. 1
      lib/tasks/dummydata.rake
  12. 2
      spec/models/client_spec.rb

7
app/controllers/bikes_controller.rb

@ -67,13 +67,6 @@ class BikesController < ApplicationController
end end
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 private
def set_bike def set_bike
@bike = Bike.find(params[:id]) @bike = Bike.find(params[:id])

7
app/controllers/clients_controller.rb

@ -24,7 +24,11 @@ class ClientsController < ApplicationController
def update def update
if @client.update(client_params) 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 else
render action: 'edit' render action: 'edit'
end end
@ -46,7 +50,6 @@ class ClientsController < ApplicationController
:weight, :weight,
:helmet, :helmet,
:lock, :lock,
:completion_date,
:bike_id, :bike_id,
:will_pay, :will_pay,
:bike_type_requested, :bike_type_requested,

5
app/models/bike.rb

@ -43,11 +43,6 @@ class Bike < ActiveRecord::Base
all_freecyclery_bikes - assigned_bikes all_freecyclery_bikes - assigned_bikes
end 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 def post_to_bike_index
return true if self.bike_index_id.present? return true if self.bike_index_id.present?
BikeIndexLogger.perform_async(self.id) BikeIndexLogger.perform_async(self.id)

4
app/models/client.rb

@ -7,7 +7,7 @@ class Client < ActiveRecord::Base
def self.waiting_list def self.waiting_list
clients = Client.all clients = Client.all
non_voided_clients = clients.select{|client| !client.application_voided} 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?} 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 = waiting_list_with_null_application_dates.select{|client| !client.application_date.nil?} - clients_with_bikes
waiting_list.sort_by!{|client| client.application_date} waiting_list.sort_by!{|client| client.application_date}
@ -18,7 +18,7 @@ class Client < ActiveRecord::Base
end end
def self.closed_applications 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 end
def bike def bike

5
app/views/clients/_fields.html.haml

@ -60,11 +60,6 @@
.col-sm-10 .col-sm-10
= f.check_box :lock, disabled: disabled = 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 .form-group
= f.label "Bike:", class: "col-sm-2 control-label" = f.label "Bike:", class: "col-sm-2 control-label"
.col-sm-10 .col-sm-10

2
app/views/freecyclery/closed_applications.html.haml

@ -14,6 +14,6 @@
%tr %tr
%td= client.name %td= client.name
%td= client.application_voided %td= client.application_voided
%td= client.completion_date %td= client.pickup_date
%td= link_to 'Edit', edit_client_path(client) %td= link_to 'Edit', edit_client_path(client)
%br %br

2
app/views/freecyclery/ready_for_pickup.html.haml

@ -7,11 +7,9 @@
%tr %tr
%th Bike %th Bike
%th Client %th Client
%th
%tbody %tbody
- @bikes_for_pickup.each do |bike| - @bikes_for_pickup.each do |bike|
%tr %tr
%td= bike.name %td= bike.name
%td= bike.client.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"

1
config/routes.rb

@ -12,7 +12,6 @@ Bikedb::Application.routes.draw do
get 'print_labels' => 'bikes#print_labels', on: :collection get 'print_labels' => 'bikes#print_labels', on: :collection
get 'freecyclery_pickup' => 'bikes#freecyclery_pickup', on: :collection get 'freecyclery_pickup' => 'bikes#freecyclery_pickup', on: :collection
patch 'mark_as_sold' => 'bikes#mark_as_sold', on: :member patch 'mark_as_sold' => 'bikes#mark_as_sold', on: :member
patch 'mark_picked_up' => 'bikes#mark_picked_up', on: :member
end end
resources :volunteers resources :volunteers

5
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

2
db/schema.rb

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"

1
lib/tasks/dummydata.rake

@ -35,7 +35,6 @@ namespace :db do
weight: rand(100) + 100, weight: rand(100) + 100,
helmet: [true, false].sample, helmet: [true, false].sample,
lock: [true, false].sample, lock: [true, false].sample,
completion_date: [rand(30.days).ago, nil].sample,
bike_type_requested: ["Cruiser", "Road", "Mountain"].sample, bike_type_requested: ["Cruiser", "Road", "Mountain"].sample,
will_pay: [true, false].sample, will_pay: [true, false].sample,
notes: "A great client!", notes: "A great client!",

2
spec/models/client_spec.rb

@ -14,7 +14,7 @@ describe Client do
end end
it "does not include completed clients" do 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 expect(Client.waiting_list).to be_empty
end end
end end

Loading…
Cancel
Save