From f24af3feb0d01bd4b0ec36a3c8e7ff3176cb783c Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Tue, 11 Jul 2023 09:41:01 +0100 Subject: [PATCH] extract invoice printing logic into a seperated method --- app/jobs/bulk_invoice_job.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/jobs/bulk_invoice_job.rb b/app/jobs/bulk_invoice_job.rb index fba3dde99f..b16443fb6b 100644 --- a/app/jobs/bulk_invoice_job.rb +++ b/app/jobs/bulk_invoice_job.rb @@ -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