Adopt model to allow FinancialTransaction without an ordergroup
This will allow us to add accounting for the foodcoop itself, to support listing for spendings independent of the order (e.g. rent, electricity).
This commit is contained in:
parent
1053b3883d
commit
1a49bee42d
11 changed files with 22 additions and 7 deletions
|
@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base
|
|||
include Concerns::FoodcoopScope
|
||||
include Concerns::Auth
|
||||
include Concerns::Locale
|
||||
include PathHelper
|
||||
helper_method :current_user
|
||||
helper_method :available_locales
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ class Finance::BaseController < ApplicationController
|
|||
before_action :authenticate_finance
|
||||
|
||||
def index
|
||||
@financial_transactions = FinancialTransaction.includes(:ordergroup).order('created_on DESC').limit(8)
|
||||
@financial_transactions = FinancialTransaction.with_ordergroup.includes(:ordergroup).order(created_on: :desc).limit(8)
|
||||
@orders = Order.finished_not_closed.includes(:supplier).limit(8)
|
||||
@unpaid_invoices = Invoice.unpaid.includes(:supplier).limit(8)
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class Finance::FinancialLinksController < Finance::BaseController
|
|||
{
|
||||
date: ft.created_on,
|
||||
type: t('activerecord.models.financial_transaction'),
|
||||
description: "#{ft.ordergroup.name}: #{ft.note}",
|
||||
description: "#{ft.ordergroup_name}: #{ft.note}",
|
||||
amount: ft.amount,
|
||||
link_to: finance_ordergroup_transactions_path(ft.ordergroup),
|
||||
remove_path: remove_financial_transaction_finance_link_path(@financial_link, ft)
|
||||
|
|
|
@ -9,12 +9,13 @@ class FinancialTransaction < ApplicationRecord
|
|||
belongs_to :reverts, class_name: 'FinancialTransaction', foreign_key: 'reverts_id'
|
||||
has_one :reverted_by, class_name: 'FinancialTransaction', foreign_key: 'reverts_id'
|
||||
|
||||
validates_presence_of :amount, :note, :user_id, :ordergroup_id
|
||||
validates_presence_of :amount, :note, :user_id
|
||||
validates_numericality_of :amount, greater_then: -100_000,
|
||||
less_than: 100_000
|
||||
|
||||
scope :visible, -> { joins('LEFT JOIN financial_transactions r ON financial_transactions.id = r.reverts_id').where('r.id IS NULL').where(reverts: nil) }
|
||||
scope :without_financial_link, -> { where(financial_link: nil) }
|
||||
scope :with_ordergroup, -> { where.not(ordergroup: nil) }
|
||||
|
||||
localize_input_of :amount
|
||||
|
||||
|
@ -54,6 +55,10 @@ class FinancialTransaction < ApplicationRecord
|
|||
reverts.present? || reverted_by.present?
|
||||
end
|
||||
|
||||
def ordergroup_name
|
||||
ordergroup ? ordergroup.name : I18n.t('model.financial_transaction.foodcoop_name')
|
||||
end
|
||||
|
||||
# @todo rename in model, see #575
|
||||
def created_at
|
||||
created_on
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
- for t in @financial_transactions
|
||||
%tr
|
||||
%td= link_to format_time(t.created_on), add_financial_transaction_finance_link_path(@financial_link, financial_transaction: t.id), method: :put
|
||||
%td= t.ordergroup.name
|
||||
%td= t.ordergroup_name
|
||||
- if FinancialTransactionType.has_multiple_types
|
||||
%td= h t.financial_transaction_type.name
|
||||
%td= number_to_currency t.amount
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
- else
|
||||
= format_time(t.created_on)
|
||||
- if with_ordergroup
|
||||
%td= h link_to t.ordergroup.name, finance_ordergroup_transactions_path(t.ordergroup)
|
||||
%td= h link_to t.ordergroup_name, finance_ordergroup_transactions_path(t.ordergroup)
|
||||
%td= h show_user(t.user)
|
||||
- if FinancialTransactionType.has_multiple_types
|
||||
%td= h t.financial_transaction_type.name
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
- @financial_transactions.each do |ft|
|
||||
%tr
|
||||
%td= format_date(ft.created_on)
|
||||
%td= ft.ordergroup.name
|
||||
%td= ft.ordergroup_name
|
||||
%td= ft.note
|
||||
%td.numeric= format_currency ft.amount
|
||||
.span6
|
||||
|
|
|
@ -1272,6 +1272,8 @@ de:
|
|||
model:
|
||||
delivery:
|
||||
each_stock_article_must_be_unique: Lieferung darf jeden Lagerartikel höchstens einmal auflisten.
|
||||
financial_transaction:
|
||||
foodcoop_name: Foodcoop
|
||||
financial_transaction_type:
|
||||
no_delete_last: Es muss mindestens ein Kontotransaktionstyp existieren.
|
||||
group_order:
|
||||
|
|
|
@ -1311,6 +1311,8 @@ en:
|
|||
model:
|
||||
delivery:
|
||||
each_stock_article_must_be_unique: Each stock article must not be listed more than once.
|
||||
financial_transaction:
|
||||
foodcoop_name: Foodcoop
|
||||
financial_transaction_type:
|
||||
no_delete_last: At least one financial transaction type must exist.
|
||||
group_order:
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AllowEmtpyOrdergroupInFinancialTransaction < ActiveRecord::Migration
|
||||
def change
|
||||
change_column_null :financial_transactions, :ordergroup_id, true
|
||||
end
|
||||
end
|
|
@ -130,7 +130,7 @@ ActiveRecord::Schema.define(version: 20181205010000) do
|
|||
add_index "financial_transaction_types", ["name_short"], name: "index_financial_transaction_types_on_name_short", using: :btree
|
||||
|
||||
create_table "financial_transactions", force: :cascade do |t|
|
||||
t.integer "ordergroup_id", limit: 4, default: 0, null: false
|
||||
t.integer "ordergroup_id", limit: 4
|
||||
t.decimal "amount", precision: 8, scale: 2, default: 0, null: false
|
||||
t.text "note", limit: 65535, null: false
|
||||
t.integer "user_id", limit: 4, default: 0, null: false
|
||||
|
|
Loading…
Reference in a new issue