Skip to content

Commit

Permalink
feat(revshare): Add db columns for partners and self_billed invoices (#…
Browse files Browse the repository at this point in the history
…3062)

## Roadmap

👉 https://getlago.canny.io/feature-requests/p/calculate-revenue-share

 ## Context

Current problem: companies with **partners** selling for them cannot
have a **revenue share** system in Lago.

We want to propose **self-billing** into Lago, a billing arrangement
where the **customer** creates and issues the invoice on **behalf** of
the **supplier** for goods or services received.

 ## Description

Add `account_type` enum to customers.

Add `self_billed` flag to invoices
  • Loading branch information
ancorcruz authored Jan 16, 2025
1 parent 7c0b99b commit a3bacfd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def ensure_slug
# Table name: customers
#
# id :uuid not null, primary key
# account_type :enum default("customer"), not null
# address_line1 :string
# address_line2 :string
# city :string
Expand Down Expand Up @@ -278,6 +279,7 @@ def ensure_slug
#
# Indexes
#
# index_customers_on_account_type (account_type)
# index_customers_on_applied_dunning_campaign_id (applied_dunning_campaign_id)
# index_customers_on_deleted_at (deleted_at)
# index_customers_on_external_id_and_organization_id (external_id,organization_id) UNIQUE WHERE (deleted_at IS NULL)
Expand Down
2 changes: 2 additions & 0 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ def status_changed_to_finalized?
# progressive_billing_credit_amount_cents :bigint default(0), not null
# ready_for_payment_processing :boolean default(TRUE), not null
# ready_to_be_refreshed :boolean default(FALSE), not null
# self_billed :boolean default(FALSE), not null
# skip_charges :boolean default(FALSE), not null
# status :integer default("finalized"), not null
# sub_total_excluding_taxes_amount_cents :bigint default(0), not null
Expand Down Expand Up @@ -502,6 +503,7 @@ def status_changed_to_finalized?
# index_invoices_on_organization_id (organization_id)
# index_invoices_on_payment_overdue (payment_overdue)
# index_invoices_on_ready_to_be_refreshed (ready_to_be_refreshed) WHERE (ready_to_be_refreshed = true)
# index_invoices_on_self_billed (self_billed)
# index_invoices_on_sequential_id (sequential_id)
# index_invoices_on_status (status)
#
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20250114163522_add_account_type_to_customers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class AddAccountTypeToCustomers < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
create_enum :customer_account_type, %w[customer partner]
add_column :customers, :account_type, :enum, enum_type: "customer_account_type", default: "customer", null: false

add_index :customers, :account_type, algorithm: :concurrently
end
end
10 changes: 10 additions & 0 deletions db/migrate/20250114172823_add_self_billed_to_invoices.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AddSelfBilledToInvoices < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
add_column :invoices, :self_billed, :boolean, default: false, null: false
add_index :invoices, :self_billed, algorithm: :concurrently
end
end
7 changes: 6 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3bacfd

Please sign in to comment.