plutus 0.12.2 → 0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/README.markdown +21 -11
  3. data/app/assets/javascripts/plutus/application.js +1 -1
  4. data/app/assets/stylesheets/plutus/application.css +0 -1
  5. data/app/controllers/plutus/accounts_controller.rb +1 -1
  6. data/app/controllers/plutus/entries_controller.rb +6 -1
  7. data/app/controllers/plutus/reports_controller.rb +1 -1
  8. data/app/models/plutus/account.rb +13 -1
  9. data/app/models/plutus/amount.rb +2 -11
  10. data/app/models/plutus/amounts_extension.rb +3 -5
  11. data/app/models/plutus/asset.rb +1 -1
  12. data/app/models/plutus/credit_amount.rb +1 -1
  13. data/app/models/plutus/debit_amount.rb +1 -1
  14. data/app/models/plutus/entry.rb +10 -3
  15. data/app/models/plutus/equity.rb +1 -1
  16. data/app/models/plutus/expense.rb +1 -1
  17. data/app/models/plutus/liability.rb +1 -1
  18. data/app/models/plutus/revenue.rb +1 -1
  19. data/app/models/plutus/tenancy.rb +5 -1
  20. data/app/views/layouts/plutus/application.html.erb +0 -1
  21. data/app/views/plutus/entries/index.html.erb +9 -0
  22. data/app/views/plutus/reports/balance_sheet.html.erb +1 -1
  23. data/app/views/plutus/reports/income_statement.html.erb +2 -2
  24. data/{lib/generators/plutus/templates/migration.rb → db/migrate/20160422010135_create_plutus_tables.rb} +3 -9
  25. data/lib/generators/plutus/templates/tenant_migration.rb +1 -1
  26. data/lib/plutus.rb +2 -5
  27. data/lib/plutus/engine.rb +5 -0
  28. data/lib/plutus/version.rb +1 -1
  29. data/spec/controllers/accounts_controller_spec.rb +2 -2
  30. data/spec/controllers/entries_controller_spec.rb +2 -2
  31. data/spec/controllers/reports_controller_spec.rb +4 -4
  32. data/spec/factories/account_factory.rb +6 -6
  33. data/spec/factories/amount_factory.rb +3 -3
  34. data/spec/factories/entry_factory.rb +1 -1
  35. data/spec/factories/tenant_factory.rb +12 -0
  36. data/spec/models/account_spec.rb +71 -7
  37. data/spec/models/amount_spec.rb +6 -1
  38. data/spec/models/entry_spec.rb +27 -64
  39. data/spec/models/tenancy_spec.rb +26 -8
  40. data/spec/routing/accounts_routing_spec.rb +1 -1
  41. data/spec/routing/entries_routing_spec.rb +1 -1
  42. data/spec/spec_helper.rb +3 -2
  43. data/spec/support/account_shared_examples.rb +11 -11
  44. data/spec/support/amount_shared_examples.rb +4 -4
  45. data/spec/support/shoulda_matchers.rb +8 -0
  46. metadata +44 -43
  47. data/app/assets/javascripts/plutus/reports.js.coffee +0 -2
  48. data/lib/generators/plutus/templates/add_date_migration.rb +0 -6
  49. data/lib/generators/plutus/templates/update_migration.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ff6db3055f833f230341e09d485329f5e2150d7d
4
- data.tar.gz: bfc7ded7630f7a77c4bd79ebb17f723db77c7596
2
+ SHA256:
3
+ metadata.gz: 8d6d53fa47c9c392c0a240fadd36257b8716367a1694642d3597d338f6173a93
4
+ data.tar.gz: a918177e468ee3d2f47acd6fa62eeaceb1e2c604f86161e8c717c9b00927ced4
5
5
  SHA512:
