diff --git a/README.md b/README.md index 645c5c945..93a0ae94f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/app/assets/javascripts/services/accounting_period.js b/app/assets/javascripts/services/accounting_period.js new file mode 100644 index 000000000..b5a92433b --- /dev/null +++ b/app/assets/javascripts/services/accounting_period.js @@ -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' + } + } + ); +}]); diff --git a/app/models/accounting_period.rb b/app/models/accounting_period.rb new file mode 100644 index 000000000..824e5e3f4 --- /dev/null +++ b/app/models/accounting_period.rb @@ -0,0 +1,8 @@ +class AccountingPeriod < ActiveRecord::Base + before_destroy { false } + before_update { false } + + def delete + false + end +end diff --git a/db/migrate/20190107103632_create_accounting_periods.rb b/db/migrate/20190107103632_create_accounting_periods.rb new file mode 100644 index 000000000..32dd47a33 --- /dev/null +++ b/db/migrate/20190107103632_create_accounting_periods.rb @@ -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 diff --git a/db/migrate/20190107111749_protect_accounting_periods.rb b/db/migrate/20190107111749_protect_accounting_periods.rb new file mode 100644 index 000000000..3bc97965b --- /dev/null +++ b/db/migrate/20190107111749_protect_accounting_periods.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 3687c8c06..403316d9a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/test/fixtures/accounting_periods.yml b/test/fixtures/accounting_periods.yml new file mode 100644 index 000000000..473afb877 --- /dev/null +++ b/test/fixtures/accounting_periods.yml @@ -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: diff --git a/test/models/accounting_period_test.rb b/test/models/accounting_period_test.rb new file mode 100644 index 000000000..c797cea83 --- /dev/null +++ b/test/models/accounting_period_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class AccountingPeriodTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end