Add button to create a new empty FinacialLink

This commit is contained in:
Patrick Gansterer 2021-02-08 02:44:07 +01:00
parent 1656efd845
commit 0e77a0e77c
5 changed files with 15 additions and 1 deletions

View file

@ -36,7 +36,7 @@ class Finance::FinancialLinksController < Finance::BaseController
end end
def create def create
@financial_link = FinancialLink.new @financial_link = FinancialLink.first_unused_or_create
if params[:bank_transaction] then if params[:bank_transaction] then
bank_transaction = BankTransaction.find(params[:bank_transaction]) bank_transaction = BankTransaction.find(params[:bank_transaction])
bank_transaction.update_attribute :financial_link, @financial_link bank_transaction.update_attribute :financial_link, @financial_link

View file

@ -4,6 +4,12 @@ class FinancialLink < ApplicationRecord
has_many :invoices has_many :invoices
scope :incomplete, -> { with_full_sum.where.not('full_sums.full_sum' => 0) } scope :incomplete, -> { with_full_sum.where.not('full_sums.full_sum' => 0) }
scope :unused, -> {
includes(:bank_transactions, :financial_transactions, :invoices)
.where(bank_transactions: { financial_link_id: nil })
.where(financial_transactions: { financial_link_id: nil })
.where(invoices: { financial_link_id: nil})
}
scope :with_full_sum, -> { scope :with_full_sum, -> {
select(:id, :note, :full_sum).joins(<<-SQL) select(:id, :note, :full_sum).joins(<<-SQL)
LEFT JOIN ( LEFT JOIN (
@ -27,4 +33,8 @@ class FinancialLink < ApplicationRecord
) full_sums ON full_sums.id = financial_links.id ) full_sums ON full_sums.id = financial_links.id
SQL SQL
} }
def self.first_unused_or_create
unused.first || create
end
end end

View file

@ -3,6 +3,8 @@
- content_for :actionbar do - content_for :actionbar do
= link_to t('.show_all'), finance_transactions_path, class: 'btn' = link_to t('.show_all'), finance_transactions_path, class: 'btn'
= link_to t('.show_foodcoop'), finance_foodcoop_financial_transactions_path, class: 'btn' = link_to t('.show_foodcoop'), finance_foodcoop_financial_transactions_path, class: 'btn'
- if FinancialLink.any?
= link_to t('.new_financial_link'), finance_links_path, method: :post, class: 'btn'
= link_to t('.new_transaction'), finance_new_transaction_collection_path, class: 'btn btn-primary' = link_to t('.new_transaction'), finance_new_transaction_collection_path, class: 'btn btn-primary'
.well.well-small .well.well-small

View file

@ -955,6 +955,7 @@ de:
title: Unbezahlte Rechnungen title: Unbezahlte Rechnungen
ordergroups: ordergroups:
index: index:
new_financial_link: Neuer Finanzlink
new_transaction: Neue Überweisungen eingeben new_transaction: Neue Überweisungen eingeben
show_all: Alle Transaktionen show_all: Alle Transaktionen
show_foodcoop: Foodcoop Transaktionen show_foodcoop: Foodcoop Transaktionen

View file

@ -956,6 +956,7 @@ en:
title: Unpaid invoices title: Unpaid invoices
ordergroups: ordergroups:
index: index:
new_financial_link: New financial link
new_transaction: Add new transactions new_transaction: Add new transactions
show_all: All transactions show_all: All transactions
show_foodcoop: Foodcoop transaktions show_foodcoop: Foodcoop transaktions