Skip to content

Commit

Permalink
improve all_distributors_can_invoice?
Browse files Browse the repository at this point in the history
  • Loading branch information
abdellani committed Feb 19, 2024
1 parent f582bff commit 618f232
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/reflexes/admin/orders_reflex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def ship

def bulk_invoice(params)
visible_orders = editable_orders.where(id: params[:bulk_ids]).filter(&:invoiceable?)
return unless all_distributors_can_invoice?(visible_orders)
if Spree::Config.enterprise_number_required_on_invoices? &&
!all_distributors_can_invoice?(visible_orders)
render_business_number_required_error
return
end

cable_ready.append(
selector: "#orders-index",
Expand Down Expand Up @@ -111,14 +115,14 @@ def set_param_for_controller
end

def all_distributors_can_invoice?(orders)
distributors = orders.map(&:distributor).uniq.reject(&:can_invoice?)

return true if distributors.empty?
distributor_ids = orders.map(&:distributor_id)
Enterprise.where(id: distributor_ids, abn: nil).empty?
end

def render_business_number_required_error
flash[:error] = I18n.t(:must_have_valid_business_number,
enterprise_name: distributors.map(&:name).join(", "))
morph_admin_flashes
false
end
end
end

0 comments on commit 618f232

Please sign in to comment.