From 85ddd0220a872c4f69342bcd66f16b391a3321fb Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Mon, 11 Dec 2023 09:42:55 +0100 Subject: [PATCH] check ABN before bulk printing --- app/reflexes/admin/orders_reflex.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/reflexes/admin/orders_reflex.rb b/app/reflexes/admin/orders_reflex.rb index 765438d7cc3f..8aaeb48dfee2 100644 --- a/app/reflexes/admin/orders_reflex.rb +++ b/app/reflexes/admin/orders_reflex.rb @@ -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") @@ -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