Skip to content

Commit

Permalink
Add a button to send the order to the supplier
Browse files Browse the repository at this point in the history
  • Loading branch information
paroga committed Aug 11, 2017
1 parent af1243e commit fd44518
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ def finish
redirect_to orders_url, alert: I18n.t('errors.general_msg', :msg => error.message)
end

# Send a order to the supplier.
def send_result_to_supplier
order = Order.find(params[:id])
Mailer.order_result_supplier(@current_user, order).deliver_now
redirect_to order, notice: I18n.t('orders.send_to_supplier.notice')
rescue => error
redirect_to order, alert: I18n.t('errors.general_msg', :msg => error.message)
end

def receive
@order = Order.find(params[:id])
unless request.post?
Expand Down
27 changes: 26 additions & 1 deletion app/mailers/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ def order_result(user, group_order)
:subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.order_result.subject', :name => group_order.order.name)
end

# Sends order result to the supplier
def order_result_supplier(user, order, options = {})
set_foodcoop_scope
@user = user
@order = order
@supplier = order.supplier

add_order_result_attachments order, options

subject = "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.order_result_supplier.subject', :name => order.supplier.name)
subject += " (#{I18n.t('activerecord.attributes.order.pickup')}: #{format_date(order.pickup)})" if order.pickup
user_email = "#{show_user user} <#{user.email}>"

mail :to => order.supplier.email,
:cc => user_email,
:reply_to => user_email,
:subject => subject
end

# Notify user if account balance is less than zero
def negative_balance(user,transaction)
set_foodcoop_scope
Expand Down Expand Up @@ -94,5 +113,11 @@ def set_foodcoop_scope(foodcoop = FoodsoftConfig.scope)
end
ActionMailer::Base.default_url_options[:foodcoop] = foodcoop
end


# separate method to allow plugins to mess with the attachments
def add_order_result_attachments(order, options = {})
attachments['order.pdf'] = OrderFax.new(order, options).to_pdf
attachments['order.csv'] = OrderCsv.new(order, options).to_csv
end

end
1 change: 1 addition & 0 deletions app/views/mailer/order_result_supplier.text.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= raw t '.text', user: show_user(@user), foodcoop: FoodsoftConfig[:name]
1 change: 1 addition & 0 deletions app/views/orders/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
= link_to t('.stock_order'), new_group_order_path(:order_id => @order.id, :stock_order => true), class: 'btn'
= link_to t('ui.edit'), edit_order_path(@order), class: 'btn'
- elsif not @order.closed? and not @order.stockit?
= link_to t('.send_to_supplier'), send_result_to_supplier_order_path(@order), method: :post, class: 'btn btn-primary'
= receive_button @order
- unless @order.closed?
= link_to t('ui.delete'), @order, data: {confirm: t('.confirm_delete')}, method: :delete,
Expand Down
15 changes: 15 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,18 @@ de:
die Bestellung für "%{order}" wurde am %{when} von %{user} beendet.
Für Euch wurden die folgenden Artikel bestellt:
text1: "o Gesamtpreis: %{sum}\n\nBestellung online einsehen: %{order_url}\n\n\nViele Grüße von %{foodcoop} "
order_result_supplier:
subject: Neue Bestellung für %{name}
text: |
Guten Tag,
die Foodcoop %{foodcoop} möchte gerne eine Bestellung abgeben.
Im Anhang befinden sich ein PDF und eine CSV-Tabelle.
Mit freundlichen Grüßen
%{user}
%{foodcoop}
reset_password:
subject: Neues Password für %{username}
text: |-
Expand Down Expand Up @@ -1411,6 +1423,8 @@ de:
submit: Bestellung in Empfang nehmen
surplus_options: 'Verteilungsoptionen:'
title: "»%{order}« in Empfang nehmen"
send_to_supplier:
notice: Die Bestellung wurde an die Lieferantin geschickt.
show:
action_end: Beenden!
amounts: 'Netto/Bruttosumme:'
Expand Down Expand Up @@ -1445,6 +1459,7 @@ de:
default: Suche nach Artikeln ...
groups: Suche nach Bestellgruppen ...
search_reset: Suche zurücksetzen
send_to_supplier: An Lieferantin schicken
show_invoice: Rechnung anzeigen
sort_article: Sortiert nach Artikeln
sort_group: Sortiert nach Gruppen
Expand Down
15 changes: 15 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,18 @@ en:
Kind regards from %{foodcoop}.
order_result_supplier:
subject: New order for %{name}
text: |
Hi!
Foodcoop %{foodcoop} would like to place an order.
Please find a PDF and spreadsheet attached.
Kind regards,
%{user}
%{foodcoop}
reset_password:
subject: New password for %{username}
text: |
Expand Down Expand Up @@ -1420,6 +1432,8 @@ en:
submit: Receive order
surplus_options: 'Distribution options:'
title: Receiving %{order}
send_to_supplier:
notice: The order has been sent to the supplier.
show:
action_end: Close!
amounts: 'Net/gross sum:'
Expand Down Expand Up @@ -1454,6 +1468,7 @@ en:
default: Search for articles...
groups: Search for ordergroups...
search_reset: Reset search
send_to_supplier: Send to supplier
show_invoice: Show invoice
sort_article: Sorted in articles
sort_group: Sorted in groups
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
member do
post :finish
post :add_comment
post :send_result_to_supplier

get :receive
post :receive
Expand Down

0 comments on commit fd44518

Please sign in to comment.