From 37f13caf93d6912fc07ac4748dc256a20b61dfa2 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Tue, 17 Dec 2024 17:56:58 +0100 Subject: [PATCH] change the way to load invoice with subscriptions --- app/services/invoices/refresh_draft_service.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/invoices/refresh_draft_service.rb b/app/services/invoices/refresh_draft_service.rb index 8fa6a33b738..095ca6e7649 100644 --- a/app/services/invoices/refresh_draft_service.rb +++ b/app/services/invoices/refresh_draft_service.rb @@ -51,10 +51,9 @@ def call refresh: true ).raise_if_error! - # TODO: instead of invoice.reload, do the full request to the DB with includes to have preloaded relationships: - # invoice = Invoice.find(invoice.id).includes(invoice_subscriptions: :subscription) + invoice = Invoice.includes(invoice_subscriptions: :subscription).find(result.invoice.id) calculate_result = Invoices::CalculateFeesService.call( - invoice: invoice.reload, + invoice: invoice, recurring:, context: ) @@ -103,7 +102,8 @@ def fetch_timestamp def invoice_credit_note_items CreditNoteItem .joins(:credit_note) - .where(credit_note: {invoice_id: invoice.id}).includes(:fee) + .where(credit_note: {invoice_id: invoice.id}) + .includes(:fee) end def flag_lifetime_usage_for_refresh