-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dunning): Refactor payment_requests and remove payable_groups (#…
…2456) ## Context We want to be able to manually request payment of the overdue balance and send emails for reminders. https://getlago.canny.io/feature-requests/p/send-reminders-for-overdue-invoices ## Description The goal of this PR is to refactor how we define a payment request by removing the payable group entity. --------- Co-authored-by: Ancor Cruz <[email protected]>
- Loading branch information
Showing
22 changed files
with
161 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class PaymentRequest | ||
class AppliedInvoice < ApplicationRecord | ||
self.table_name = "invoices_payment_requests" | ||
|
||
belongs_to :invoice | ||
belongs_to :payment_request | ||
end | ||
end | ||
|
||
# == Schema Information | ||
# | ||
# Table name: invoices_payment_requests | ||
# | ||
# id :uuid not null, primary key | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# invoice_id :uuid not null | ||
# payment_request_id :uuid not null | ||
# | ||
# Indexes | ||
# | ||
# idx_on_invoice_id_payment_request_id_aa550779a4 (invoice_id,payment_request_id) UNIQUE | ||
# index_invoices_payment_requests_on_invoice_id (invoice_id) | ||
# index_invoices_payment_requests_on_payment_request_id (payment_request_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (invoice_id => invoices.id) | ||
# fk_rails_... (payment_request_id => payment_requests.id) | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
db/migrate/20240821093145_create_invoices_payment_requests.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateInvoicesPaymentRequests < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :invoices_payment_requests, id: :uuid do |t| | ||
t.references :invoice, type: :uuid, null: false, foreign_key: true | ||
t.references :payment_request, type: :uuid, null: false, foreign_key: true | ||
t.timestamps | ||
end | ||
|
||
add_index :invoices_payment_requests, %i[invoice_id payment_request_id], unique: true | ||
|
||
remove_column :payments, :payment_request_id, :uuid | ||
|
||
# NOTE: Migrate existing data from invoices to invoices_payment_requests | ||
reversible do |dir| | ||
dir.up do | ||
execute <<-SQL | ||
INSERT INTO invoices_payment_requests (invoice_id, payment_request_id, created_at, updated_at) | ||
SELECT invoices.id, payment_requests.id, invoices.created_at, invoices.updated_at | ||
FROM invoices | ||
inner join payment_requests on payment_requests.payment_requestable_id = invoices.payable_group_id | ||
and payment_requests.payment_requestable_type = 'PayableGroup' | ||
WHERE payable_group_id IS NOT NULL | ||
SQL | ||
end | ||
end | ||
|
||
drop_table :payable_groups, id: :uuid do |t| | ||
t.references :customer, type: :uuid, null: false, foreign_key: true | ||
t.references :organization, type: :uuid, null: false, foreign_key: true | ||
t.integer :payment_status, null: false, default: 0 | ||
t.timestamps | ||
end | ||
|
||
change_table :payment_requests, bulk: true do |t| | ||
t.remove :payment_requestable_id, type: :uuid | ||
t.remove :payment_requestable_type, type: :string | ||
|
||
t.integer :payment_status, null: false, default: 0 | ||
end | ||
|
||
remove_column :invoices, :payable_group_id, :uuid | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.