mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
[ongoing] attach invoices to invoicingProfile instead of user
This commit is contained in:
parent
5231e464fe
commit
3945b760b5
@ -13,6 +13,7 @@ class Invoice < ActiveRecord::Base
|
|||||||
has_many :invoice_items, dependent: :destroy
|
has_many :invoice_items, dependent: :destroy
|
||||||
accepts_nested_attributes_for :invoice_items
|
accepts_nested_attributes_for :invoice_items
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :invoicing_profile
|
||||||
belongs_to :wallet_transaction
|
belongs_to :wallet_transaction
|
||||||
belongs_to :coupon
|
belongs_to :coupon
|
||||||
|
|
||||||
|
@ -2,4 +2,5 @@ class InvoicingProfile < ActiveRecord::Base
|
|||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_one :address, as: :placeable, dependent: :destroy
|
has_one :address, as: :placeable, dependent: :destroy
|
||||||
has_one :organization, dependent: :destroy
|
has_one :organization, dependent: :destroy
|
||||||
|
has_many :invoices, dependent: :destroy
|
||||||
end
|
end
|
||||||
|
@ -21,6 +21,8 @@ class User < ActiveRecord::Base
|
|||||||
has_one :profile, dependent: :destroy
|
has_one :profile, dependent: :destroy
|
||||||
accepts_nested_attributes_for :profile
|
accepts_nested_attributes_for :profile
|
||||||
|
|
||||||
|
has_one :invoicing_profile, dependent: :nullify
|
||||||
|
|
||||||
has_many :my_projects, foreign_key: :author_id, class_name: 'Project', dependent: :destroy
|
has_many :my_projects, foreign_key: :author_id, class_name: 'Project', dependent: :destroy
|
||||||
has_many :project_users, dependent: :destroy
|
has_many :project_users, dependent: :destroy
|
||||||
has_many :projects, through: :project_users
|
has_many :projects, through: :project_users
|
||||||
|
@ -9,5 +9,6 @@ class CreateInvoicingProfiles < ActiveRecord::Migration
|
|||||||
end
|
end
|
||||||
|
|
||||||
add_reference :organizations, :invoicing_profile, index: true, foreign_key: true
|
add_reference :organizations, :invoicing_profile, index: true, foreign_key: true
|
||||||
|
add_reference :invoices, :invoicing_profile, index: true, foreign_key: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
class MigrateProfileToInvoicingProfile < ActiveRecord::Migration
|
class MigrateProfileToInvoicingProfile < ActiveRecord::Migration
|
||||||
def up
|
def up
|
||||||
Profile.all.each do |p|
|
User.all.each do |u|
|
||||||
|
p = u.profile
|
||||||
|
puts "WARNING: User #{u.id} has no profile" and next unless p
|
||||||
|
|
||||||
ip = InvoicingProfile.create!(
|
ip = InvoicingProfile.create!(
|
||||||
user: p.user,
|
user: u,
|
||||||
first_name: p.first_name,
|
first_name: p.first_name,
|
||||||
last_name: p.last_name
|
last_name: p.last_name
|
||||||
)
|
)
|
||||||
@ -20,7 +23,7 @@ class MigrateProfileToInvoicingProfile < ActiveRecord::Migration
|
|||||||
profile = ip.user.profile
|
profile = ip.user.profile
|
||||||
profile.update_attributes(
|
profile.update_attributes(
|
||||||
first_name: ip.first_name,
|
first_name: ip.first_name,
|
||||||
last_name: ip.last_name,
|
last_name: ip.last_name
|
||||||
)
|
)
|
||||||
ip.address&.update_attributes(
|
ip.address&.update_attributes(
|
||||||
placeable: profile
|
placeable: profile
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
class MigrateUserToInvoicingProfile < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
# first, check the footprints
|
||||||
|
puts 'Checking all invoices footprints. This may take a while...'
|
||||||
|
Invoice.where.not(footprint: nil).order(:created_at).all.each do |i|
|
||||||
|
raise "Invalid footprint for invoice #{i.id}" unless i.check_footprint
|
||||||
|
end
|
||||||
|
# if everything is ok, proceed with migration
|
||||||
|
Invoice.order(:created_at).all.each do |i|
|
||||||
|
i.update_column('invoicing_profile_id', i.user.invoicing_profile.id)
|
||||||
|
i.update_column('user_id', nil)
|
||||||
|
i.chain_record
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
Invoice.order(:created_at).all.each do |i|
|
||||||
|
i.update_column('user_id', i.invoicing_profile.user_id)
|
||||||
|
i.update_column('invoicing_profile_id', nil)
|
||||||
|
i.chain_record
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
16
db/schema.rb
16
db/schema.rb
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20190521124609) do
|
ActiveRecord::Schema.define(version: 20190320091148) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@ -287,16 +287,6 @@ ActiveRecord::Schema.define(version: 20190521124609) do
|
|||||||
add_index "invoices", ["user_id"], name: "index_invoices_on_user_id", using: :btree
|
add_index "invoices", ["user_id"], name: "index_invoices_on_user_id", using: :btree
|
||||||
add_index "invoices", ["wallet_transaction_id"], name: "index_invoices_on_wallet_transaction_id", using: :btree
|
add_index "invoices", ["wallet_transaction_id"], name: "index_invoices_on_wallet_transaction_id", using: :btree
|
||||||
|
|
||||||
create_table "invoicing_profiles", force: :cascade do |t|
|
|
||||||
t.integer "user_id"
|
|
||||||
t.string "first_name"
|
|
||||||
t.string "last_name"
|
|
||||||
t.datetime "created_at", null: false
|
|
||||||
t.datetime "updated_at", null: false
|
|
||||||
end
|
|
||||||
|
|
||||||
add_index "invoicing_profiles", ["user_id"], name: "index_invoicing_profiles_on_user_id", using: :btree
|
|
||||||
|
|
||||||
create_table "licences", force: :cascade do |t|
|
create_table "licences", force: :cascade do |t|
|
||||||
t.string "name", limit: 255, null: false
|
t.string "name", limit: 255, null: false
|
||||||
t.text "description"
|
t.text "description"
|
||||||
@ -396,10 +386,8 @@ ActiveRecord::Schema.define(version: 20190521124609) do
|
|||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "profile_id"
|
t.integer "profile_id"
|
||||||
t.integer "invoicing_profile_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "organizations", ["invoicing_profile_id"], name: "index_organizations_on_invoicing_profile_id", using: :btree
|
|
||||||
add_index "organizations", ["profile_id"], name: "index_organizations_on_profile_id", using: :btree
|
add_index "organizations", ["profile_id"], name: "index_organizations_on_profile_id", using: :btree
|
||||||
|
|
||||||
create_table "plans", force: :cascade do |t|
|
create_table "plans", force: :cascade do |t|
|
||||||
@ -898,10 +886,8 @@ ActiveRecord::Schema.define(version: 20190521124609) do
|
|||||||
add_foreign_key "invoices", "coupons"
|
add_foreign_key "invoices", "coupons"
|
||||||
add_foreign_key "invoices", "users", column: "operator_id"
|
add_foreign_key "invoices", "users", column: "operator_id"
|
||||||
add_foreign_key "invoices", "wallet_transactions"
|
add_foreign_key "invoices", "wallet_transactions"
|
||||||
add_foreign_key "invoicing_profiles", "users"
|
|
||||||
add_foreign_key "o_auth2_mappings", "o_auth2_providers"
|
add_foreign_key "o_auth2_mappings", "o_auth2_providers"
|
||||||
add_foreign_key "open_api_calls_count_tracings", "open_api_clients"
|
add_foreign_key "open_api_calls_count_tracings", "open_api_clients"
|
||||||
add_foreign_key "organizations", "invoicing_profiles"
|
|
||||||
add_foreign_key "organizations", "profiles"
|
add_foreign_key "organizations", "profiles"
|
||||||
add_foreign_key "prices", "groups"
|
add_foreign_key "prices", "groups"
|
||||||
add_foreign_key "prices", "plans"
|
add_foreign_key "prices", "plans"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user