Skip to content

Commit

Permalink
check ABN before bulk printing
Browse files Browse the repository at this point in the history
  • Loading branch information
abdellani committed Dec 11, 2023
1 parent f6ba2dc commit 85ddd02
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/reflexes/admin/orders_reflex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def ship
end

def bulk_invoice(params)
return unless all_orders_invoiceable?(params[:bulk_ids])

cable_ready.append(
selector: "#orders-index",
html: render(partial: "spree/admin/orders/bulk/invoice_modal")
Expand Down Expand Up @@ -96,5 +98,19 @@ def success(i18n_key, count)
def editable_orders
Permissions::Order.new(current_user).editable_orders
end

def all_orders_invoiceable?(order_ids)
distributors = editable_orders.where(id: order_ids).filter do |o|
!o.distributor.can_invoice?
end.map(&:distributor).uniq

return true if distributors.empty?

distributors.each do |d|
flash[:error] = I18n.t(:must_have_valid_business_number, enterprise_name: d.name)
morph_admin_flashes
end
false
end
end
end

0 comments on commit 85ddd02

Please sign in to comment.