1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-19 08:52:25 +01:00
fab-manager/app/models/invoicing_profile.rb
Sylvain af3def0e2e (feat) save the accounting data in DB
Previously, the accounting data were built on demand,
extracting the data from the invoices on-the-fly.
This is intended to be used only once in a while, so there was
no performance issue with that.
Now, we want those data to be accessed from the OpenAPI,
so building them on-the-fly would be very much
intensive and resouces heavy. So we build them each nights
using a scheduled worker and save them in the database
2022-12-21 14:11:40 +01:00

37 lines
1.7 KiB
Ruby

# frozen_string_literal: true
# This table will save the user's profile data needed for legal accounting (invoices, wallet, etc.)
# Legal accounting must be kept for 10 years but GDPR requires that an user can delete his account at any time.
# The data will be kept even if the user is deleted, but it will be unlinked from the user's account.
class InvoicingProfile < ApplicationRecord
belongs_to :user
has_one :address, as: :placeable, dependent: :destroy
accepts_nested_attributes_for :address, allow_destroy: true
has_one :organization, dependent: :destroy
accepts_nested_attributes_for :organization, allow_destroy: false
has_many :invoices, dependent: :destroy
has_many :payment_schedules, dependent: :destroy
has_one :wallet, dependent: :destroy
has_many :wallet_transactions, dependent: :destroy
has_many :history_values, dependent: :nullify
has_many :operated_invoices, foreign_key: :operator_profile_id, class_name: 'Invoice', dependent: :nullify, inverse_of: :operator_profile
has_many :operated_payment_schedules, foreign_key: :operator_profile_id, class_name: 'PaymentSchedule',
dependent: :nullify, inverse_of: :operator_profile
has_many :user_profile_custom_fields, dependent: :destroy
has_many :profile_custom_fields, through: :user_profile_custom_fields
accepts_nested_attributes_for :user_profile_custom_fields, allow_destroy: true
has_many :accounting_lines, dependent: :destroy
validates :address, presence: true, if: -> { Setting.get('address_required') }
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
end