mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
extract invoice printing logic into a seperated method
This commit is contained in:
@@ -5,13 +5,7 @@ class BulkInvoiceJob < ApplicationJob
|
||||
delegate :render, to: ActionController::Base
|
||||
|
||||
def perform(order_ids, filepath, options = {})
|
||||
pdf = CombinePDF.new
|
||||
|
||||
sorted_orders(order_ids).each do |order|
|
||||
invoice = renderer.render_to_string(order)
|
||||
|
||||
pdf << CombinePDF.parse(invoice)
|
||||
end
|
||||
sorted_orders(order_ids).each(&method(:generate_invoice))
|
||||
|
||||
ensure_directory_exists filepath
|
||||
|
||||
@@ -32,6 +26,11 @@ class BulkInvoiceJob < ApplicationJob
|
||||
@renderer ||= InvoiceRenderer.new
|
||||
end
|
||||
|
||||
def generate_invoice order
|
||||
invoice = renderer.render_to_string(order)
|
||||
pdf << CombinePDF.parse(invoice)
|
||||
end
|
||||
|
||||
def broadcast(filepath, channel)
|
||||
file_id = filepath.split("/").last.split(".").first
|
||||
|
||||
@@ -47,4 +46,8 @@ class BulkInvoiceJob < ApplicationJob
|
||||
def ensure_directory_exists(filepath)
|
||||
FileUtils.mkdir_p(File.dirname(filepath))
|
||||
end
|
||||
|
||||
def pdf
|
||||
@pdf ||= CombinePDF.new
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user