mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +00:00
Merge pull request #11696 from abdellani/sequential-invoice-numbers-per-distributor
Sequential invoice numbers per distributor
This commit is contained in:
@@ -26,4 +26,8 @@ class Invoice < ApplicationRecord
|
||||
def cancel_previous_invoices
|
||||
order.invoices.where.not(id:).update_all(cancelled: true)
|
||||
end
|
||||
|
||||
def display_number
|
||||
"#{order.distributor.id}-#{number}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,8 +5,8 @@ class Invoice
|
||||
include ::ActionView::Helpers::NumberHelper
|
||||
attr_reader :invoice
|
||||
|
||||
delegate :data, to: :invoice
|
||||
delegate :number, :date, to: :invoice, prefix: true
|
||||
delegate :display_number, :data, to: :invoice
|
||||
delegate :date, to: :invoice, prefix: true
|
||||
|
||||
FINALIZED_NON_SUCCESSFUL_STATES = %w(canceled returned).freeze
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class OrderInvoiceGenerator
|
||||
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?
|
||||
@@ -31,4 +31,8 @@ class OrderInvoiceGenerator
|
||||
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
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
%td.align-center.created_at
|
||||
= invoice.presenter.display_date
|
||||
%td.align-center.label
|
||||
= invoice.number
|
||||
= invoice.display_number
|
||||
%td.align-center.label
|
||||
= invoice.presenter.total
|
||||
%td.align-center.label
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
%td{ :align => "left" }
|
||||
%br
|
||||
= "#{t :invoice_number}:"
|
||||
= @order.invoice_number
|
||||
= @order.display_number
|
||||
%br
|
||||
= t :invoice_issued_on
|
||||
= l @order.invoice_date
|
||||
|
||||
@@ -1078,10 +1078,11 @@ describe '
|
||||
].join(" ").upcase
|
||||
}
|
||||
|
||||
let(:invoice_number){ "#{order.distributor_id}-1" }
|
||||
let(:table_contents) {
|
||||
[
|
||||
Invoice.first.created_at.strftime('%B %d, %Y').to_s,
|
||||
"1",
|
||||
invoice_number,
|
||||
"0.0",
|
||||
"Active",
|
||||
"Download"
|
||||
|
||||
@@ -170,10 +170,13 @@ describe '
|
||||
describe 'listing invoices' do
|
||||
let(:date){ Time.current.to_date }
|
||||
|
||||
let(:first_invoice){ "#{distributor.id}-1" }
|
||||
let(:second_invoice){ "#{distributor.id}-2" }
|
||||
|
||||
let(:row1){
|
||||
[
|
||||
I18n.l(date, format: :long),
|
||||
"2",
|
||||
second_invoice,
|
||||
order.total,
|
||||
"Active",
|
||||
"Download"
|
||||
@@ -183,7 +186,7 @@ describe '
|
||||
let(:row2){
|
||||
[
|
||||
I18n.l(date, format: :long),
|
||||
"1",
|
||||
first_invoice,
|
||||
order.total,
|
||||
"Cancelled",
|
||||
"Download"
|
||||
|
||||
Reference in New Issue
Block a user