charge transport cost as well when accounting order (fix #861 after f7c7b56)

This commit is contained in:
twothreenine 2021-03-19 03:36:36 +01:00 committed by Patrick Gansterer
parent 052d297bff
commit f3493b3242
2 changed files with 27 additions and 1 deletions

View file

@ -391,7 +391,7 @@ class Order < ApplicationRecord
note = transaction_note note = transaction_note
group_orders.includes(:ordergroup).each do |group_order| group_orders.includes(:ordergroup).each do |group_order|
if group_order.ordergroup 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) group_order.ordergroup.add_financial_transaction!(price, note, user, transaction_type, nil, group_order)
end end
end end

View file

@ -1,6 +1,7 @@
require_relative '../spec_helper' require_relative '../spec_helper'
describe Order do describe Order do
let!(:ftt) { create :financial_transaction_type }
let(:user) { create :user, groups: [create(:ordergroup)] } let(:user) { create :user, groups: [create(:ordergroup)] }
it 'automaticly finishes ended' do it 'automaticly finishes ended' do
@ -151,4 +152,29 @@ describe Order do
expect(orders[1][:group_order]).to be_nil expect(orders[1][:group_order]).to be_nil
end end
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 end