Skip to content

Commit

Permalink
update the invoice number calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
abdellani committed Oct 21, 2023
1 parent c1e611a commit bd8460d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/services/order_invoice_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def generate_or_update_latest_invoice
if comparator.can_generate_new_invoice?
order.invoices.create!(
date: Time.zone.today,
number: order.invoices.count + 1,
number: total_invoices_created_by_distributor + 1,
data: invoice_data
)
elsif comparator.can_update_latest_invoice?
Expand All @@ -31,4 +31,8 @@ def comparator
def invoice_data
@invoice_data ||= InvoiceDataGenerator.new(order).generate
end

def total_invoices_created_by_distributor
Invoice.joins(:order).where(order: { distributor: order.distributor }).count
end
end

0 comments on commit bd8460d

Please sign in to comment.