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 9e808cb
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 @@ -27,13 +27,16 @@ def ship
end

def bulk_invoice(params)
visible_orders = editable_orders.where(id: params[:bulk_ids])
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 @@ -96,5 +99,16 @@ def success(i18n_key, count)
def editable_orders
Permissions::Order.new(current_user).editable_orders
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 9e808cb

Please sign in to comment.