Add option to ignore financial transaction when calculating the balance
This commit is contained in:
parent
a30d0d4453
commit
7d5155bef6
6 changed files with 68 additions and 16 deletions
|
|
@ -1,10 +1,14 @@
|
|||
class FinancialTransactionClass < ApplicationRecord
|
||||
has_many :financial_transaction_types, dependent: :destroy
|
||||
has_many :supplier_category, dependent: :restrict_with_exception
|
||||
has_many :financial_transactions, through: :financial_transaction_types
|
||||
has_many :ordergroups, -> { distinct }, through: :financial_transactions
|
||||
|
||||
validates :name, presence: true
|
||||
validates_uniqueness_of :name
|
||||
|
||||
after_save :update_balance_of_ordergroups
|
||||
|
||||
scope :sorted, -> { order(name: :asc) }
|
||||
|
||||
def self.has_multiple_classes
|
||||
|
|
@ -18,4 +22,10 @@ class FinancialTransactionClass < ApplicationRecord
|
|||
I18n.t('activerecord.attributes.financial_transaction.amount')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_balance_of_ordergroups
|
||||
ordergroups.each { |og| og.update_balance! }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue