This commit is contained in:
parent
052d297bff
commit
f3493b3242
2 changed files with 27 additions and 1 deletions
|
@ -391,7 +391,7 @@ class Order < ApplicationRecord
|
|||
note = transaction_note
|
||||
group_orders.includes(:ordergroup).each do |group_order|
|
||||
if group_order.ordergroup
|
||||
price = group_order.price * -1 # decrease! account balance
|
||||
price = group_order.total * -1 # decrease! account balance
|
||||
group_order.ordergroup.add_financial_transaction!(price, note, user, transaction_type, nil, group_order)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe Order do
|
||||
let!(:ftt) { create :financial_transaction_type }
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
|
||||
it 'automaticly finishes ended' do
|
||||
|
@ -151,4 +152,29 @@ describe Order do
|
|||
expect(orders[1][:group_order]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'balancing charges correct amounts' do
|
||||
let!(:transport) { rand(0.1..26.0).round(2) }
|
||||
let!(:order) { create :order, article_count: 1 }
|
||||
let!(:oa) { order.order_articles.first }
|
||||
let!(:go) { create :group_order, order: order, transport: transport }
|
||||
let!(:goa) { create :group_order_article, group_order: go, order_article: oa, quantity: 1 }
|
||||
|
||||
before do
|
||||
goa.update_quantities(1, 0)
|
||||
go.reload
|
||||
go.update_price!
|
||||
user.ordergroup.update_stats!
|
||||
oa.update_results!
|
||||
|
||||
order.finish!(user)
|
||||
order.reload
|
||||
order.close!(user, ftt)
|
||||
end
|
||||
|
||||
it 'creates financial transaction with correct amount' do
|
||||
expect(goa.result).to be > 0
|
||||
expect(go.ordergroup.financial_transactions.last.amount).to eq(-go.total)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue