mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
use Invoice#latest to fetch the most recent invoice
This commit is contained in:
@@ -9,6 +9,10 @@ class Invoice < ApplicationRecord
|
||||
after_create :cancel_previous_invoices
|
||||
default_scope { order(created_at: :desc) }
|
||||
|
||||
def self.latest
|
||||
reorder(created_at: :desc).first
|
||||
end
|
||||
|
||||
def presenter
|
||||
@presenter ||= Invoice::DataPresenter.new(self)
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class OrderInvoiceGenerator
|
||||
data: invoice_data
|
||||
)
|
||||
elsif comparator.can_update_latest_invoice?
|
||||
order.invoices.first.update!(
|
||||
order.invoices.latest.update!(
|
||||
date: Time.zone.today,
|
||||
data: invoice_data
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user