From f509f85327860e8a00b174446af20c12b0b3701d Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Wed, 11 Oct 2017 15:53:58 +0200 Subject: [PATCH] Save the timestamp of the last mail to supplier and confirm resending it --- app/controllers/orders_controller.rb | 1 + app/views/orders/show.html.haml | 4 +++- config/locales/de.yml | 1 + config/locales/en.yml | 1 + db/migrate/20171001000000_add_last_sent_mail_to_order.rb | 5 +++++ db/schema.rb | 3 ++- 6 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20171001000000_add_last_sent_mail_to_order.rb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 222b8f26..e788d9bd 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -118,6 +118,7 @@ class OrdersController < ApplicationController def send_result_to_supplier order = Order.find(params[:id]) Mailer.order_result_supplier(@current_user, order).deliver_now + order.update!(last_sent_mail: Time.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) diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index dd9353a5..9bc936f4 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -87,7 +87,9 @@ = 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' + = link_to t('.send_to_supplier'), send_result_to_supplier_order_path(@order), method: :post, + class: "btn#{' btn-primary' unless @order.last_sent_mail}", + data: {confirm: @order.last_sent_mail && t('.confirm_send_to_supplier', when: format_time(@order.last_sent_mail)) } = receive_button @order - unless @order.closed? = link_to t('ui.delete'), @order, data: {confirm: t('.confirm_delete')}, method: :delete, diff --git a/config/locales/de.yml b/config/locales/de.yml index c5ea160a..a3942e90 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1444,6 +1444,7 @@ de: confirm_end: |- Willst Du wirklich die Bestellung %{order} beenden? Es gibt kein zurück. + confirm_send_to_supplier: Die Bestellung wurde bereit am %{when} zur Lieferantin geschickt. Willst du sie wirklich erneut schicken? create_invoice: Rechnung anlegen description1_order: "%{state} Bestellung von %{supplier} angelegt von %{who}," description1_period: diff --git a/config/locales/en.yml b/config/locales/en.yml index 58cdc8ca..b4d388e0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1454,6 +1454,7 @@ en: confirm_end: |- Do you really want to close the order %{order}? There is no going back. + confirm_send_to_supplier: The order has been sent to the supplier already on %{when}. Do you really want to send it again? create_invoice: Add invoice description1_order: "%{state} order from %{supplier} opened by %{who}," description1_period: diff --git a/db/migrate/20171001000000_add_last_sent_mail_to_order.rb b/db/migrate/20171001000000_add_last_sent_mail_to_order.rb new file mode 100644 index 00000000..d21b0ed9 --- /dev/null +++ b/db/migrate/20171001000000_add_last_sent_mail_to_order.rb @@ -0,0 +1,5 @@ +class AddLastSentMailToOrder < ActiveRecord::Migration + def change + add_column :orders, :last_sent_mail, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 0f850f6c..52540fa3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170801000000) do +ActiveRecord::Schema.define(version: 20171001000000) do create_table "article_categories", force: :cascade do |t| t.string "name", limit: 255, default: "", null: false @@ -243,6 +243,7 @@ ActiveRecord::Schema.define(version: 20170801000000) do t.datetime "boxfill" t.date "pickup" t.integer "invoice_id" + t.datetime "last_sent_mail" end add_index "orders", ["state"], name: "index_orders_on_state", using: :btree