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 Feb 19, 2024
1 parent 4bb1afc commit 6e9089a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/reflexes/admin/orders_reflex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ def ship
end

def bulk_invoice(params)
visible_orders = editable_orders.where(id: params[:bulk_ids]).filter(&:invoiceable?)
return unless all_distributors_can_invoice?(visible_orders)

cable_ready.append(
selector: "#orders-index",
html: render(partial: "spree/admin/orders/bulk/invoice_modal")
).broadcast

BulkInvoiceJob.perform_later(
params[:bulk_ids],
visible_orders.pluck(:id),
"tmp/invoices/#{Time.zone.now.to_i}-#{SecureRandom.hex(2)}.pdf",
channel: SessionChannel.for_request(request),
current_user_id: current_user.id
Expand Down Expand Up @@ -106,5 +109,16 @@ def editable_orders
def set_param_for_controller
params[:id] = @order.number
end

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

return true if distributors.empty?

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 6e9089a

Please sign in to comment.