mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-16 04:24:23 +00:00
Preventing double creation of invoices by recognising completed invoices within the specifed period
This commit is contained in:
@@ -18,7 +18,6 @@ Spree.user_class.class_eval do
|
||||
|
||||
validate :limit_owned_enterprises
|
||||
|
||||
|
||||
def known_users
|
||||
if admin?
|
||||
Spree::User.scoped
|
||||
@@ -49,10 +48,9 @@ Spree.user_class.class_eval do
|
||||
owned_enterprises(:reload).size < enterprise_limit
|
||||
end
|
||||
|
||||
def current_invoice
|
||||
start_of_current_billing_period = (Time.now - 1.day).beginning_of_month
|
||||
existing = orders.where('distributor_id = (?) AND created_at >= (?) AND completed_at IS NULL',
|
||||
Spree::Config[:accounts_distributor_id], start_of_current_billing_period).first
|
||||
def invoice_for(start_date, end_date)
|
||||
existing = orders.where('distributor_id = (?) AND created_at >= (?) AND created_at < (?)',
|
||||
Spree::Config[:accounts_distributor_id], start_date, end_date).first
|
||||
existing || orders.new(distributor_id: Spree::Config[:accounts_distributor_id])
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user