Files
openfoodnetwork/app/controllers/spree/admin/invoices_controller.rb
David Cook e62b640372 Poll to check when invoice file finished
The BulkInvoiceJob already sends a notification via WebSockets once complete, but sometimes that fails. So this is added on top, just in case.
2024-07-05 08:58:10 +10:00

42 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module Spree
module Admin
class InvoicesController < Spree::Admin::BaseController
respond_to :json
def index
@order = Spree::Order.find_by(number: params[:order_id])
authorize! :invoice, @order
end
def show
invoice_id = params[:id]
invoice_pdf = filepath(invoice_id)
send_file(invoice_pdf, type: 'application/pdf', disposition: :inline)
rescue ActionController::MissingFile
render "errors/not_found", status: :not_found, formats: :html
end
def generate
@order = Order.find_by(number: params[:order_id])
if @order.distributor.can_invoice?
authorize! :invoice, @order
::Orders::GenerateInvoiceService.new(@order).generate_or_update_latest_invoice
else
flash[:error] = t(:must_have_valid_business_number,
enterprise_name: @order.distributor.name)
end
redirect_back(fallback_location: spree.admin_dashboard_path)
end
private
def filepath(invoice_id)
"tmp/invoices/#{invoice_id}.pdf"
end
end
end
end