1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

rails DB model for accounting periods

This commit is contained in:
Sylvain 2019-01-07 12:29:52 +01:00
parent 0a59dc6b5d
commit 0a684c8e13
8 changed files with 80 additions and 1 deletions

View File

@ -332,6 +332,7 @@ This can be achieved doing the following:
- `db/migrate/20150604131525_add_meta_data_to_notifications.rb` is using [jsonb](https://www.postgresql.org/docs/9.4/static/datatype-json.html), a PostgreSQL 9.4+ datatype.
- `db/migrate/20160915105234_add_transformation_to_o_auth2_mapping.rb` is using [jsonb](https://www.postgresql.org/docs/9.4/static/datatype-json.html), a PostgreSQL 9.4+ datatype.
- `db/migrate/20181217103441_migrate_settings_value_to_history_values.rb` is using `SELECT DISTINCT ON`.
- `db/migrate/20190107111749_protect_accounting_periods.rb` is using `CREATE RULE` and `DROP RULE`.
- If you intend to contribute to the project code, you will need to run the test suite with `rake test`.
This also requires your user to have the _SUPERUSER_ role.
Please see the [known issues](#known-issues) section for more information about this.

View File

@ -0,0 +1,12 @@
'use strict';
Application.Services.factory('AccountingPeriod', ['$resource', function ($resource) {
return $resource('/api/accounting_period/:id',
{ id: '@id' }, {
lastClosingEnd: {
method: 'GET',
url: '/api/accounting_period/last_closing_end'
}
}
);
}]);

View File

@ -0,0 +1,8 @@
class AccountingPeriod < ActiveRecord::Base
before_destroy { false }
before_update { false }
def delete
false
end
end

View File

@ -0,0 +1,15 @@
class CreateAccountingPeriods < ActiveRecord::Migration
def change
create_table :accounting_periods do |t|
t.date :start_at
t.date :end_at
t.datetime :closed_at
t.integer :closed_by
t.timestamps null: false
end
add_foreign_key :accounting_periods, :users, column: :closed_by, primary_key: :id
end
end

View File

@ -0,0 +1,13 @@
class ProtectAccountingPeriods < ActiveRecord::Migration
# PostgreSQL only
def up
execute('CREATE RULE accounting_periods_del_protect AS ON DELETE TO accounting_periods DO INSTEAD NOTHING;')
execute('CREATE RULE accounting_periods_upd_protect AS ON UPDATE TO accounting_periods DO INSTEAD NOTHING;')
end
def down
execute('DROP RULE IF EXISTS accounting_periods_del_protect ON accounting_periods;')
execute('DROP RULE IF EXISTS accounting_periods_upd_protect ON accounting_periods;')
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181217110454) do
ActiveRecord::Schema.define(version: 20190107111749) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -31,6 +31,15 @@ ActiveRecord::Schema.define(version: 20181217110454) do
add_index "abuses", ["signaled_type", "signaled_id"], name: "index_abuses_on_signaled_type_and_signaled_id", using: :btree
create_table "accounting_periods", force: :cascade do |t|
t.date "start_at"
t.date "end_at"
t.datetime "closed_at"
t.integer "closed_by"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "addresses", force: :cascade do |t|
t.string "address", limit: 255
t.string "street_number", limit: 255
@ -856,6 +865,7 @@ ActiveRecord::Schema.define(version: 20181217110454) do
add_index "wallets", ["user_id"], name: "index_wallets_on_user_id", using: :btree
add_foreign_key "accounting_periods", "users", column: "closed_by"
add_foreign_key "availability_tags", "availabilities"
add_foreign_key "availability_tags", "tags"
add_foreign_key "event_price_categories", "events"

13
test/fixtures/accounting_periods.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
twothousandsseventeen:
start_at: 2017-01-01
end_at: 2017-12-31
closed_at: 2018-01-04 18:12:07
closed_by:
twothousandseighteen:
start_at: 2018-01-01
end_at: 2018-12-31
closed_at: 2019-01-07 11:36:32
closed_by:

View File

@ -0,0 +1,7 @@
require 'test_helper'
class AccountingPeriodTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end