From 4e838b2c6e81042ae6a561517d0bb24980ee4089 Mon Sep 17 00:00:00 2001 From: apoorv1316 Date: Wed, 18 Sep 2024 14:03:32 +0530 Subject: [PATCH 1/6] add bank account details --- .../v1/invoices/view_controller.rb | 2 +- .../v1/payment_settings_controller.rb | 17 +++++++++++++- app/models/bank_account.rb | 10 ++++++++ app/models/company.rb | 1 + app/models/invoice.rb | 4 ++++ app/policies/payment_settings_policy.rb | 4 ++++ .../invoice_payment/pdf_generation.rb | 4 +++- .../v1/invoices/_bank_account.json.jbuilder | 9 ++++++++ .../v1/invoices/view/show.json.jbuilder | 3 +++ .../v1/payment_settings/index.json.jbuilder | 3 +++ app/views/layouts/pdf.html.erb | 3 ++- .../mailers/invoice_mailer/invoice.html.erb | 23 +++++++++++++++++++ app/views/pdfs/invoices.html.erb | 9 ++++++++ config/routes/internal_api.rb | 1 + .../20240903141939_create_bank_accounts.rb | 14 +++++++++++ db/schema.rb | 14 ++++++++++- 16 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 app/models/bank_account.rb create mode 100644 app/views/internal_api/v1/invoices/_bank_account.json.jbuilder create mode 100644 db/migrate/20240903141939_create_bank_accounts.rb diff --git a/app/controllers/internal_api/v1/invoices/view_controller.rb b/app/controllers/internal_api/v1/invoices/view_controller.rb index ecc5946d34..16ed3c004c 100644 --- a/app/controllers/internal_api/v1/invoices/view_controller.rb +++ b/app/controllers/internal_api/v1/invoices/view_controller.rb @@ -9,7 +9,7 @@ class InternalApi::V1::Invoices::ViewController < InternalApi::V1::ApplicationCo def show invoice.viewed! if invoice.sent? Invoices::EventTrackerService.new("view", invoice, params).process - render :show, locals: { invoice:, stripe_connected_account: } + render :show, locals: { invoice:, stripe_connected_account:, bank_account: invoice.bank_account_details } end private diff --git a/app/controllers/internal_api/v1/payment_settings_controller.rb b/app/controllers/internal_api/v1/payment_settings_controller.rb index 0d79d2ecd7..4be2306ee1 100644 --- a/app/controllers/internal_api/v1/payment_settings_controller.rb +++ b/app/controllers/internal_api/v1/payment_settings_controller.rb @@ -6,7 +6,7 @@ class InternalApi::V1::PaymentSettingsController < InternalApi::V1::ApplicationC def index authorize :index, policy_class: PaymentSettingsPolicy - render :index, locals: { stripe_connected_account: } + render :index, locals: { stripe_connected_account:, bank_account: current_company.bank_account } end def connect_stripe @@ -27,6 +27,17 @@ def destroy end end + def update_bank_account + authorize :update_bank_account, policy_class: PaymentSettingsPolicy + + @bank_account = current_company.bank_account || current_company.build_bank_account + if @bank_account.update(bank_account_params) + render json: { notice: "Bank account details updated successfully" }, status: :ok + else + render json: { error: @bank_account.errors.full_messages }, status: :unprocessable_entity + end + end + private def stripe_connected_account @@ -36,4 +47,8 @@ def stripe_connected_account def save_stripe_settings PaymentProviders::CreateStripeProviderService.process(current_company) end + + def bank_account_params + params.require(:bank_account).permit(:routing_number, :account_number, :account_type, :bank_name) + end end diff --git a/app/models/bank_account.rb b/app/models/bank_account.rb new file mode 100644 index 0000000000..11b092377f --- /dev/null +++ b/app/models/bank_account.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class BankAccount < ApplicationRecord + belongs_to :company + + validates :routing_number, presence: true + validates :account_number, presence: true + validates :account_type, presence: true, inclusion: { in: %w[checking savings] } + validates :bank_name, presence: true +end diff --git a/app/models/company.rb b/app/models/company.rb index 07eb91e3f6..4706a4abe7 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -31,6 +31,7 @@ class Company < ApplicationRecord has_many :invoices has_many :payments, through: :invoices has_one :stripe_connected_account, dependent: :destroy + has_one :bank_account, dependent: :destroy has_many :payments_providers, dependent: :destroy has_many :addresses, as: :addressable, dependent: :destroy has_many :devices, dependent: :destroy diff --git a/app/models/invoice.rb b/app/models/invoice.rb index e515ee5c86..09b7bc96cb 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -177,6 +177,10 @@ def refresh_invoice_index Invoice.search_index.refresh end + def bank_account_details + company.bank_account + end + private def set_external_view_key diff --git a/app/policies/payment_settings_policy.rb b/app/policies/payment_settings_policy.rb index 508aaf33a8..e47687ca86 100644 --- a/app/policies/payment_settings_policy.rb +++ b/app/policies/payment_settings_policy.rb @@ -16,4 +16,8 @@ def destroy? def refresh_stripe_connect? user_owner_role? || user_admin_role? end + + def update_bank_account? + user_owner_role? || user_admin_role? + end end diff --git a/app/services/invoice_payment/pdf_generation.rb b/app/services/invoice_payment/pdf_generation.rb index 3bae8dd76d..c4e8d82375 100644 --- a/app/services/invoice_payment/pdf_generation.rb +++ b/app/services/invoice_payment/pdf_generation.rb @@ -9,6 +9,7 @@ def initialize(invoice, company_logo, root_url, filepath = nil) @base_currency = invoice.company.base_currency @root_url = root_url @filepath = filepath + @bank_account = invoice.bank_account_details end def process @@ -24,7 +25,8 @@ def process client: @invoice.client, invoice_line_items: invoice_data[:invoice_line_items], sub_total: format_currency(invoice_data[:sub_total]), - total: format_currency(invoice_data[:total]) + total: format_currency(invoice_data[:total]), + bank_account: @bank_account } Pdf::HtmlGenerator.new( diff --git a/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder b/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder new file mode 100644 index 0000000000..512e7f38c5 --- /dev/null +++ b/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder @@ -0,0 +1,9 @@ + +if bank_account.present? + json.bank_name bank_account.bank_name + json.account_type bank_account.account_type.capitalize + json.routing_number bank_account.routing_number + json.account_number bank_account.account_number +else + json.null! +end diff --git a/app/views/internal_api/v1/invoices/view/show.json.jbuilder b/app/views/internal_api/v1/invoices/view/show.json.jbuilder index 5d2106b80e..4b3cdddaf8 100644 --- a/app/views/internal_api/v1/invoices/view/show.json.jbuilder +++ b/app/views/internal_api/v1/invoices/view/show.json.jbuilder @@ -11,3 +11,6 @@ end json.client do json.partial! "internal_api/v1/partial/client", locals: { client: invoice.client } end +json.bank_account do + json.partial! "internal_api/v1/invoices/bank_account", bank_account: +end \ No newline at end of file diff --git a/app/views/internal_api/v1/payment_settings/index.json.jbuilder b/app/views/internal_api/v1/payment_settings/index.json.jbuilder index 605ec49271..204772d79f 100644 --- a/app/views/internal_api/v1/payment_settings/index.json.jbuilder +++ b/app/views/internal_api/v1/payment_settings/index.json.jbuilder @@ -10,4 +10,7 @@ json.providers do json.paypal do json.connected false end + json.bank_account do + json.partial! "internal_api/v1/invoices/bank_account", bank_account: + end end diff --git a/app/views/layouts/pdf.html.erb b/app/views/layouts/pdf.html.erb index 9b809f595c..98fed23c07 100644 --- a/app/views/layouts/pdf.html.erb +++ b/app/views/layouts/pdf.html.erb @@ -3,8 +3,9 @@ - <%= stylesheet_link_tag '/assets/stylesheets/application.css'%> + <%= stylesheet_link_tag 'application'%> <%= stylesheet_pack_tag "application" %> + diff --git a/app/views/mailers/invoice_mailer/invoice.html.erb b/app/views/mailers/invoice_mailer/invoice.html.erb index 98ac2e0ebe..304e7a8c85 100644 --- a/app/views/mailers/invoice_mailer/invoice.html.erb +++ b/app/views/mailers/invoice_mailer/invoice.html.erb @@ -50,6 +50,29 @@ > Invoice Summary + <% if @bank_account.present? %> +
+ Bank Account Details +
+ + + + + + + + + + + + + + + + + +
Bank Name:<%= @bank_account.bank_name %>
Account Type:<%= @bank_account.account_type.capitalize %>
Routing Number:<%= @bank_account.routing_number %>
Account Number:<%= @bank_account.account_number %>
+ <% end %> diff --git a/app/views/pdfs/invoices.html.erb b/app/views/pdfs/invoices.html.erb index 0a4a7266ae..b7a300d3a7 100644 --- a/app/views/pdfs/invoices.html.erb +++ b/app/views/pdfs/invoices.html.erb @@ -137,4 +137,13 @@ html {
+ <% if bank_account %> +
+

Bank Account Details

+

Bank Name: <%= bank_account[:bank_name] %>

+

Account Type: <%= bank_account[:account_type].capitalize %>

+

Routing Number: <%= bank_account[:routing_number] %>

+

Account Number: <%= bank_account[:account_number] %>

+
+ <% end %> diff --git a/config/routes/internal_api.rb b/config/routes/internal_api.rb index 5a5b575687..aefcf82bce 100644 --- a/config/routes/internal_api.rb +++ b/config/routes/internal_api.rb @@ -129,6 +129,7 @@ get "payments/settings", to: "payment_settings#index" post "payments/settings/stripe/connect", to: "payment_settings#connect_stripe" delete "payments/settings/stripe/disconnect", to: "payment_settings#destroy" + patch "payments/settings/bank_account", to: "payment_settings#update_bank_account" get "calendars/redirect", to: "calendars#redirect", as: "redirect" get "calendars/callback", to: "calendars#callback", as: "callback" get "calendars/calendars", to: "calendars#calendars", as: "calendars" diff --git a/db/migrate/20240903141939_create_bank_accounts.rb b/db/migrate/20240903141939_create_bank_accounts.rb new file mode 100644 index 0000000000..31ff13df9e --- /dev/null +++ b/db/migrate/20240903141939_create_bank_accounts.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class CreateBankAccounts < ActiveRecord::Migration[7.1] + def change + create_table :bank_accounts do |t| + t.references :company, null: false, foreign_key: true + t.string :routing_number, null: false + t.string :account_number, null: false + t.string :account_type, null: false + t.string :bank_name, null: false + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2992576374..e1f97a9133 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_08_05_040547) do +ActiveRecord::Schema[7.1].define(version: 2024_09_03_141939) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -100,6 +100,17 @@ t.index ["visit_token"], name: "index_ahoy_visits_on_visit_token", unique: true end + create_table "bank_accounts", force: :cascade do |t| + t.bigint "company_id", null: false + t.string "routing_number", null: false + t.string "account_number", null: false + t.string "account_type", null: false + t.string "bank_name", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["company_id"], name: "index_bank_accounts_on_company_id" + end + create_table "bulk_invoice_download_statuses", force: :cascade do |t| t.string "download_id" t.string "status" @@ -691,6 +702,7 @@ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" + add_foreign_key "bank_accounts", "companies" add_foreign_key "carryovers", "companies" add_foreign_key "carryovers", "leave_types" add_foreign_key "carryovers", "users" From 094d0c0c69741d9afd4a2ce426429106c7645df3 Mon Sep 17 00:00:00 2001 From: apoorv1316 Date: Fri, 20 Sep 2024 12:45:14 +0530 Subject: [PATCH 2/6] Fix offence and policy specs --- .../v1/payment_settings_controller.rb | 8 +- app/policies/payment_settings_policy.rb | 19 +++-- .../v1/invoices/_bank_account.json.jbuilder | 1 + .../v1/invoices/view/show.json.jbuilder | 4 +- .../v1/payment_settings/index.json.jbuilder | 2 +- .../mailers/invoice_mailer/invoice.html.erb | 23 ------ config/routes/internal_api.rb | 12 ++- spec/policies/payment_settings_policy_spec.rb | 82 ++++++++++++------- 8 files changed, 84 insertions(+), 67 deletions(-) diff --git a/app/controllers/internal_api/v1/payment_settings_controller.rb b/app/controllers/internal_api/v1/payment_settings_controller.rb index 4be2306ee1..1a18b20858 100644 --- a/app/controllers/internal_api/v1/payment_settings_controller.rb +++ b/app/controllers/internal_api/v1/payment_settings_controller.rb @@ -4,13 +4,13 @@ class InternalApi::V1::PaymentSettingsController < InternalApi::V1::ApplicationC after_action :save_stripe_settings, only: :index def index - authorize :index, policy_class: PaymentSettingsPolicy + authorize current_company, policy_class: PaymentSettingsPolicy render :index, locals: { stripe_connected_account:, bank_account: current_company.bank_account } end def connect_stripe - authorize :connect_stripe, policy_class: PaymentSettingsPolicy + authorize current_company, policy_class: PaymentSettingsPolicy StripeConnectedAccount.create!({ company: current_company }) if stripe_connected_account.nil? @@ -18,7 +18,7 @@ def connect_stripe end def destroy - authorize :destroy, policy_class: PaymentSettingsPolicy + authorize current_company, policy_class: PaymentSettingsPolicy if stripe_connected_account.destroy render json: { notice: "Stripe connection disconnected" }, status: :ok @@ -28,7 +28,7 @@ def destroy end def update_bank_account - authorize :update_bank_account, policy_class: PaymentSettingsPolicy + authorize current_company, policy_class: PaymentSettingsPolicy @bank_account = current_company.bank_account || current_company.build_bank_account if @bank_account.update(bank_account_params) diff --git a/app/policies/payment_settings_policy.rb b/app/policies/payment_settings_policy.rb index e47687ca86..3cb35c78e1 100644 --- a/app/policies/payment_settings_policy.rb +++ b/app/policies/payment_settings_policy.rb @@ -2,22 +2,31 @@ class PaymentSettingsPolicy < ApplicationPolicy def index? - user_owner_role? || user_admin_role? + has_owner_or_admin_role?(record) end def connect_stripe? - user_owner_role? || user_admin_role? + has_owner_or_admin_role?(record) end def destroy? - user_owner_role? || user_admin_role? + has_owner_or_admin_role?(record) end def refresh_stripe_connect? - user_owner_role? || user_admin_role? + has_owner_or_admin_role?(record) end def update_bank_account? - user_owner_role? || user_admin_role? + has_owner_or_admin_role?(record) end + + private + + def has_owner_or_admin_role?(company) + user.has_any_role?( + { name: :admin, resource: company }, + { name: :owner, resource: company } + ) + end end diff --git a/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder b/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder index 512e7f38c5..9b80a02a05 100644 --- a/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder +++ b/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder @@ -1,3 +1,4 @@ +# frozen_string_literal: true if bank_account.present? json.bank_name bank_account.bank_name diff --git a/app/views/internal_api/v1/invoices/view/show.json.jbuilder b/app/views/internal_api/v1/invoices/view/show.json.jbuilder index 4b3cdddaf8..70312d4dfa 100644 --- a/app/views/internal_api/v1/invoices/view/show.json.jbuilder +++ b/app/views/internal_api/v1/invoices/view/show.json.jbuilder @@ -12,5 +12,5 @@ json.client do json.partial! "internal_api/v1/partial/client", locals: { client: invoice.client } end json.bank_account do - json.partial! "internal_api/v1/invoices/bank_account", bank_account: -end \ No newline at end of file + json.partial! "internal_api/v1/invoices/bank_account", bank_account: +end diff --git a/app/views/internal_api/v1/payment_settings/index.json.jbuilder b/app/views/internal_api/v1/payment_settings/index.json.jbuilder index 204772d79f..4d58245eaa 100644 --- a/app/views/internal_api/v1/payment_settings/index.json.jbuilder +++ b/app/views/internal_api/v1/payment_settings/index.json.jbuilder @@ -11,6 +11,6 @@ json.providers do json.connected false end json.bank_account do - json.partial! "internal_api/v1/invoices/bank_account", bank_account: + json.partial! "internal_api/v1/invoices/bank_account", bank_account: end end diff --git a/app/views/mailers/invoice_mailer/invoice.html.erb b/app/views/mailers/invoice_mailer/invoice.html.erb index 304e7a8c85..98ac2e0ebe 100644 --- a/app/views/mailers/invoice_mailer/invoice.html.erb +++ b/app/views/mailers/invoice_mailer/invoice.html.erb @@ -50,29 +50,6 @@ > Invoice Summary - <% if @bank_account.present? %> -
- Bank Account Details -
- - - - - - - - - - - - - - - - - -
Bank Name:<%= @bank_account.bank_name %>
Account Type:<%= @bank_account.account_type.capitalize %>
Routing Number:<%= @bank_account.routing_number %>
Account Number:<%= @bank_account.account_number %>
- <% end %> diff --git a/config/routes/internal_api.rb b/config/routes/internal_api.rb index aefcf82bce..8938b00f8e 100644 --- a/config/routes/internal_api.rb +++ b/config/routes/internal_api.rb @@ -125,11 +125,15 @@ resources :time_tracking, only: [:index], path: "time-tracking" + resources :payment_settings, only: [:index, :update], path: "payments/settings" do + collection do + post "stripe/connect", to: "payment_settings#connect_stripe" + delete "stripe/disconnect", to: "payment_settings#destroy" + put "bank_account", to: "payment_settings#update_bank_account" + end + end + # Non-Resourceful Routes - get "payments/settings", to: "payment_settings#index" - post "payments/settings/stripe/connect", to: "payment_settings#connect_stripe" - delete "payments/settings/stripe/disconnect", to: "payment_settings#destroy" - patch "payments/settings/bank_account", to: "payment_settings#update_bank_account" get "calendars/redirect", to: "calendars#redirect", as: "redirect" get "calendars/callback", to: "calendars#callback", as: "callback" get "calendars/calendars", to: "calendars#calendars", as: "calendars" diff --git a/spec/policies/payment_settings_policy_spec.rb b/spec/policies/payment_settings_policy_spec.rb index ad5e92d82c..94cff8c374 100644 --- a/spec/policies/payment_settings_policy_spec.rb +++ b/spec/policies/payment_settings_policy_spec.rb @@ -4,46 +4,72 @@ RSpec.describe PaymentSettingsPolicy, type: :policy do let(:company) { create(:company) } - let(:user) { create(:user, current_workspace_id: company.id) } + let(:admin) { create(:user, current_workspace_id: company.id) } + let(:owner) { create(:user, current_workspace_id: company.id) } + let(:employee) { create(:user, current_workspace_id: company.id) } + let(:book_keeper) { create(:user, current_workspace_id: company.id) } + + let(:another_company) { create(:company) } + let(:another_admin) { create(:user, current_workspace_id: another_company.id) } + let(:another_owner) { create(:user, current_workspace_id: another_company.id) } + let(:another_employee) { create(:user, current_workspace_id: another_company.id) } subject { described_class } - context "when user is an admin" do - before do - create(:employment, company:, user:) - user.add_role :admin, company - end + before do + admin.add_role :admin, company + owner.add_role :owner, company + employee.add_role :employee, company + book_keeper.add_role :book_keeper, company - permissions :index? do - it "is permitted to access index" do - expect(subject).to permit(user, :payment_settings) - end - end + another_admin.add_role :admin, another_company + another_owner.add_role :owner, another_company + another_employee.add_role :employee, another_company end - context "when user is an employee" do - before do - create(:employment, company:, user:) - user.add_role :employee, company + shared_examples "grants access to admin and owner" do |action| + it "allows admin and owner to perform #{action}" do + expect(subject).to permit(admin, company) + expect(subject).to permit(owner, company) end + end - permissions :index? do - it "is not permitted to access index" do - expect(subject).not_to permit(user, :payment_settings) - end + shared_examples "denies access to employee and book keeper" do |action| + it "denies #{action} to employee and book keeper" do + expect(subject).not_to permit(employee, company) + expect(subject).not_to permit(book_keeper, company) end end - context "when user is a book keeper" do - before do - create(:employment, company:, user:) - user.add_role :book_keeper, company + shared_examples "denies access to another company's users" do |action| + it "denies #{action} to users from another company" do + expect(subject).not_to permit(another_admin, company) + expect(subject).not_to permit(another_owner, company) + expect(subject).not_to permit(another_employee, company) end + end - permissions :index? do - it "is not permitted to access index" do - expect(subject).not_to permit(user, :payment_settings) - end - end + permissions :index? do + include_examples "grants access to admin and owner", "index" + include_examples "denies access to employee and book keeper", "index" + include_examples "denies access to another company's users", "index" + end + + permissions :update_bank_account? do + include_examples "grants access to admin and owner", "update_bank_account" + include_examples "denies access to employee and book keeper", "update_bank_account" + include_examples "denies access to another company's users", "update_bank_account" + end + + permissions :destroy? do + include_examples "grants access to admin and owner", "destroy" + include_examples "denies access to employee and book keeper", "destroy" + include_examples "denies access to another company's users", "destroy" + end + + permissions :connect_stripe? do + include_examples "grants access to admin and owner", "connect_stripe" + include_examples "denies access to employee and book keeper", "connect_stripe" + include_examples "denies access to another company's users", "connect_stripe" end end From ed35c6d58663aaaeb0a90c9c397d74b18a1c40a6 Mon Sep 17 00:00:00 2001 From: apoorv1316 Date: Mon, 23 Sep 2024 20:31:33 +0530 Subject: [PATCH 3/6] fix specs --- app/controllers/payment_settings_controller.rb | 4 ++-- config/routes/internal_api.rb | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/payment_settings_controller.rb b/app/controllers/payment_settings_controller.rb index 41a28005cf..27b9f43592 100644 --- a/app/controllers/payment_settings_controller.rb +++ b/app/controllers/payment_settings_controller.rb @@ -2,11 +2,11 @@ class PaymentSettingsController < ApplicationController def index - authorize :index, policy_class: PaymentSettingsPolicy + authorize current_company, policy_class: PaymentSettingsPolicy end def refresh_stripe_connect - authorize :refresh_stripe_connect, policy_class: PaymentSettingsPolicy + authorize current_company, policy_class: PaymentSettingsPolicy redirect_to stripe_connected_account.url, allow_other_host: true end diff --git a/config/routes/internal_api.rb b/config/routes/internal_api.rb index 8938b00f8e..384e0670c5 100644 --- a/config/routes/internal_api.rb +++ b/config/routes/internal_api.rb @@ -125,15 +125,11 @@ resources :time_tracking, only: [:index], path: "time-tracking" - resources :payment_settings, only: [:index, :update], path: "payments/settings" do - collection do - post "stripe/connect", to: "payment_settings#connect_stripe" - delete "stripe/disconnect", to: "payment_settings#destroy" - put "bank_account", to: "payment_settings#update_bank_account" - end - end - # Non-Resourceful Routes + get "payments/settings", to: "payment_settings#index" + post "payments/settings/stripe/connect", to: "payment_settings#connect_stripe" + delete "payments/settings/stripe/disconnect", to: "payment_settings#destroy" + put "payments/settings/bank_account", to: "payment_settings#update_bank_account" get "calendars/redirect", to: "calendars#redirect", as: "redirect" get "calendars/callback", to: "calendars#callback", as: "callback" get "calendars/calendars", to: "calendars#calendars", as: "calendars" From fa40a0fd8a2b979cf6400c04c9e685e41adb03af Mon Sep 17 00:00:00 2001 From: apoorv1316 Date: Thu, 24 Oct 2024 10:54:36 +0530 Subject: [PATCH 4/6] review comments --- app/controllers/internal_api/v1/invoices/view_controller.rb | 2 +- app/models/invoice.rb | 4 ---- app/services/invoice_payment/pdf_generation.rb | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/controllers/internal_api/v1/invoices/view_controller.rb b/app/controllers/internal_api/v1/invoices/view_controller.rb index 16ed3c004c..137d966c8e 100644 --- a/app/controllers/internal_api/v1/invoices/view_controller.rb +++ b/app/controllers/internal_api/v1/invoices/view_controller.rb @@ -9,7 +9,7 @@ class InternalApi::V1::Invoices::ViewController < InternalApi::V1::ApplicationCo def show invoice.viewed! if invoice.sent? Invoices::EventTrackerService.new("view", invoice, params).process - render :show, locals: { invoice:, stripe_connected_account:, bank_account: invoice.bank_account_details } + render :show, locals: { invoice:, stripe_connected_account:, bank_account: invoice.company.bank_account } end private diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 09b7bc96cb..e515ee5c86 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -177,10 +177,6 @@ def refresh_invoice_index Invoice.search_index.refresh end - def bank_account_details - company.bank_account - end - private def set_external_view_key diff --git a/app/services/invoice_payment/pdf_generation.rb b/app/services/invoice_payment/pdf_generation.rb index c4e8d82375..9bbe106333 100644 --- a/app/services/invoice_payment/pdf_generation.rb +++ b/app/services/invoice_payment/pdf_generation.rb @@ -9,7 +9,7 @@ def initialize(invoice, company_logo, root_url, filepath = nil) @base_currency = invoice.company.base_currency @root_url = root_url @filepath = filepath - @bank_account = invoice.bank_account_details + @bank_account = invoice.company.bank_account end def process From b1d89b0be61477095943ece04e40d523f9b937ba Mon Sep 17 00:00:00 2001 From: apoorv1316 Date: Thu, 24 Oct 2024 10:58:24 +0530 Subject: [PATCH 5/6] Review commetns --- .../v1/invoices/_bank_account.json.jbuilder | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder b/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder index 9b80a02a05..f476fd2e90 100644 --- a/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder +++ b/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder @@ -1,10 +1,6 @@ # frozen_string_literal: true -if bank_account.present? - json.bank_name bank_account.bank_name - json.account_type bank_account.account_type.capitalize - json.routing_number bank_account.routing_number - json.account_number bank_account.account_number -else - json.null! -end +json.bank_name bank_account.bank_name +json.account_type bank_account.account_type.capitalize +json.routing_number bank_account.routing_number +json.account_number bank_account.account_number From 967edefbece399ab0f2bf961b4004260502c671f Mon Sep 17 00:00:00 2001 From: apoorv1316 Date: Mon, 28 Oct 2024 11:23:49 +0530 Subject: [PATCH 6/6] Add safe navigation --- .../internal_api/v1/invoices/_bank_account.json.jbuilder | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder b/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder index f476fd2e90..733072e463 100644 --- a/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder +++ b/app/views/internal_api/v1/invoices/_bank_account.json.jbuilder @@ -1,6 +1,6 @@ # frozen_string_literal: true -json.bank_name bank_account.bank_name -json.account_type bank_account.account_type.capitalize -json.routing_number bank_account.routing_number -json.account_number bank_account.account_number +json.bank_name bank_account&.bank_name +json.account_type bank_account&.account_type&.capitalize +json.routing_number bank_account&.routing_number +json.account_number bank_account&.account_number