Skip to content

Commit

Permalink
add db changes for edit draft invoice feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lovrocolic committed Dec 20, 2023
1 parent 7577eb8 commit ab3724d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/models/adjusted_fee.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class AdjustedFee < ApplicationRecord
belongs_to :invoice
belongs_to :fee, optional: true

enum fee_type: Fee::FEE_TYPES
end
22 changes: 22 additions & 0 deletions db/migrate/20231220140936_create_adjusted_fees.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

class CreateAdjustedFees < ActiveRecord::Migration[7.0]
def change
create_table :adjusted_fees, id: :uuid do |t|
t.references :fee, type: :uuid, null: true, index: true, foreign_key: true
t.references :invoice, type: :uuid, null: false, index: true, foreign_key: true
t.references :subscription, type: :uuid, null: true, foreign_key: true, index: true
t.references :charge, type: :uuid, null: true, foreign_key: true, index: true

t.string :invoice_display_name
t.integer :fee_type
t.boolean :adjusted_units, default: false, null: false
t.boolean :adjusted_amount, default: false, null: false
t.decimal :units, default: '0.0', null: false
t.bigint :unit_amount_cents, null: false, default: 0
t.jsonb :properties, null: false, default: {}

t.timestamps
end
end
end
26 changes: 25 additions & 1 deletion db/schema.rb

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

18 changes: 18 additions & 0 deletions spec/factories/adjusted_fees.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

FactoryBot.define do
factory :adjusted_fee do
invoice
fee
charge { nil }
subscription

fee_type { 'subscription' }

unit_amount_cents { 200 }
units { 2 }
adjusted_amount { true }

invoice_display_name { Faker::Fantasy::Tolkien.character }
end
end

0 comments on commit ab3724d

Please sign in to comment.