forked from foodcoops/foodsoft
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add class and type for financial transactions foodcoops#367
This change introduces two new data types to group the financial transactions. Now every transaction has a "type", which itself belongs to a "class". Types should be used add structured information to an transaction, instead of writing it into the notice textfield. E.g. this could be used to have different types depending on the source of money (cash vs. bank transfer). Classes are shown as different columns in the tables and will be uses to group transactions of specific types. They should be used if not the whole amount of ordergroup should be used to order fodd. E.g. if there is a deposit or membership fee, which is independent of the normal credit. This will allow us to implement additional features based on classes in the future. E.g. the sum of transactions in the "membership fee" class must be positive to allow food orders or show a big warning if it is bellow a certain value.
- Loading branch information
Showing
29 changed files
with
224 additions
and
12 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
app/controllers/admin/financial_transaction_classes_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Admin::FinancialTransactionClassesController < Admin::BaseController | ||
inherit_resources | ||
|
||
def index | ||
@financial_transaction_classes = FinancialTransactionClass.order('name ASC') | ||
end | ||
|
||
def destroy | ||
@financial_transaction_class = FinancialTransactionClass.find(params[:id]) | ||
@financial_transaction_class.destroy | ||
redirect_to admin_financial_transaction_classes_url, notice: t('admin.financial_transaction_classes.destroy.notice') | ||
rescue => error | ||
redirect_to admin_financial_transaction_classes_url, alert: t('admin.financial_transaction_classes.destroy.error', error: error.message) | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
app/controllers/admin/financial_transaction_types_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Admin::FinancialTransactionTypesController < Admin::BaseController | ||
inherit_resources | ||
|
||
def index | ||
@financial_transaction_types = FinancialTransactionType.order('name ASC') | ||
end | ||
|
||
def destroy | ||
@financial_transaction_type = FinancialTransactionClass.find(params[:id]) | ||
@financial_transaction_type.destroy | ||
redirect_to admin_financial_transaction_types_url, notice: t('admin.financial_transaction_types.destroy.notice') | ||
rescue => error | ||
redirect_to admin_financial_transaction_types_url, alert: t('admin.financial_transaction_types.destroy.error', error: error.message) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class FinancialTransactionClass < ActiveRecord::Base | ||
has_many :financial_transaction_types | ||
|
||
validates :name, presence: true | ||
|
||
scope :table_columns, -> { order(name: :asc) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class FinancialTransactionType < ActiveRecord::Base | ||
belongs_to :financial_transaction_class | ||
has_many :financial_transactions | ||
|
||
validates :name, presence: true | ||
validates :financial_transaction_class, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/views/admin/financial_transaction_classes/_form.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
= simple_form_for [:admin, @financial_transaction_class] do |f| | ||
= f.input :name | ||
.form-actions | ||
= f.button :submit | ||
= link_to t('ui.or_cancel'), :back |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- title t '.title' | ||
|
||
= render 'form' |
21 changes: 21 additions & 0 deletions
21
app/views/admin/financial_transaction_classes/index.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- title t '.title' | ||
|
||
- content_for :actionbar do | ||
= link_to t('.new_financial_transaction_class'), new_admin_financial_transaction_class_path, class: 'btn btn-primary' | ||
|
||
- content_for :sidebar do | ||
%p= t('.first_paragraph', url: link_to(t('.new_financial_transaction_classes'), new_admin_financial_transaction_class_path)).html_safe | ||
|
||
%table.table.table-striped | ||
%thead | ||
%tr | ||
%th= t '.name' | ||
%th= t 'ui.actions' | ||
%tbody | ||
- for financial_transaction_class in @financial_transaction_classes | ||
%tr | ||
%td= link_to financial_transaction_class.name, [:admin, financial_transaction_class] | ||
%td | ||
= link_to t('ui.edit'), edit_admin_financial_transaction_class_path(financial_transaction_class), class: 'btn btn-mini' | ||
= link_to t('ui.delete'), [:admin, financial_transaction_class], :data => {:confirm => t('admin.confirm', name: financial_transaction_class.name)}, | ||
:method => :delete, class: 'btn btn-mini btn-danger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- title t '.title' | ||
|
||
= render 'form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- title t '.title', name: @financial_transaction_class.name | ||
|
||
= link_to t('ui.edit'), edit_admin_financial_transaction_class_path(@financial_transaction_class), class: 'btn' | ||
= link_to t('ui.delete'), [:admin, @financial_transaction_class], :data => {:confirm => t('.confirm')}, :method => :delete, class: 'btn btn-danger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
= simple_form_for [:admin, @financial_transaction_type] do |f| | ||
= f.input :name | ||
= f.association :financial_transaction_class, :include_blank => false | ||
.form-actions | ||
= f.button :submit | ||
= link_to t('ui.or_cancel'), :back |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- title t '.title' | ||
|
||
= render 'form' |
21 changes: 21 additions & 0 deletions
21
app/views/admin/financial_transaction_types/index.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- title t '.title' | ||
|
||
- content_for :actionbar do | ||
= link_to t('.new_financial_transaction_type'), new_admin_financial_transaction_type_path, class: 'btn btn-primary' | ||
|
||
- content_for :sidebar do | ||
%p= t('.first_paragraph', url: link_to(t('.new_financial_transaction_types'), new_admin_financial_transaction_type_path)).html_safe | ||
|
||
%table.table.table-striped | ||
%thead | ||
%tr | ||
%th= t '.name' | ||
%th= t 'ui.actions' | ||
%tbody | ||
- for financial_transaction_type in @financial_transaction_types | ||
%tr | ||
%td= link_to financial_transaction_type.name, [:admin, financial_transaction_type] | ||
%td | ||
= link_to t('ui.edit'), edit_admin_financial_transaction_type_path(financial_transaction_type), class: 'btn btn-mini' | ||
= link_to t('ui.delete'), [:admin, financial_transaction_type], :data => {:confirm => t('admin.confirm', name: financial_transaction_type.name)}, | ||
:method => :delete, class: 'btn btn-mini btn-danger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- title t '.title' | ||
|
||
= render 'form' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- title t '.title', name: @financial_transaction_type.name | ||
|
||
%p | ||
%b= heading_helper(FinancialTransactionType, :financial_transaction_class) + ':' | ||
= @financial_transaction_type.financial_transaction_class.name | ||
|
||
= link_to t('ui.edit'), edit_admin_financial_transaction_type_path(@financial_transaction_type), class: 'btn' | ||
= link_to t('ui.delete'), [:admin, @financial_transaction_type], :data => {:confirm => t('.confirm')}, :method => :delete, class: 'btn btn-danger' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
db/migrate/20160219123220_create_financial_transaction_class_and_types.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CreateFinancialTransactionClassAndTypes < ActiveRecord::Migration | ||
def change | ||
create_table :financial_transaction_classes do |t| | ||
t.string :name, :null => false | ||
end | ||
|
||
create_table :financial_transaction_types do |t| | ||
t.string :name, :null => false | ||
t.references :financial_transaction_class, :null => false | ||
end | ||
|
||
change_table :financial_transactions do |t| | ||
t.references :financial_transaction_type | ||
end | ||
|
||
execute "INSERT INTO financial_transaction_classes (id, name) VALUES (1, '')" | ||
execute "INSERT INTO financial_transaction_types (id, name, financial_transaction_class_id) VALUES (1, 'Foodsoft', 1)" | ||
execute "UPDATE financial_transactions SET financial_transaction_type_id = 1" | ||
|
||
change_column_null :financial_transactions, :financial_transaction_type_id, false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'factory_girl' | ||
|
||
FactoryGirl.define do | ||
|
||
factory :financial_transaction_class do | ||
sequence(:name) { |n| Faker::Lorem.characters(rand(2..12)) + " ##{n}" } | ||
end | ||
|
||
factory :financial_transaction_type do | ||
sequence(:name) { |n| Faker::Lorem.words(rand(2..4)).join(' ') + " ##{n}" } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters