Skip to content

Commit

Permalink
courier feature ready for testing on production
Browse files Browse the repository at this point in the history
  • Loading branch information
chiramiso committed Dec 12, 2014
1 parent 8826bed commit 3588eae
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ paypal_adaptive.yml

# mac DS_Store
*.DS_Store
config/courier.yml
4 changes: 4 additions & 0 deletions app/assets/stylesheets/email/email.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ hr {
.line-item-group {
overflow: hidden;
margin-bottom: 1.3em;

.Button--with-margin {
margin-bottom: 0.5em;
}
}

.seller-imprint-container {
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/business_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def set_transport_ready

if @business_transaction.prepare
CartMailer.delay.courier_notification(@business_transaction.line_item_group)
notice = 'Du hast erfolgreich den Versandstatus geändert.'
notice = I18n.t('transaction.notice.ready_success', id: @business_transaction.line_item_group_purchase_id)
else
notice = 'Bei Ändern des Versandstatuses ist ein Fehler aufgetreten. Entweder hast Du ihn schon bestätigt...'
notice = I18n.t('transaction.notice.ready_failure', id: @business_transaction.line_item_group_purchase_id)
end

redirect_to line_item_group_path(@business_transaction.line_item_group), notice: notice
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/cart_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CartMailer < ActionMailer::Base
include MailerHelper
before_filter :inline_logos
before_filter :inline_logos, except: :courier_notification

default from: $email_addresses['default']
layout 'email'
Expand Down
8 changes: 0 additions & 8 deletions app/mailers/courier_mailer.rb

This file was deleted.

26 changes: 13 additions & 13 deletions app/models/business_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BusinessTransaction < ActiveRecord::Base
:vacationing?, :cancellation_form,
to: :article_seller, prefix: true
delegate :url, to: :article_seller_cancellation_form, prefix: true
delegate :payment_address, :transport_address, to: :line_item_group
delegate :payment_address, :transport_address, :purchase_id, to: :line_item_group
#delegate :buyer, :seller, to: :line_item_group


Expand Down Expand Up @@ -125,24 +125,24 @@ def refunded?
refunded_fee && refunded_fair
end

private

# Custom conditions for validations
#
def bike_courier_selected?
self.selected_transport == 'bike_courier'
end

def transport_address_in_area?
unless $courier['zip'].split(' ').include?(self.transport_address_zip)
errors.add(:selected_transport, I18n.t('transaction.errors.transport_address_not_in_area'))
private

# Custom conditions for validations
#
def transport_address_in_area?
unless $courier['zip'].split(' ').include?(self.transport_address_zip)
errors.add(:selected_transport, I18n.t('transaction.errors.transport_address_not_in_area'))
end
end
end

def right_time_frame_for_bike_courier?
unless self.seller.pickup_time.include? self.bike_courier_time
errors.add(:bike_courier_time, I18n.t('transaction.errors.wrong_time_frame'))
def right_time_frame_for_bike_courier?
unless self.seller.pickup_time.include? self.bike_courier_time
errors.add(:bike_courier_time, I18n.t('transaction.errors.wrong_time_frame'))
end
end
end

end
2 changes: 1 addition & 1 deletion app/models/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class LineItem < ActiveRecord::Base
attr_accessor :cart_cookie # temp storage to validate with pundit

delegate :id, to: :cart, prefix: true
delegate :quantity, :quantity_available, :price, :title,
delegate :quantity, :quantity_available, :price, :title, :transport_bike_courier,
to: :article, prefix: true

belongs_to :line_item_group, inverse_of: :line_items
Expand Down
3 changes: 0 additions & 3 deletions app/models/opening_time.rb

This file was deleted.

4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ def pickup_time
if day[0] == day_of_week
for hour in 8..19 do
if hour >= Time.now.hour
times.push "#{ day[1] } #{ hour + 2 }:00 bis #{ hour + 3 }:00"
unless (hour + 3) > 20
times.push "#{ day[1] } #{ hour + 2 }:00 bis #{ hour + 3 }:00"
end
end
end
elsif day[0] > day_of_week
Expand Down
4 changes: 0 additions & 4 deletions app/models/user/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,5 @@ module User::Associations
has_many :hearted_libraries, through: :hearts, source: :heartable, source_type: 'Library'

has_attached_file :cancellation_form

# Opening times
has_one :opening_time, foreign_key: 'user_id'

end
end
2 changes: 1 addition & 1 deletion app/objects/abaci/payment_abacus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def initialize_payment payment, bts
def add_single_transports_to_payment payment, business_transactions

business_transactions.each do |bt|
transport = @transport_abacus.single_transports[bt]
transport = @transport_abacus.single_transports[bt] unless bt.selected_transport == 'bike_courier'
@payments[payment][:transports] << transport if transport
end
end
Expand Down
9 changes: 6 additions & 3 deletions app/views/cart_mailer/_article.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
h4
| Gesamtpreis
= "#{bt.article_price * bt.quantity_bought}€"
- if bt.article.transport_bike_courier && role == 'buyer'
- if bt.bike_courier_selected? == 'bike_courier' && role == 'buyer'
.message
| "Dieser Artikel wird per Fahrradkurier geliefert. Bitte halte zum Lieferzeitpunkt die Lieferkosten von #{ humanized_money_with_symbol Money.new($courier['price']) } in bar bereit."
- if bt.article.transport_bike_courier && role == 'seller'
center
| "Dieser Artikel wird per Fahrradkurier geliefert. Bitte halte zum Lieferzeitpunkt die Lieferkosten von #{ humanized_money_with_symbol Money.new($courier['price']) } in bar bereit."
br
= link_to "Hier findest Du die AGB von #{ $courier['name'] }", attachments[$courier['tos']].url
- if bt.bike_courier_selected? && role == 'seller'
.message
| "Für diesen Artikel wurde die Versandart Fahrradkurier gewählt, bitte verpacke ihn umgehend und bestätige durch Drücken des Buttons, dass der Artikel zum Versand bereit ist. Erst dann wird der Kurierdienst benachrichtigt."
4 changes: 2 additions & 2 deletions app/views/cart_mailer/seller_email.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ p
- @line_item_group.business_transactions.each do |bt|
= render 'article', bt: bt, role: 'seller'
center
- if bt.selected_transport == 'bike_courier'
- if bt.bike_courier_selected?
br
= link_to 'Sendung als versandfertig markieren', set_transport_ready_url(bt.id), class: 'Button'
= link_to 'Sendung als versandfertig markieren', set_transport_ready_url(bt.id), class: 'Button Button--with-margin'

- abacus = Abacus.new(@line_item_group)
= render 'donations', abacus: abacus, role: 'seller'
Expand Down
2 changes: 1 addition & 1 deletion app/views/carts/checkout/_courier_step.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.fa.fa-bicycle
.middle
= t.input :bike_courier_time, as: :select, collection: line_item.business_transaction.article.seller.pickup_time
= t.input :tos_bike_courier_accepted, required: false, label: "Die Lieferkosten in Höhe von #{ humanized_money_with_symbol(Money.new($courier['price'])) } zahle ich bar bei Lieferung, und ich akzeptiere die AGB und Widerrufsbelehrung des Kurierdienstes."
= t.input :tos_bike_courier_accepted, required: false, label: "Die Lieferkosten in Höhe von #{ humanized_money_with_symbol(Money.new($courier['price'])) } zahle ich bar bei Lieferung, und ich akzeptiere die ".html_safe + link_to('AGB', "/assets/#{ $courier['tos'] }", target: 'blank') + " des Kurierdienstes.".html_safe
.right
= t.input :bike_courier_message, required: false, input_html: { rows: 4 }

2 changes: 1 addition & 1 deletion app/views/carts/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
span.unified_transport_impossible
= t('cart.texts.unified_transport_impossible')

- if line_item.article.transport_bike_courier
- if line_item.article_transport_bike_courier
= render 'carts/checkout/courier_step', line_item: line_item, line_item_fields: line_item_fields

.warning
Expand Down
2 changes: 1 addition & 1 deletion app/views/carts/overview.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
= render '/line_item_groups/abacus/transport_row', abacus: abacus, transport: transport
= render '/line_item_groups/abacus/cash_on_delivery_row', cash_on_delivery_total: hash[:cash_on_delivery_total]
= render '/line_item_groups/abacus/total_row', total: hash[:total], payment: payment
= render '/line_item_groups/abacus/bike_courier_row', bike_courier_total: hash[:bike_courier_total]
= render '/line_item_groups/abacus/bike_courier_row', bike_courier_total: $courier['price']
.addresses_preview
.payment_address
= gray_box t('cart.texts.addresses.payment') do
Expand Down
14 changes: 4 additions & 10 deletions app/views/categories/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
.Category-index.Grid-mansory
- @categories.each do |category|

.Category-index-parent.Category-Grid

h2
a href: category_path(category)
= category.name
= link_to category.name, category_path(category)
ul
- category.children.each do |child1|
li
a href: category_path(child1)
= child1.name
= link_to child1.name, category_path(child1)
ul
- child1.children.each do |child2|
li
a href: category_path(child2)
= child2.name
= link_to child2.name, category_path(child2)
ul
- child2.children.each do |child3|
li
a href: category_path(child3)
= child3.name
= link_to child3.name, category_path(child3)
11 changes: 11 additions & 0 deletions config/courier.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
courier:
name: 'Kurierdienst'
address: "Kurierdienst der Stadt\nGleisbauer Str. 42\n10999 Berlin"
email: 'kurier@kurier.com'
price: '1180'
measure_1: '60x42x5cm'
measure_2: '40x30x20cm'
max_weight: '5kg'
times: 'Mo, 09:00 - 20:00; Di, 09:00 - 20:00; Mi, 09:00 - 20:00; Do, 09:00 - 20:00, Fr, 09:00 - 20:00'
tos: 'fahrwerk_kurierkollektiv_agb.pdf'
zip: "10115 10117 10119 10178 10179 10243 10245 10247 10249 10405 10407 10435 10437 10551 10553 10555 10557 10559 10585 10587 10589 10623 10625 10627 10629 10707 10709 10711 10713 10715 10717 10719 10777 10779 10781 10783 10785 10787 10789 10823 10825 10827 10829 10961 10963 10965 10967 10969 10997 10999 13355 12101 12101 12047 12045 12043 12053 12049"
2 changes: 2 additions & 0 deletions config/locales/transaction/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,5 @@ de:
notice:
paypal_success: "Vielen Dank, die Zahlung wurde ausgeführt."
paypal_cancel: "Die PayPal-Zahlung wurde abgebrochen. Bitte versuche es noch einmal."
ready_success: 'Du hast die Auftrag mit der Transaktionsnummer %{ id } als versandfertig markiert.'
ready_failure: 'Der Auftrag mit der Transaktionsnummer %{ id } konnte nicht als versandfertig markiert werden. Dies kann u.a. daran liegen, dass der Status schon einmal verändert wurde.'
17 changes: 0 additions & 17 deletions db/migrate/20141201080901_create_opening_times.rb

This file was deleted.

13 changes: 0 additions & 13 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,19 +429,6 @@

add_index "notices", ["user_id"], name: "index_notices_on_user_id", using: :btree

create_table "opening_times", force: true do |t|
t.integer "user_id", limit: 8
t.string "monday"
t.string "tuesday"
t.string "wednesday"
t.string "thursday"
t.string "friday"
t.string "saturday"
t.string "sunday"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "payments", force: true do |t|
t.string "pay_key"
t.string "state"
Expand Down
24 changes: 18 additions & 6 deletions test/mailers/cart_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@
mail.must deliver_to(user.email)
end

it 'sends email to buyer' do
cart = FactoryGirl.create(:cart, :with_line_item_groups_from_legal_entity, user: FactoryGirl.create(:user), sold: true)
user = cart.user
mail = CartMailer.buyer_email(cart)
mail.must deliver_to(user.email)
describe 'CartMailer#buyer_email' do
let(:cart) { FactoryGirl.create(:cart, :with_line_item_groups_from_legal_entity, user: FactoryGirl.create(:user), sold: true) }

it 'sends email to buyer' do
user = cart.user
mail = CartMailer.buyer_email(cart)
mail.must deliver_to(user.email)
end

it 'must contain courier terms when at least one transaction has selected_transport bike_courier' do
bt = FactoryGirl.create :business_transaction, line_item_group_id: cart.line_item_groups.first.id
BusinessTransaction.any_instance.stubs(:selected_transport).returns('bike_courier')
mail = CartMailer.buyer_email(cart)

# Attachment
attachment = mail.attachments['fahrwerk_kurierkollektiv_agb.pdf']
attachment.filename.must_equal 'fahrwerk_kurierkollektiv_agb.pdf'
end
end

it 'sends email to courier service' do
Expand Down Expand Up @@ -51,6 +64,5 @@
# Info about Transaction
mail.must have_body_text(business_transaction.bike_courier_time)
mail.must have_body_text(business_transaction.bike_courier_message)

end
end
25 changes: 0 additions & 25 deletions test/models/opening_time_test.rb

This file was deleted.

1 change: 0 additions & 1 deletion test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
it { subject.must have_one(:image) }
it { subject.must have_many(:seller_line_item_groups) }
it { subject.must have_many(:buyer_line_item_groups) }
it { subject.must have_one(:opening_time) }
end

describe "validations" do
Expand Down

0 comments on commit 3588eae

Please sign in to comment.