Skip to content

Commit c9e4442

Browse files
committed
Improve financial link feature & transaction links
- add a config option "use_financial_links" for activating both finance links and foodcoop transaction features - add migration: set this option to true if any financial link or foodcoop transaction exists - add options to create a financial link and/or foodcoop transaction when balancing an order - show links to finance links only to users with finance role (required anyway, but links were shown in home/ordergroup) - add note column when adding a financial transaction to a link - financial transactions: show link to group_order only in home/ordergroup and (additionally) dashboard; replace with link to order's balancing page in finance views - finance link: show link in financial transaction note to respective order's balancing page (also when adding a financial transaction) - finance link: replace misleading "delete" button for removing a transaction with "remove from link", also adapt confirm message - adapt en/de locales, fix finance-related locale typos
1 parent 8b4c36e commit c9e4442

19 files changed

+115
-42
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: 294
211+
Max: 304
212212

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

app/controllers/finance/balancing_controller.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def confirm
8080
def close
8181
@order = Order.find(params[:id])
8282
@type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
83-
@order.close!(@current_user, @type)
83+
@link = FinancialLink.new if params[:create_financial_link]
84+
@order.close!(@current_user, @type, @link, create_foodcoop_transaction: params[:create_foodcoop_transaction])
8485
redirect_to finance_order_index_url, notice: t('.notice')
8586
rescue StandardError => e
8687
redirect_to new_finance_order_url(order_id: @order.id), alert: t('.alert', message: e.message)

app/controllers/finance/financial_links_controller.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ def show
1313
}
1414
end
1515
@items += @financial_link.financial_transactions.map do |ft|
16+
ft_note =
17+
if ft.group_order
18+
view_context.link_to ft.note, new_finance_order_path(order_id: ft.group_order.order.id)
19+
else
20+
ft.note
21+
end
1622
{
1723
date: ft.created_on,
1824
type: t('activerecord.models.financial_transaction'),
19-
description: "#{ft.ordergroup_name}: #{ft.note}",
25+
description: "#{ft.ordergroup_name}: #{ft_note}",
2026
amount: ft.amount,
2127
link_to: finance_group_transactions_path(ft.ordergroup),
2228
remove_path: remove_financial_transaction_finance_link_path(@financial_link, ft)
@@ -80,8 +86,7 @@ def create_financial_transaction
8086
end
8187

8288
def index_financial_transaction
83-
@financial_transactions = FinancialTransaction.without_financial_link.includes(:financial_transaction_type,
84-
:ordergroup)
89+
@financial_transactions = FinancialTransaction.without_financial_link.includes(:financial_transaction_type, :ordergroup, :group_order)
8590
end
8691

8792
def add_financial_transaction

app/models/order.rb

+15-4
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,13 @@ def finish!(user)
271271
end
272272

273273
# Sets order.status to 'close' and updates all Ordergroup.account_balances
274-
def close!(user, transaction_type = nil)
274+
def close!(user, transaction_type = nil, financial_link = nil, create_foodcoop_transaction: false)
275275
raise I18n.t('orders.model.error_closed') if closed?
276276

277277
update_price_of_group_orders!
278278

279279
transaction do # Start updating account balances
280-
charge_group_orders!(user, transaction_type)
280+
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)
@@ -286,6 +286,17 @@ def close!(user, transaction_type = nil)
286286
end
287287
end
288288

289+
if create_foodcoop_transaction
290+
ft = FinancialTransaction.new({
291+
financial_transaction_type: transaction_type,
292+
user: user,
293+
amount: sum(:groups),
294+
note: transaction_note,
295+
financial_link: financial_link
296+
})
297+
ft.save!
298+
end
299+
289300
update!(state: 'closed', updated_by: user, foodcoop_result: profit)
290301
end
291302
end
@@ -397,12 +408,12 @@ def update_price_of_group_orders!
397408
group_orders.each(&:update_price!)
398409
end
399410

400-
def charge_group_orders!(user, transaction_type = nil)
411+
def charge_group_orders!(user, transaction_type = nil, financial_link = nil)
401412
note = transaction_note
402413
group_orders.includes(:ordergroup).find_each do |group_order|
403414
if group_order.ordergroup
404415
price = group_order.total * -1 # decrease! account balance
405-
group_order.ordergroup.add_financial_transaction!(price, note, user, transaction_type, nil, group_order)
416+
group_order.ordergroup.add_financial_transaction!(price, note, user, transaction_type, financial_link, group_order)
406417
end
407418
end
408419
end