6
- metadata.gz: 05d28ad8fabc751e2fcf36ca759a11d3daf8103b6e62c933a8933cfc6515a9fa9c510f602efbc4faf51bf3769d7e72886a7115d097cb048bb6c6a7517d3ef22e
7
- data.tar.gz: fb15f1b5870bff1159c0b3eab675f3298cd973e96ffa82740aed24263bd037750a59f33b5a5d975d9e5c50d9dda05dfe414782b68f6da76ea69a025d93a54c0e
6
+ metadata.gz: d84a78fe7b972cd457d27c9da70fac2c79dfeaf5bea80e26be2d131174c3750d4a59a3254214a96b51f871f1f7895a905811df8b25b2953587d77bce981108b1
7
+ data.tar.gz: cf15cc0e6c2492c7b15f1a2aba067737bc3816fabe59ee57f61f44f74ea84af417b7fc169d6028bf95de6bc693062586433d5fcbf55570c6292b722cdab1a40f
@@ -1,14 +1,14 @@
1
1
  Plutus
2
2
  =================
3
- [![Build Status](https://secure.travis-ci.org/mbulat/plutus.png?branch=master)](http://travis-ci.org/mbulat/plutus)
3
+ [![Build Status](https://travis-ci.org/mbulat/plutus.svg?branch=master)](https://travis-ci.org/mbulat/plutus) [![Coverage Status](https://coveralls.io/repos/github/mbulat/plutus/badge.svg?branch=master)](https://coveralls.io/github/mbulat/plutus?branch=master)
4
4
 
5
5
  The Plutus plugin is a Ruby on Rails Engine which provides a double entry accounting system for your application.
6
6
 
7
7
  Compatibility
8
8
  =============
9
9
 
10
- * Ruby versions: MRI 1.9.3 - 2.2, Rubinius 2.2, JRuby 1.7+
11
- * Rails versions: ~> 4.0
10
+ * Ruby versions: MRI 2.5+
11
+ * Rails versions: ~> 6.0
12
12
 
13
13
  For earlier versions, and upgrading, please see the section titled [Previous Versions](https://github.com/mbulat/plutus#previous-versions)
14
14
 
@@ -16,9 +16,7 @@ Installation
16
16
  ============
17
17
 
18
18
  - Add the gem to your Gemfile `gem "plutus"`
19
-
20
- - generate migration files `rails g plutus`
21
-
19
+ - generate migration files `rake plutus:install:migrations`
22
20
  - run migrations `rake db:migrate`
23
21
 
24
22
  Overview
@@ -269,7 +267,7 @@ entry = Plutus::Entry.build(
269
267
  Multitenancy Support
270
268
  =====================
271
269
 
272
- Plutus supports multitenant applications. Multitenancy is acheived by associating all Accounts under `Plutus::Account` with a "Tenant" object (typically some model in your Rails application). To add multi-tenancy support to Plutus, you must do the following:
270
+ Plutus supports multitenant applications. Multitenancy is achieved by associating all Accounts under `Plutus::Account` with a "Tenant" object (typically some model in your Rails application). To add multi-tenancy support to Plutus, you must do the following:
273
271
 
274
272
  - Generate the migration which will add `tenant_id` to the plutus accounts table
275
273
 
@@ -291,6 +289,19 @@ Plutus.config do |config|
291
289
  config.tenant_class = 'Tenant'
292
290
  end
293
291
  ```
292
+ *NOTE: When building entries, be sure to specify the account directly, rather than use the `account_name` feature. Otherwise you'll probably end up with the wrong account.*
293
+
294
+ ```ruby
295
+ debit_account = Plutus::Account.where(:name => "Cash", :tenant => my_tenant).last
296
+ credit_account = Plutus::Account.where(:name => "Unearned Revenue", :tenant => my_tenant).last
297
+ entry = Plutus::Entry.new(
298
+ :description => "Order placed for widgets",
299
+ :date => Date.yesterday,
300
+ :debits => [
301
+ {:account => debit_account, :amount => 100.00}],
302
+ :credits => [
303
+ {:account => credit_account, :amount => 100.00}])
304
+ ```
294
305
 
295
306
  Reporting Views
296
307
  ===============
@@ -315,7 +326,7 @@ Previous Versions
315
326
 
316
327
  For the rails 3 version, you can go here:
317
328
 
318
- [https://github.com/mbulat/plutus](https://github.com/mbulat/plutus/tree/rails3)
329
+ [https://github.com/mbulat/plutus/tree/rails3](https://github.com/mbulat/plutus/tree/rails3)
319
330
 
320
331
  For the rails 2 version, you can go here:
321
332
 
@@ -324,6 +335,7 @@ For the rails 2 version, you can go here:
324
335
  * Gems in RubyGems.org >= 0.5.0 support Rails 3
325
336
  * Gems in RubyGems.org >= 0.8.0 support Rails 4
326
337
  * Gems in RubyGems.org >= 0.9.0 support Rails ~> 4.1
338
+ * Gems in RubyGems.org >= 0.13.0 support Rails ~> 5.0
327
339
 
328
340
  Upgrading from older versions
329
341
  -----------------------------
@@ -360,8 +372,6 @@ Plutus is free software, but if you'd like to support development, feel free to
360
372
 
361
373
  `1QFSdJheyFkLcsV8X428J8e3pYqX1nmW39`
362
374
 
363
- ![bitcoin](https://dl.dropboxusercontent.com/u/8428240/plutus_tip.png)
364
-
365
375
  Also, if anyone is using Plutus for bitcoin related accounting, I'd love to hear about it! Drop me a line.
366
376
 
367
377
  ToDo
@@ -379,4 +389,4 @@ For a complete reference on Accounting principles, we recommend the following te
379
389
 
380
390
  * * *
381
391
 
382
- Copyright (c) 2010-2012 Michael Bulat
392
+ Copyright (c) 2010-2016 Michael Bulat
@@ -12,5 +12,5 @@
12
12
  //
13
13
  //= require jquery
14
14
  //= require jquery_ujs
15
- //= require jquery.ui.datepicker
15
+ //= require jquery-ui/widgets/datepicker
16
16
  //= require_tree .
@@ -13,7 +13,6 @@
13
13
  *= require_tree .
14
14
  *= require bootstrap.min
15
15
  *= require bootstrap-theme.min
16
- *= require jquery.ui.datepicker
17
16
  *= require_self
18
17
  */
19
18
  body { padding-top: 60px; }
@@ -10,7 +10,7 @@ module Plutus
10
10
  # controller will inherit.
11
11
  #
12
12
  # @author Michael Bulat
13
- class AccountsController < Plutus::ApplicationController
13
+ class AccountsController < ::Plutus::ApplicationController
14
14
  unloadable
15
15
 
16
16
  # @example
@@ -17,7 +17,12 @@ module Plutus
17
17
  # GET /entries.xml
18
18
  # GET /entries.json
19
19
  def index
20
- @entries = Entry.limit(100).order('date DESC')
20
+ if params[:order] == 'ascending'
21
+ order = 'ASC'
22
+ else
23
+ order = 'DESC'
24
+ end
25
+ @entries = Entry.page(params[:page]).per(params[:limit]).order("date #{order}")
21
26
 
22
27
  respond_to do |format|
23
28
  format.html # index.html.erb
@@ -5,7 +5,7 @@ module Plutus
5
5
  # controller will inherit.
6
6
  #
7
7
  # @author Michael Bulat
8
- class ReportsController < Plutus::ApplicationController
8
+ class ReportsController < ::Plutus::ApplicationController
9
9
  unloadable
10
10
 
11
11
  # @example
@@ -32,13 +32,25 @@ module Plutus
32
32
  class Account < ActiveRecord::Base
33
33
  class_attribute :normal_credit_balance
34
34
 
35
+ has_many :amounts
35
36
  has_many :credit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::CreditAmount'
36
37
  has_many :debit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::DebitAmount'
38
+ has_many :entries, through: :amounts, source: :entry
37
39
  has_many :credit_entries, :through => :credit_amounts, :source => :entry, :class_name => 'Plutus::Entry'
38
40
  has_many :debit_entries, :through => :debit_amounts, :source => :entry, :class_name => 'Plutus::Entry'
39
41
 
40
42
  validates_presence_of :type
41
43
 
44
+ def self.types
45
+ [
46
+ ::Plutus::Asset,
47
+ ::Plutus::Equity,
48
+ ::Plutus::Expense,
49
+ ::Plutus::Liability,
50
+ ::Plutus::Revenue,
51
+ ]
52
+ end
53
+
42
54
  if Plutus.enable_tenancy
43
55
  include Plutus::Tenancy
44
56
  else
@@ -135,7 +147,7 @@ module Plutus
135
147
  if self.new.class == Plutus::Account
136
148
  raise(NoMethodError, "undefined method 'balance'")
137
149
  else
138
- accounts_balance = BigDecimal.new('0')
150
+ accounts_balance = BigDecimal('0')
139
151
  accounts = self.all
140
152
  accounts.each do |account|
141
153
  if account.contra
@@ -12,22 +12,13 @@ module Plutus
12
12
  validates_presence_of :type, :amount, :entry, :account
13
13
  # attr_accessible :account, :account_name, :amount, :entry
14
14
 
15
+ delegate :name, to: :account, prefix: true, allow_nil: true
16
+
15
17
  # Assign an account by name
16
18
  def account_name=(name)
17
19
  self.account = Account.find_by_name!(name)
18
20
  end
19
21
 
20
22
  protected
21
-
22
- # Support constructing amounts with account = "name" syntax
23
- def account_with_name_lookup=(v)
24
- if v.kind_of?(String)
25
- ActiveSupport::Deprecation.warn('Plutus was given an :account String (use account_name instead)', caller)
26
- self.account_name = v
27
- else
28
- self.account_without_name_lookup = v
29
- end
30
- end
31
- alias_method_chain :account=, :name_lookup
32
23
  end
33
24
  end
@@ -30,12 +30,10 @@ module Plutus
30
30
  #
31
31
  # Since this does not use the database for sumation, it may be used on non-persisted records.
32
32
  def balance_for_new_record
33
- balance = BigDecimal.new('0')
33
+ balance = BigDecimal('0')
34
34
  each do |amount_record|
35
- if amount_record.amount
36
- balance += amount_record.amount
37
- else
38
- balance = nil
35
+ if amount_record.amount && !amount_record.marked_for_destruction?
36
+ balance += amount_record.amount # unless amount_record.marked_for_destruction?
39
37
  end
40
38
  end
41
39
  return balance
@@ -7,7 +7,7 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Asset Assets
8
8
  #
9
9
  # @author Michael Bulat
10
- class Asset < Account
10
+ class Asset < ::Plutus::Account
11
11
 
12
12
  self.normal_credit_balance = false
13
13
 
@@ -5,6 +5,6 @@ module Plutus
5
5
  # credit_amount = Plutus::CreditAmount.new(:account => revenue, :amount => 1000)
6
6
  #
7
7
  # @author Michael Bulat
8
- class CreditAmount < Amount
8
+ class CreditAmount < ::Plutus::Amount
9
9
  end
10
10
  end
@@ -5,6 +5,6 @@ module Plutus
5
5
  # debit_amount = Plutus::DebitAmount.new(:account => cash, :amount => 1000)
6
6
  #
7
7
  # @author Michael Bulat
8
- class DebitAmount < Amount
8
+ class DebitAmount < ::Plutus::Amount
9
9
  end
10
10
  end
@@ -23,7 +23,13 @@ module Plutus
23
23
  # @author Michael Bulat
24
24
  class Entry < ActiveRecord::Base
25
25
  before_save :default_date
26
- belongs_to :commercial_document, :polymorphic => true
26
+
27
+ if ActiveRecord::VERSION::MAJOR > 4
28
+ belongs_to :commercial_document, :polymorphic => true, optional: true
29
+ else
30
+ belongs_to :commercial_document, :polymorphic => true
31
+ end
32
+
27
33
  has_many :credit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::CreditAmount', :inverse_of => :entry
28
34
  has_many :debit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::DebitAmount', :inverse_of => :entry
29
35
  has_many :credit_accounts, :through => :credit_amounts, :source => :account, :class_name => 'Plutus::Account'
@@ -35,7 +41,7 @@ module Plutus
35
41
  validate :amounts_cancel?
36
42
 
37
43
  # Support construction using 'credits' and 'debits' keys
38
- accepts_nested_attributes_for :credit_amounts, :debit_amounts
44
+ accepts_nested_attributes_for :credit_amounts, :debit_amounts, allow_destroy: true
39
45
  alias_method :credits=, :credit_amounts_attributes=
40
46
  alias_method :debits=, :debit_amounts_attributes=
41
47
  # attr_accessible :credits, :debits
@@ -52,7 +58,8 @@ module Plutus
52
58
 
53
59
  private
54
60
  def default_date
55
- self.date ||= Date.today
61
+ todays_date = ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Time.now
62
+ self.date ||= todays_date
56
63
  end
57
64
 
58
65
  def has_credit_amounts?
@@ -7,7 +7,7 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Equity_(finance) Equity
8
8
  #
9
9
  # @author Michael Bulat
10
- class Equity < Account
10
+ class Equity < ::Plutus::Account
11
11
 
12
12
  self.normal_credit_balance = true
13
13
 
@@ -7,7 +7,7 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Expense Expenses
8
8
  #
9
9
  # @author Michael Bulat
10
- class Expense < Account
10
+ class Expense < ::Plutus::Account
11
11
 
12
12
  self.normal_credit_balance = false
13
13
 
@@ -7,7 +7,7 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Liability_(financial_accounting) Liability
8
8
  #
9
9
  # @author Michael Bulat
10
- class Liability < Account
10
+ class Liability < ::Plutus::Account
11
11
 
12
12
  self.normal_credit_balance = true
13
13
 
@@ -7,7 +7,7 @@ module Plutus
7
7
  # @see http://en.wikipedia.org/wiki/Revenue Revenue
8
8
  #
9
9
  # @author Michael Bulat
10
- class Revenue < Account
10
+ class Revenue < ::Plutus::Account
11
11
 
12
12
  self.normal_credit_balance = true
13
13
 
@@ -5,7 +5,11 @@ module Plutus
5
5
  included do
6
6
  validates :name, presence: true, uniqueness: { scope: :tenant_id }
7
7
 
8
- belongs_to :tenant, class_name: Plutus.tenant_class
8
+ if ActiveRecord::VERSION::MAJOR > 4
9
+ belongs_to :tenant, class_name: Plutus.tenant_class, optional: true
10
+ else
11
+ belongs_to :tenant, class_name: Plutus.tenant_class
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -4,7 +4,6 @@
4
4
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
5
  <title>Plutus</title>
6
6
  <%= stylesheet_link_tag "plutus/application", media: "all" %>
7
- <%= javascript_include_tag "plutus/application" %>
8
7
  <%= csrf_meta_tags %>
9
8
  </head>
10
9
  <body>
@@ -2,6 +2,13 @@
2
2
  <center>
3
3
  <h1>Journal</h1>
4
4
  <br>
5
+ <%= form_tag({:action => 'index'}, {:method => :get, :class => 'form-inline'}) do%>
6
+ <div class="form-group">
7
+ Per page: <%= select_tag :limit, options_for_select([25, 100, 200, 300], selected: params[:limit]), class: 'form-control' %>
8
+ Order: <%= select_tag :order, options_for_select(['descending', 'ascending'], selected: params[:order]), class: 'form-control' %>
9
+ </div>
10
+ <button type="submit" class="btn btn-default">Refresh</button>
11
+ <% end %>
5
12
  </center>
6
13
 
7
14
  <table class="table table-striped table-hover">
@@ -47,4 +54,6 @@
47
54
  </tbody>
48
55
  </table>
49
56
 
57
+ <%= paginate @entries %>
58
+
50
59
  </div>
@@ -5,7 +5,7 @@
5
5
  <%= form_tag({:action => 'balance_sheet'}, {:method => :get, :class => 'form-inline'}) do%>
6
6
  <div class="form-group">
7
7
  <%= label_tag :date, nil, class: 'sr-only'%>
8
- <%= text_field_tag :date, @to_date, :class => 'datepicker form-control' %>
8
+ <%= date_field_tag :date, @to_date, :class => 'form-control' %>
9
9
  </div>
10
10
  <button type="submit" class="btn btn-default">Get Report</button>
11
11
  <% end %>
@@ -5,11 +5,11 @@
5
5
  <%= form_tag({:action => 'income_statement'}, {:method => :get, :class => 'form-inline'}) do%>
6
6
  <div class="form-group">
7
7
  <%= label_tag :from_date, nil, class: 'sr-only'%>
8
- <%= text_field_tag :from_date, @from_date, :class => 'datepicker form-control', :placeholder => "Date" %>
8
+ <%= date_field_tag :from_date, @from_date, :class => 'form-control', :placeholder => "Date" %>
9
9
  </div>
10
10
  <div class="form-group">
11
11
  <%= label_tag :to_date, nil, class: 'sr-only'%>
12
- <%= text_field_tag :to_date, @to_date, :class => 'datepicker form-control', :placeholder => "Date" %>
12
+ <%= date_field_tag :to_date, @to_date, :class => 'form-control', :placeholder => "Date" %>
13
13
  </div>
14
14
  <button type="submit" class="btn btn-default">Get Report</button>
15
15
  <% end %>
@@ -1,9 +1,9 @@
1
- class CreatePlutusTables < ActiveRecord::Migration
2
- def self.up
1
+ class CreatePlutusTables < ActiveRecord::Migration[4.2]
2
+ def change
3
3
  create_table :plutus_accounts do |t|
4
4
  t.string :name
5
5
  t.string :type
6
- t.boolean :contra
6
+ t.boolean :contra, default: false
7
7
 
8
8
  t.timestamps
9
9
  end
@@ -30,10 +30,4 @@ class CreatePlutusTables < ActiveRecord::Migration
30
30
  add_index :plutus_amounts, [:account_id, :entry_id]
31
31
  add_index :plutus_amounts, [:entry_id, :account_id]
32
32
  end
33
-
34
- def self.down
35
- drop_table :plutus_accounts
36
- drop_table :plutus_entries
37
- drop_table :plutus_amounts
38
- end
39
33
  end
@@ -1,4 +1,4 @@
1
- class TenantPlutusTables < ActiveRecord::Migration
1
+ class TenantPlutusTables < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  # add a tenant column to plutus accounts table.
4
4
  add_column :plutus_accounts, :tenant_id, :integer, index: true
@@ -2,11 +2,6 @@
2
2
  require "rails"
3
3
 
4
4
  module Plutus
5
- class Engine < Rails::Engine
6
- isolate_namespace Plutus
7
- end
8
-
9
-
10
5
  # ------------------------------ tenancy ------------------------------
11
6
  # configuration to enable or disable tenancy
12
7
  mattr_accessor :enable_tenancy
@@ -21,3 +16,5 @@ module Plutus
21
16
  yield(self)
22
17
  end
23
18
  end
19
+
20
+ require "plutus/engine"