Skip to content

Commit

Permalink
notify if any distributors doesn't have an abn
Browse files Browse the repository at this point in the history
  • Loading branch information
abdellani committed Jun 24, 2024
1 parent c4470f7 commit a3fd7b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
44 changes: 32 additions & 12 deletions app/reflexes/admin/orders_reflex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion spec/system/admin/orders/bulk_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a3fd7b7

Please sign in to comment.