app/views/admin/configs/_tab_payment.html.haml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
= config_input_field form, :minimum_balance, as: :decimal, class: 'input-small'
1313
= config_input form, :charge_members_manually, as: :boolean
1414
= config_input form, :use_iban, as: :boolean
15+
= config_input form, :use_financial_links, as: :boolean
1516
= config_input form, :use_self_service, as: :boolean
1617

1718
%h4= t '.schedule_title'

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

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
%tr{:class => cycle('even', 'odd')}
1010
%td= group_order.ordergroup_name
1111
%td.numeric= number_to_currency(group_order.total)
12+
- if FoodsoftConfig[:use_financial_links]
13+
%p
14+
%label
15+
= check_box_tag :create_financial_link, true, params.fetch(:create_financial_link, true)
16+
= t('.create_financial_link')
17+
%label
18+
= check_box_tag :create_foodcoop_transaction, true, params.fetch(:create_foodcoop_transaction, true)
19+
= t('.create_foodcoop_transaction', sum: number_to_currency(@order.sum(:groups)))
1220
.form-actions
1321
= submit_tag t('.clear'), class: 'btn btn-primary'
1422
= link_to t('.or_cancel'), new_finance_order_path(order_id: @order.id)

app/views/finance/financial_links/_index_financial_transaction.html.haml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
%tr
88
%th= heading_helper FinancialTransaction, :created_on
99
%th= heading_helper FinancialTransaction, :ordergroup
10+
%th= heading_helper FinancialTransaction, :note
1011
- if FinancialTransactionType.has_multiple_types
1112
%th= heading_helper FinancialTransaction, :financial_transaction_type
1213
%th= heading_helper FinancialTransaction, :amount
@@ -15,6 +16,7 @@
1516
%tr
1617
%td= link_to format_time(t.created_on), add_financial_transaction_finance_link_path(@financial_link, financial_transaction: t.id), method: :put
1718
%td= t.ordergroup_name
19+
%td= render 'finance/financial_transactions/order_note', financial_transaction:t, with_grouporder_link: false
1820
- if FinancialTransactionType.has_multiple_types
1921
%td= h t.financial_transaction_type.name
2022
%td= number_to_currency t.amount

app/views/finance/financial_links/show.html.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
- else
2828
= format_date item[:date]
2929
%td= item[:type]
30-
%td= item[:description]
30+
%td= sanitize item[:description]
3131
%td.numeric{style: 'width:5em'}= format_currency item[:amount]
32-
%td= link_to t('ui.delete'), item[:remove_path], :data => {:confirm => t('ui.confirm_delete', name: item[:description])}, :method => :delete,
32+
%td= link_to t('.remove_from_link'), item[:remove_path], :data => {:confirm => t('.remove_from_link_confirm')}, :method => :delete,
3333
class: 'btn btn-danger btn-mini'
3434

3535
%p
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- financial_transaction = local_assigns[:financial_transaction]
2+
- with_grouporder_link = local_assigns[:with_grouporder_link]
3+
- if financial_transaction.group_order
4+
- if with_grouporder_link
5+
= link_to financial_transaction.note, financial_transaction.group_order
6+
- else
7+
= link_to financial_transaction.note, new_finance_order_path(order_id: financial_transaction.group_order.order.id)
8+
- else
9+
= financial_transaction.note

app/views/finance/financial_transactions/_transactions.html.haml

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- with_ordergroup = local_assigns[:with_ordergroup]
22
- with_hidden = local_assigns[:with_hidden]
33
- with_csv = local_assigns[:with_csv]
4+
- with_grouporder_links = local_assigns[:with_grouporder_links]
45
- with_payment = @financial_transactions.with_payment_plugin.any?
56
.pull-right
67
- if with_csv
@@ -36,7 +37,7 @@
3637
- @financial_transactions.each do |t|
3738
%tr{class: "#{'deleted_row' if t.hidden?}"}
3839
%td
39-
- if t.financial_link
40+
- if t.financial_link && current_user.role_finance?
4041
= link_to format_time(t.created_on), finance_link_path(t.financial_link)
4142
- else
4243
= format_time(t.created_on)
@@ -45,11 +46,7 @@
4546
%td= h show_user(t.user)
4647
- if FinancialTransactionType.has_multiple_types
4748
%td= h t.financial_transaction_type.name
48-
%td
49-
- if t.group_order
50-
= link_to t.note, t.group_order
51-
- else
52-
= t.note
49+
%td= render "finance/financial_transactions/order_note", financial_transaction:t, with_grouporder_link: with_grouporder_links
5350
- if with_payment
5451
%td= t.payment_plugin
5552
%td= t.payment_method

app/views/finance/financial_transactions/new_collection.html.haml

+5-7
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,14 @@
6868
%p
6969
= link_to t('.new_ordergroup'), '#', 'data-add-transaction' => true, class: 'btn'
7070
= link_to t('.add_all_ordergroups'), '#', 'data-add-all-ordergroups' => true, class: 'btn'
71-
- if FinancialTransaction.where(ordergroup: nil).any?
71+
- if FoodsoftConfig[:use_financial_links]
7272
%p
7373
%label
74-
= check_box_tag :create_foodcoop_transaction, true, params[:create_foodcoop_transaction]
75-
= t('.create_foodcoop_transaction')
76-
- if BankAccount.any?
77-
%p
78-
%label
79-
= check_box_tag :create_financial_link, true, params[:create_financial_link]
74+
= check_box_tag :create_financial_link, true, params.fetch(:create_financial_link, true)
8075
= t('.create_financial_link')
76+
%label
77+
= check_box_tag :create_foodcoop_transaction, true, params.fetch(:create_foodcoop_transaction, true)
78+
= t('.create_foodcoop_transaction')
8179
%p
8280
- Ordergroup.custom_fields.each do |f|
8381
- if f[:financial_transaction_source]

app/views/finance/ordergroups/index.html.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
- content_for :actionbar do
44
= link_to t('.show_all'), finance_transactions_path, class: 'btn'
5-
= link_to t('.show_foodcoop'), finance_foodcoop_financial_transactions_path, class: 'btn'
6-
- if FinancialLink.any?
5+
- if FoodsoftConfig[:use_financial_links]
6+
= link_to t('.show_foodcoop'), finance_foodcoop_financial_transactions_path, class: 'btn'
77
= link_to t('.new_financial_link'), finance_links_path, method: :post, class: 'btn'
88
= link_to t('.new_transaction'), finance_new_transaction_collection_path, class: 'btn btn-primary'
99

app/views/home/index.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
%td= h(show_user(ft.user))
8686
- if FinancialTransactionType.has_multiple_types
8787
%td= h(ft.financial_transaction_type.name)
88-
%td= h(ft.note)
88+
%td= h(render "finance/financial_transactions/order_note", financial_transaction:ft, with_grouporder_link: true)
8989
- if with_payment
9090
%td= h(ft.payment_state)
9191
- FinancialTransactionClass.sorted.each do |fc|

app/views/home/ordergroup.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
'data-submit-onchange' => true, class: 'form-search' do
3232
= text_field_tag :query, params[:query], class: 'input-medium search-query',
3333
placeholder: t('.search')
34-
#transactions= render "finance/financial_transactions/transactions", with_csv: false
34+
#transactions= render "finance/financial_transactions/transactions", with_csv: false, with_grouporder_links: true

config/app_config.yml.SAMPLE

+18
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ default: &defaults
6868
# not fully enforced right now, since the check is only client-side
6969
#minimum_balance: 0
7070

71+
# When you keep track of who received what elsewhere (e.g. on paper), and you don't want to
72+
# enter this into Foodsoft, set this to true. You'll need to charge member accounts
73+
# manually (using "Add new transactions"). You still need to settle orders in the
74+
# balancing screen, but this will not charge any member accounts.
75+
#charge_members_manually: true
76+
77+
# When enabled, supplier and user provide an additonal field for storing the international bank account number.
78+
#use_iban: true
79+
80+
# When enabled, options to create financial links will be shown, which can group associated
81+
# financial transactions, invoices, and bank transactions. Also, options to create foodcoop transactions
82+
# will be shown (transactions which aren't assigned to any ordergroup, but serve as balancing entries
83+
# for double-entry accounting.)
84+
#use_financial_links: true
85+
86+
# When enabled, members are able to use selected balancing functions on their own.
87+
#use_self_service: true
88+
7189
# how many days there are between two periodic tasks
7290
#tasks_period_days: 7
7391
# how many days upfront periodic tasks are created

config/locales/de.yml

+19-12
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ de:
632632
use_apple_points: Wenn das Apfel Punktesystem aktiviert ist, ist es erforderlich, dass Mitglieder Aufgaben erledigen um bestellen zu können.
633633
use_boxfill: Wenn aktiviert, können Benutzer nahe am Ende der Bestellung diese nur mehr so verändern, dass sich die Gesamtsumme erhöht. Dies hilft beim auffüllen der verbleibenden Kisten. Es muss trotzdem noch das Kistenauffülldatum bei der Bestellung gesetzt werden.
634634
use_iban: Zusätzlich Feld für die internationale Kontonummer bei Benutzern und Lieferanten anzeigen
635+
use_financial_links: Wenn aktiviert, werden Optionen zum Anlegen von Finanzlinks angezeigt, die zusammenhängende Kontotransaktionen, Rechnungen und Banktransaktionen gruppieren können. Außerdem werden Optionen zum Anlegen von Foodcoop-Transaktionen angezeigt (Transaktionen, die keiner Bestellgruppe zugeordnet sind, sondern als Ausgleichsbuchungen zwecks doppelter Buchführung dienen).
635636
use_nick: Benutzernamen anstatt reale Namen zeigen und verwenden, jeder Benutzer muss dazu einen Benutzernamen (Spitznamen) haben.
636637
use_self_service: Wenn aktiviert, können Benutzer_innen selbständig dafür freigegebene Abrechungsfunktionen nutzen.
637638
webstats_tracking_code: Tracking Code für Webseitenanalyse (wie Piwik oder Google Analytics), leer lassen wenn keine Analyse erfolgt
@@ -691,6 +692,7 @@ de:
691692
use_apple_points: Apfelpunkte verwenden
692693
use_boxfill: Kistenauffüllphase
693694
use_iban: IBAN verwenden
695+
use_financial_links: Finanzlinks & Foodcoop-Transaktionen verwenden
694696
use_nick: Benutzernamen verwenden
695697
use_self_service: Selbstbedienung verwenden
696698
webstats_tracking_code: Code für Websiteanalysetool
@@ -792,6 +794,8 @@ de:
792794
confirm:
793795
clear: Abrechnen
794796
first_paragraph: 'Wenn die Bestellung abgerechnet wird, werden ebenfalls alle Gruppenkonten aktualisiert.<br />Die Konten werden wie folgt belastet:'
797+
create_financial_link: Erstelle einen gemeinsamen Finanzlink für die neuen Transaktionen.
798+
create_foodcoop_transaction: Erstelle eine Foodcoop-Transaktion mit der invertierten Summe (%{sum}).
795799
or_cancel: oder zurück zur Abrechnung
796800
title: Bestellung abrechnen
797801
edit_note:
@@ -886,11 +890,11 @@ de:
886890
notice: Rechnung wurde erstellt.
887891
financial_links:
888892
add_bank_transaction:
889-
notice: Verlinkung wurde zu der Banktransaktion wurde hinzugefügt.
893+
notice: Verlinkung zu der Banktransaktion wurde hinzugefügt.
890894
add_financial_transaction:
891-
notice: Verlinkung wurde zu der Kontotransaktion wurde hinzugefügt.
895+
notice: Verlinkung zu der Kontotransaktion wurde hinzugefügt.
892896
add_invoice:
893-
notice: Verlinkung wurde zu der Rechnung wurde hinzugefügt.
897+
notice: Verlinkung zu der Rechnung wurde hinzugefügt.
894898
create:
895899
notice: Ein neuer Finanzlink wurde erstellt.
896900
create_financial_transaction:
@@ -904,11 +908,11 @@ de:
904908
new_financial_transaction:
905909
title: Neue Kontotransaktion hinzufügen
906910
remove_bank_transaction:
907-
notice: Verlinkung wurde zu der Banktransaktion wurde entfernt.
911+
notice: Verlinkung zu der Banktransaktion wurde entfernt.
908912
remove_financial_transaction:
909-
notice: Verlinkung wurde zu der Kontotransaktion wurde entfernt.
913+
notice: Verlinkung zu der Kontotransaktion wurde entfernt.
910914
remove_invoice:
911-
notice: Verlinkung wurde zu der Rechnung wurde entfernt.
915+
notice: Verlinkung zu der Rechnung wurde entfernt.
912916
show:
913917
add_bank_transaction: Banktransaktion hinzufügen
914918
add_financial_transaction: Kontotransaktion hinzufügen
@@ -919,6 +923,8 @@ de:
919923
new_financial_transaction: Neue Kontotransaktion hinzufügen
920924
title: Finanzlink %{number}
921925
type: Typ
926+
remove_from_link: Von Link entfernen
927+
remove_from_link_confirm: Hierdurch wird die Transaktion nicht gelöscht, sondern nur vom Finanzlink entfernt. Möchtest du fortfahren?
922928
financial_transactions:
923929
controller:
924930
create:
@@ -934,29 +940,30 @@ de:
934940
last_updated_at: "(zuletzt aktualisiert vor %{when})"
935941
new_transaction: Neue Transaktion anlegen
936942
title: Kontoauszug für %{name}
943+
title_foodcoop: Foodcoop-Kontoauszug
937944
index_collection:
938945
show_groups: Konten verwalten
939946
title: Kontotransaktionen
940947
new:
941948
paragraph: Hier kannst du der Bestellgruppe <b>%{name}</b> Geld gutschreiben/abziehen.
942-
paragraph_foodcoop: Hier kannst du der <b>Foodcooop</b> Geld gutschreiben/abziehen.
949+
paragraph_foodcoop: Hier kannst du der <b>Foodcoop</b> Geld gutschreiben/abziehen.
943950
title: Neue Transaktion
944951
new_collection:
945952
add_all_ordergroups: Alle Bestellgruppen hinzufügen
946953
add_all_ordergroups_custom_field: Alle Bestellgruppen mit %{label} hinzufügen
947954
create_financial_link: Erstelle einen gemeinsamen Finanzlink für die neuen Transaktionen.
948-
create_foodcoop_transaction: Erstelle einen Transaktion mit der der invertieten Summe für die Foodcoop (für den Fall der "doppelte Buchführung")
955+
create_foodcoop_transaction: Erstelle eine Foodcoop-Transaktion mit der invertierten Summe (für den Fall der "doppelten Buchführung")
949956
new_ordergroup: Weitere Bestellgruppe hinzufügen
950957
save: Transaktionen speichern
951958
set_balance: Setze den Kontostand der Bestellgruppe auf den eingegebenen Betrag.
952-
sidebar: Hier kannst Du mehrere Konten gleichzeitig aktualsieren. Z.B. alle Überweisungen der Bestellgruppen aus einem Kontoauszug.
959+
sidebar: Hier kannst Du mehrere Konten gleichzeitig aktualisieren. Z.B. alle Überweisungen der Bestellgruppen aus einem Kontoauszug.
953960
title: Mehrere Konten aktualisieren
954961
ordergroup:
955962
remove: Entfernen
956963
remove_group: Gruppe enfernen
957964
transactions:
958-
confirm_revert: Wills du %{name} wirklich rückgängig machen? Hierbei wird eine zusätzliche Transaktion mit dem invertierten Betrag hinzugefügt und gemeinsam mit der originalen Transaktion versteckt. Diese versteckten Transaktionen sind nur über die Option 'Versteckte anzeigen' sichtbar und können von normalen Benutzer_innen überhaupt nicht angezeigt werden.
959-
revert_title: Transaktion rückgängig machen, um sie vor normalen Benutzer_innen versteckt.
965+
confirm_revert: Willst du %{name} wirklich rückgängig machen? Hierbei wird eine zusätzliche Transaktion mit dem invertierten Betrag hinzugefügt und gemeinsam mit der originalen Transaktion versteckt. Diese versteckten Transaktionen sind nur über die Option 'Versteckte anzeigen' sichtbar und können von normalen Benutzer_innen überhaupt nicht angezeigt werden.
966+
revert_title: Transaktion rückgängig machen und vor normalen Benutzer_innen verstecken.
960967
transactions_search:
961968
show_hidden: Versteckte anzeigen
962969
index:
@@ -990,7 +997,7 @@ de:
990997
new_financial_link: Neuer Finanzlink
991998
new_transaction: Neue Überweisungen eingeben
992999
show_all: Alle Transaktionen
993-
show_foodcoop: Foodcoop Transaktionen
1000+
show_foodcoop: Foodcoop-Transaktionen
9941001
title: Konten verwalten
9951002
ordergroups:
9961003
account_statement: Kontoauszug

0 commit comments

Comments
 (0)