Add set_balance to FinancialTransactions#new_collection (fixes #438)

A new checkbox will allow user to set the balance to a given ABSOLUTE value
in addition to changing it by a RELATIVE value. This can be used if the
balance is tracked outside of foodsoft and should be syncroniced or for
setting the balance to zero for multiple ordergroups.
This commit is contained in:
Patrick Gansterer 2018-12-30 03:43:48 +01:00
parent abe847c0ee
commit 389f205a6b
5 changed files with 24 additions and 3 deletions

View file

@ -65,6 +65,13 @@ class Ordergroup < Group
account_balance - value_of_open_orders(exclude) - value_of_finished_orders(exclude)
end
def financial_transaction_class_balance(klass)
financial_transactions
.joins(:financial_transaction_type)
.where(financial_transaction_types: {financial_transaction_class_id: klass})
.sum(:amount)
end
# Creates a new FinancialTransaction for this Ordergroup and updates the account_balance accordingly.
# Throws an exception if it fails.
def add_financial_transaction!(amount, note, user, transaction_type, link = nil)