Skip to content

Commit

Permalink
New field 'name' in PostalAddress and sevel usability improvements
Browse files Browse the repository at this point in the history
 * PostalAddress#name and Shipment#contact_phone_number initializated
   with info from user's profile.
 * Cosmetic improvements in shipment form
 * More understable translations for some fields and states
 * Added user and event to shipments#show
  • Loading branch information
ancorgs committed Aug 25, 2014
1 parent 4d2d1eb commit 778027f
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 18 deletions.
3 changes: 1 addition & 2 deletions app/controllers/shipments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ def create
def new
@shipment ||= Shipment.new(params[:shipment])
@shipment.event = Event.find(params[:event_id])
@shipment.build_postal_address if @shipment.postal_address.nil?
@shipment.postal_address.country_code ||= @shipment.event.country_code
@shipment.user = current_user
@shipment.populate_contact_info
authorize! :create, @shipment
new!
end
Expand Down
19 changes: 19 additions & 0 deletions app/models/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ def can_cancel?
[:incomplete, :requested, :approved].include? state.to_sym
end

# Populate some fields with information read from the event and the user
# profile, creating the associated PostalAddress object if it's missing
#
# @param [User] contact user to read the information from. By default, the one
# associated to the request.
def populate_contact_info(contact = self.user)
self.build_postal_address if postal_address.nil?
postal_address.country_code ||= event.country_code unless event.nil?
if contact
profile = contact.profile
# Phone number
self.contact_phone_number ||= profile.phone_number
self.contact_phone_number = profile.second_phone_number if contact_phone_number.blank?
# Name
postal_address.name ||= profile.full_name
postal_address.name = contact.nickname if postal_address.name.blank?
end
end

protected

def ensure_postal_address
Expand Down
7 changes: 4 additions & 3 deletions app/views/shipments/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
- unless resource.errors[:event_id].empty?
%div.alert.alert-error= resource.errors[:event_id].join("<br>")

%strong.label= Shipment.human_attribute_name(:type)
%strong.label= Shipment.human_attribute_name(:shipment_type)
%br
%strong= resource.type
%strong= resource.shipment_type
= simple_form_for resource do |f|
%strong.label= t(:general_info)
%br
Expand All @@ -19,8 +19,9 @@
%br
= f.simple_fields_for :postal_address do |a|
.form-inputs.form-horizontal
= a.input :name
= a.input :line1
= a.input :line2
= a.input :line2, :as => :text
= a.input :city
= a.input :county
= a.input :postal_code
Expand Down
4 changes: 2 additions & 2 deletions app/views/shipments/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
%th= sort_link(@q, :id)
%th= model_class.human_attribute_name(:user)
%th= model_class.human_attribute_name(:event)
%th= model_class.human_attribute_name(:type)
%th= model_class.human_attribute_name(:shipment_type)
%th= sort_link(@q, :state)
%tbody
- collection.each do |resource|
%tr{:id => "shipment-#{resource.id}"}
%td.id= link_to "#{resource.label}", resource
%td.user= resource.user.try(:title)
%td.event= resource.event.try(:name)
%td.type= resource.type
%td.shipment_type= resource.shipment_type
%td.state= timestamped_state(resource)

