Add a button to send the order to the supplier
This commit is contained in:
parent
b4ce8c31cc
commit
f27bbc2ffa
7 changed files with 65 additions and 0 deletions
|
|
@ -114,6 +114,15 @@ class OrdersController < ApplicationController
|
|||
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?
|
||||
|
|
|
|||
|
|
@ -49,6 +49,23 @@ class Mailer < ActionMailer::Base
|
|||
subject: 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 = {})
|
||||
@user = user
|
||||
@order = order
|
||||
@supplier = order.supplier
|
||||
|
||||
add_order_result_attachments order, options
|
||||
|
||||
subject = 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
|
||||
|
||||
mail to: order.supplier.email,
|
||||
cc: user,
|
||||
reply_to: user,
|
||||
subject: subject
|
||||
end
|
||||
|
||||
# Notify user if account balance is less than zero
|
||||
def negative_balance(user,transaction)
|
||||
@group = user.ordergroup
|
||||
|
|
@ -117,4 +134,10 @@ class Mailer < ActionMailer::Base
|
|||
MailDeliveryStatus.create email: message.to[0], message: error.message
|
||||
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
app/views/mailer/order_result_supplier.text.haml
Normal file
1
app/views/mailer/order_result_supplier.text.haml
Normal file
|
|
@ -0,0 +1 @@
|
|||
= raw t '.text', user: show_user(@user), foodcoop: FoodsoftConfig[:name]
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue