diff --git a/app/reflexes/admin/orders_reflex.rb b/app/reflexes/admin/orders_reflex.rb index dedf46cdf28..c37508785fd 100644 --- a/app/reflexes/admin/orders_reflex.rb +++ b/app/reflexes/admin/orders_reflex.rb @@ -33,19 +33,9 @@ def ship end def bulk_invoice(params) - visible_orders = editable_orders.invoiceable.where(id: params[:bulk_ids]) + visible_orders = bulk_load_orders(params) - if Spree::Config.enterprise_number_required_on_invoices? - distributors_without_abn = Enterprise.where( - id: visible_orders.select(:distributor_id), - abn: nil, - ) - - if distributors_without_abn.exists? - render_business_number_required_error(distributors_without_abn) - return - end - end + return if notify_if_abn_related_issue(visible_orders) cable_ready.append( selector: "#orders-index", @@ -134,5 +124,35 @@ def render_business_number_required_error(distributors) enterprise_name: distributor_names.join(", ")) morph_admin_flashes end + + def bulk_load_orders(params) + editable_orders.invoiceable.where(id: params[:bulk_ids]) + end + + def notify_if_abn_related_issue(orders) + return false unless abn_required? + + distributors = distributors_without_abn(orders) + return false if distributors.empty? + + render_business_number_required_error(distributors) + true + end + + def abn_required? + Spree::Config.enterprise_number_required_on_invoices? + end + + def distributors_without_abn(orders) + abn = if OpenFoodNetwork::FeatureToggle.enabled?(:invoices) + [nil, ""] + else + [nil] + end + Enterprise.where( + id: orders.select(:distributor_id), + abn:, + ) + end end end diff --git a/spec/system/admin/orders/bulk_actions_spec.rb b/spec/system/admin/orders/bulk_actions_spec.rb index 17fdc62575a..4393a06c09e 100644 --- a/spec/system/admin/orders/bulk_actions_spec.rb +++ b/spec/system/admin/orders/bulk_actions_spec.rb @@ -420,7 +420,6 @@ end context "with legal invoices feature", feature: :invoices do - before { pending("#12373") } it_behaves_like "should not print the invoice" end end