= paginate collection
6 changes: 5 additions & 1 deletion app/views/shipments/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
= r.attribute :state do
= state_info(r.object)
%div.alert-info= resource.human_state_guide
= r.attribute :shipment_type
.span6
= r.attribute :type
= r.association :event do
= render resource.event
= r.association :user do
= render resource.user
.row-fluid
.span12
= r.attribute :description
Expand Down
11 changes: 6 additions & 5 deletions config/locales/models.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ en:
accepted: "The reimbursement process has started or can be started using the 'ask for reimbursement' button (if the reimbursement period is open)."
approved: "Now the requester has to accept the conditions or roll the request back to propose different ones."
canceled: "The request have been canceled and cannot be longer modified."
incomplete: "The requester must update the request with all the relevant information. Afterwards, the request must be explicitly submitted."
incomplete: "The requester must review all the information to ensure it is present and correct and then submit the request using the 'Action' button in the request page."
submitted: "The request is being evaluated. The responsible people can adjust some values and approve it or can roll it back (again to incomplete state) if the requester needs to correct something."
request_expense:
one: "expense"
Expand Down Expand Up @@ -115,7 +115,7 @@ en:
state_guides:
approved: "The reimbursement will be now processed by the administrative to start the payment process."
canceled: "The reimbursement has been canceled and cannot be longer modified."
incomplete: "The requester must update the reimbursement with all the relevant information. Afterwards, the reimbursement must be explicitly submitted."
incomplete: "The requester must review all the information to ensure it is present and correct and then submit the reimbursement using the 'Action' button in the reimbursement page."
payed: "The process have ended succesfully."
processed: "The reimbursement must be confirmed after completing the payment."
submitted: "The reimbursement is being evaluated. It will be approved or rolled back (again to incomplete state) whether the requester needs to correct something."
Expand All @@ -141,7 +141,7 @@ en:
state_guides:
approved: "It will be now sent by the shipper."
canceled: "The request has been canceled and cannot be longer modified."
incomplete: "The requester must update all the relevant information. Afterwards, the request must be explicitly submitted."
incomplete: "The requester must review all the information to ensure it is present and correct and then submit the request using the 'Action' button in the request page."
requested: "The request is being evaluated. It will be approved or rolled back (again to incomplete state) whether the requester needs to correct something."
received: "The requester has received the shipment. Final state."
sent: "After actually receiving it, the requester must confirm the shipment in the application."
Expand Down Expand Up @@ -213,6 +213,7 @@ en:
notes: "notes"
file: "file"
postal_address:
name: "name"
line1: "line 1"
line2: "line 2"
city: "city"
Expand Down Expand Up @@ -337,13 +338,13 @@ en:
zip_code: "ZIP code"
shipment:
contact_phone_number: "contact phone #"
description: "description"
description: "additional notes"
postal_address: "delivery address"
event: "event"
event_id: "event"
history: "history"
state: "state"
type: "type"
shipment_type: "type"

state_machines:
events:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140825120840_add_name_to_postal_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameToPostalAddress < ActiveRecord::Migration
def change
add_column :postal_addresses, :name, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140718101718) do
ActiveRecord::Schema.define(version: 20140825120840) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -149,6 +149,7 @@
t.string "country_code"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
end

create_table "reimbursement_attachments", force: true do |t|
Expand Down
2 changes: 1 addition & 1 deletion spec/features/reimbursement_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
fill_in "notes", :with => "Sorry Mr. Idestroyedthedeathstar: no invoices, no money"
click_button "roll back"
page.should have_content "Successfully rolled back."
page.should have_content "requester must update the reimbursement with all the relevant information"
page.should have_content "requester must review all the information to ensure it is present and correct"
page.should_not have_link "Attach signed document"

# Log in as requester
Expand Down
2 changes: 1 addition & 1 deletion spec/features/request_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
end
click_button "Create travel support request"
page.should have_content "request was successfully created"
page.should have_content "request must be explicitly submitted."
page.should have_content "then submit the request using the 'Action' button"
@request = Request.order(:created_at, :id).last

# Testing audits, just in case
Expand Down
4 changes: 2 additions & 2 deletions spec/features/shipment_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
fill_in "shipment_postal_address_attributes_line1", :with => "Send it to the base."
click_button "Create shipment request"
page.should have_content "shipment request was successfully created"
page.should have_content "request must be explicitly submitted."
page.should have_content "then submit the request using the 'Action' button"
@shipment = Shipment.order(:created_at, :id).last

# Testing audits, just in case
Expand Down Expand Up @@ -45,7 +45,7 @@
click_button "roll back"
page.should have_content "Successfully rolled back"
page.should have_content "from submitted to incomplete"
page.should have_content "requester must update all the relevant information"
page.should have_content "requester must review all the information to ensure it is present and correct"

# Log in as requester
click_link "Log out"
Expand Down

0 comments on commit 778027f

Please sign in to comment.