91bcf0c580
The database schema allows numbers up (+/-) 999_999.99. But as we are also adding the amount to the Ordergroup#account_balance, we use lower barriers to avoid running in errors when updating the account balance. So, technically the user has to make 10 times the maximum input to raise an account balance error. This should be sufficient, I hope.
17 lines
583 B
Ruby
17 lines
583 B
Ruby
# financial transactions are the foodcoop internal financial transactions
|
|
# only ordergroups have an account balance and are happy to transfer money
|
|
class FinancialTransaction < ActiveRecord::Base
|
|
belongs_to :ordergroup
|
|
belongs_to :user
|
|
|
|
validates_presence_of :amount, :note, :user_id, :ordergroup_id
|
|
validates_numericality_of :amount, greater_then: -100_000,
|
|
less_than: 100_000
|
|
|
|
localize_input_of :amount
|
|
|
|
# Use this save method instead of simple save and after callback
|
|
def add_transaction!
|
|
ordergroup.add_financial_transaction! amount, note, user
|
|
end
|
|
end
|