@@ -221,11 +221,11 @@ def sum(type = :gross)
221
221
end
222
222
elsif %i[ groups groups_without_markup ] . include? ( type )
223
223
for go in group_orders . includes ( group_order_articles : { order_article : %i[ article article_price ] } )
224
- for goa in go . group_order_articles
225
- case type
226
- when :groups
227
- total += goa . result * goa . order_article . price . fc_price
228
- when :groups_without_markup
224
+ case type
225
+ when :groups
226
+ total += go . total
227
+ when :groups_without_markup
228
+ for goa in go . group_order_articles
229
229
total += goa . result * goa . order_article . price . gross_price
230
230
end
231
231
end
@@ -277,7 +277,7 @@ def close!(user, transaction_type = nil, financial_link = nil, create_foodcoop_t
277
277
update_price_of_group_orders!
278
278
279
279
transaction do # Start updating account balances
280
- charge_group_orders! ( user , transaction_type , financial_link )
280
+ total_group_charges = charge_group_orders! ( user , transaction_type , financial_link )
281
281
282
282
if stockit? # Decreases the quantity of stock_articles
283
283
for oa in order_articles . includes ( :article )
@@ -289,7 +289,7 @@ def close!(user, transaction_type = nil, financial_link = nil, create_foodcoop_t
289
289
if create_foodcoop_transaction
290
290
ft = FinancialTransaction . new ( { financial_transaction_type : transaction_type ,
291
291
user : user ,
292
- amount : sum ( :groups ) ,
292
+ amount : total_group_charges * - 1 ,
293
293
note : transaction_note ,
294
294
financial_link : financial_link } )
295
295
ft . save!
@@ -408,12 +408,15 @@ def update_price_of_group_orders!
408
408
409
409
def charge_group_orders! ( user , transaction_type = nil , financial_link = nil )
410
410
note = transaction_note
411
+ total = 0
411
412
group_orders . includes ( :ordergroup ) . find_each do |group_order |
412
413
if group_order . ordergroup
413
414
price = group_order . total * -1 # decrease! account balance
414
- group_order . ordergroup . add_financial_transaction! ( price , note , user , transaction_type , financial_link , group_order )
415
+ transaction = group_order . ordergroup . add_financial_transaction! ( price , note , user , transaction_type , financial_link , group_order )
416
+ total += transaction . amount
415
417
end
416
418
end
419
+ total
417
420
end
418
421
419
422
def transaction_note
0 commit comments