2019-05-21 16:07:40 +02:00
|
|
|
class InvoicingProfile < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
2019-05-22 12:45:45 +02:00
|
|
|
has_one :address, as: :placeable, dependent: :destroy
|
2019-05-29 14:28:14 +02:00
|
|
|
accepts_nested_attributes_for :address, allow_destroy: true
|
2019-05-22 12:45:45 +02:00
|
|
|
has_one :organization, dependent: :destroy
|
2019-05-29 14:28:14 +02:00
|
|
|
accepts_nested_attributes_for :organization, allow_destroy: false
|
2019-05-22 17:49:22 +02:00
|
|
|
has_many :invoices, dependent: :destroy
|
2019-05-28 16:49:36 +02:00
|
|
|
|
2019-06-03 16:00:09 +02:00
|
|
|
has_one :wallet, dependent: :destroy
|
|
|
|
has_many :wallet_transactions, dependent: :destroy
|
|
|
|
|
2019-06-03 16:51:43 +02:00
|
|
|
has_many :history_values, dependent: :nullify
|
|
|
|
|
2019-06-03 16:00:09 +02:00
|
|
|
after_create :create_a_wallet
|
|
|
|
|
2019-05-28 16:49:36 +02:00
|
|
|
|
|
|
|
def full_name
|
|
|
|
# if first_name or last_name is nil, the empty string will be used as a temporary replacement
|
|
|
|
(first_name || '').humanize.titleize + ' ' + (last_name || '').humanize.titleize
|
|
|
|
end
|
2019-06-03 16:00:09 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_a_wallet
|
|
|
|
create_wallet
|
|
|
|
end
|
2019-05-21 16:07:40 +02:00
|
|
|
end
|