Allow deletion of financial transactions
This commit is contained in:
parent
260ef90f6b
commit
ff76fa60c0
14 changed files with 79 additions and 8 deletions
|
|
@ -84,8 +84,7 @@ class Ordergroup < Group
|
|||
transaction do
|
||||
t = FinancialTransaction.new(ordergroup: self, amount: amount, note: note, user: user, financial_transaction_type: transaction_type, financial_link: link)
|
||||
t.save!
|
||||
self.account_balance = financial_transactions.sum('amount')
|
||||
save!
|
||||
update_balance!
|
||||
# Notify only when order group had a positive balance before the last transaction:
|
||||
if t.amount < 0 && self.account_balance < 0 && self.account_balance - t.amount >= 0
|
||||
Resque.enqueue(UserNotifier, FoodsoftConfig.scope, 'negative_balance', self.id, t.id)
|
||||
|
|
@ -103,6 +102,10 @@ class Ordergroup < Group
|
|||
update_attribute(:stats, {:jobs_size => jobs, :orders_sum => orders_sum})
|
||||
end
|
||||
|
||||
def update_balance!
|
||||
update_attribute :account_balance, financial_transactions.sum('amount')
|
||||
end
|
||||
|
||||
def avg_jobs_per_euro
|
||||
stats[:jobs_size].to_f / stats[:orders_sum].to_f rescue 0
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue