mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
remove bulk invoice service
This commit is contained in:
@@ -12,7 +12,7 @@ module Spree
|
||||
|
||||
def show
|
||||
invoice_id = params[:id]
|
||||
invoice_pdf = BulkInvoiceService.new.filepath(invoice_id)
|
||||
invoice_pdf = filepath(invoice_id)
|
||||
|
||||
send_file(invoice_pdf, type: 'application/pdf', disposition: :inline)
|
||||
end
|
||||
@@ -23,6 +23,12 @@ module Spree
|
||||
OrderInvoiceGenerator.new(@order).generate_or_update_latest_invoice
|
||||
redirect_back(fallback_location: spree.admin_dashboard_path)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def filepath(invoice_id)
|
||||
"tmp/invoices/#{invoice_id}.pdf"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BulkInvoiceService
|
||||
attr_reader :id
|
||||
|
||||
def initialize
|
||||
@id = new_invoice_id
|
||||
end
|
||||
|
||||
def start_pdf_job(order_ids)
|
||||
BulkInvoiceJob.perform_later order_ids, "#{file_directory}/#{@id}.pdf"
|
||||
end
|
||||
|
||||
def invoice_created?(invoice_id)
|
||||
File.exist? filepath(invoice_id)
|
||||
end
|
||||
|
||||
def filepath(invoice_id)
|
||||
"#{directory}/#{invoice_id}.pdf"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def new_invoice_id
|
||||
Time.zone.now.to_i.to_s
|
||||
end
|
||||
|
||||
def directory
|
||||
'tmp/invoices'
|
||||
end
|
||||
|
||||
def file_directory
|
||||
Dir.mkdir(directory) unless File.exist?(directory)
|
||||
directory
|
||||
end
|
||||
end
|
||||
@@ -1,56 +0,0 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
require 'spec_helper'
|
||||
require 'spree/payment_methods_helper'
|
||||
|
||||
describe BulkInvoiceService do
|
||||
include ActiveJob::TestHelper
|
||||
include Spree::PaymentMethodsHelper
|
||||
|
||||
let(:service) { BulkInvoiceService.new }
|
||||
|
||||
describe "#start_pdf_job" do
|
||||
it "starts a background process to create a pdf with multiple invoices" do
|
||||
expect do
|
||||
service.start_pdf_job [1, 2]
|
||||
end.to enqueue_job BulkInvoiceJob
|
||||
end
|
||||
|
||||
it "creates a PDF invoice" do
|
||||
order = create(:completed_order_with_fees)
|
||||
order.bill_address = order.ship_address
|
||||
order.save!
|
||||
|
||||
perform_enqueued_jobs do
|
||||
service.start_pdf_job([order.id])
|
||||
end
|
||||
|
||||
expect(service.invoice_created?(service.id)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
describe "#invoice_created?" do
|
||||
context "when the invoice has been created" do
|
||||
it "returns true" do
|
||||
allow(File).to receive(:exist?).and_return(true)
|
||||
|
||||
created = service.invoice_created? '45891723'
|
||||
expect(created).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context "when the invoice has not been created" do
|
||||
it "returns false" do
|
||||
created = service.invoice_created? '1234567'
|
||||
expect(created).to_not be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#filepath" do
|
||||
it "returns the filepath of a given invoice" do
|
||||
filepath = service.filepath '1234567'
|
||||
expect(filepath).to eq 'tmp/invoices/1234567.pdf'
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user