Skip to content

Commit 5f03182

Browse files
committed
Fix transport cost related issues
- Include transport costs when calculating the group sum of an order - When creating a foodcoop transaction, use the exact inverted sum of the group transactions to prevent rounding issues - Display transport costs above "The following were not ordered" to avoid confusion
1 parent de3be58 commit 5f03182

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

.rubocop_todo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Metrics/BlockNesting:
208208
# Offense count: 18
209209
# Configuration parameters: CountComments, CountAsOne.
210210
Metrics/ClassLength:
211-
Max: 304
211+
Max: 305
212212

213213
# Offense count: 51
214214
# Configuration parameters: AllowedMethods, AllowedPatterns.

app/models/order.rb

+11-8
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ def sum(type = :gross)
221221
end
222222
elsif %i[groups groups_without_markup].include?(type)
223223
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
229229
total += goa.result * goa.order_article.price.gross_price
230230
end
231231
end
@@ -277,7 +277,7 @@ def close!(user, transaction_type = nil, financial_link = nil, create_foodcoop_t
277277
update_price_of_group_orders!
278278

279279
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)
281281

282282
if stockit? # Decreases the quantity of stock_articles
283283
for oa in order_articles.includes(:article)
@@ -289,7 +289,7 @@ def close!(user, transaction_type = nil, financial_link = nil, create_foodcoop_t
289289
if create_foodcoop_transaction
290290
ft = FinancialTransaction.new({ financial_transaction_type: transaction_type,
291291
user: user,
292-
amount: sum(:groups),
292+
amount: total_group_charges * -1,
293293
note: transaction_note,
294294
financial_link: financial_link })
295295
ft.save!
@@ -408,12 +408,15 @@ def update_price_of_group_orders!
408408

409409
def charge_group_orders!(user, transaction_type = nil, financial_link = nil)
410410
note = transaction_note
411+
total = 0
411412
group_orders.includes(:ordergroup).find_each do |group_order|
412413
if group_order.ordergroup
413414
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
415417
end
416418
end
419+
total
417420
end
418421

419422
def transaction_note

app/views/finance/balancing/_edit_results_by_articles.html.haml

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949
- for order_article in @articles.select { |oa| oa.units > 0 }
5050
= render :partial => "order_article_result", :locals => {:order_article => order_article}
5151

52-
%tr
53-
%td{ colspan: 10 } The following were not ordered
54-
55-
- for order_article in @articles.select { |oa| oa.units == 0 }
56-
= render :partial => "order_article_result", :locals => {:order_article => order_article}
57-
5852
- if @order.transport
5953
%tr
6054
%td{ colspan: 5 }= heading_helper Order, :transport
6155
%td{ colspan: 3, data: {value: @order.transport} }= number_to_currency(@order.transport)
6256
%td= link_to t('ui.edit'), edit_transport_finance_order_path(@order), remote: true,
6357
class: 'btn btn-mini' unless order_article.order.closed?
58+
59+
%tr
60+
%td{ colspan: 10 } The following were not ordered
61+
62+
- for order_article in @articles.select { |oa| oa.units == 0 }
63+
= render :partial => "order_article_result", :locals => {:order_article => order_article}

0 commit comments

Comments
 (0)