Skip to content

Commit

Permalink
Merge branch 'release/v0.12.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbulat committed Jun 9, 2015
2 parents 70cc306 + d8ab1df commit 209570a
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 156 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -3,6 +3,7 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- 2.2.0
- ruby-head
- jruby
- jruby-head
Expand Down
43 changes: 43 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,43 @@
# Contributing

Plutus welcomes contributions from *everyone*.

First of all, thank you for considering to help make Plutus better. Here are some ways you can contribute:

- by [reporting bugs you encounter](https://github.com/mbulat/plutus/issues/new)
- by closing issues that are not complete
- by adding a failing test for reproducible [reported bugs](https://github.com/mbulat/plutus/issues)
- by reviewing [pull requests](https://github.com/mbulat/plutus/pulls) and suggesting improvements
- by writing code (no patch is too small! fix typos or bad whitespace)

Thanks for helping us make Plutus better.

# Adding new features

If you would like to add a new feature to Plutus, please follow these steps:

1. First, check [github issues](https://github.com/mbulat/plutus/issues) to see if the feature has been discussed
2. For complex features or questions, [Discuss the issue](https://groups.google.com/d/forum/plutus-gem) at the plutus mailing list.
3. Open an [enhancement issues](https://github.com/mbulat/plutus/labels/enhancement) and make sure to add the enhancement label
4. Base your commits on the 'develop' branch, since we follow [Git Flow](http://nvie.com/posts/a-successful-git-branching-model/), and don't add new features to old releases.
5. Commit the code and at least one test covering your changes to a feature branch in your fork.
5. Don't commit any changes to gemspec or change the version number
6. Send us a [pull request](https://help.github.com/articles/using-pull-requests) from your feature branch.

If you don't hear back immediately, don’t get discouraged! We all have day jobs, but we respond to most tickets within a day or two.

If the pull request is merged, testing will commence on our staging systems to ensure that the new feature doesn't cause any problems for anyone in production. We'll then merge the code into the master branch and push a new gem version!

# Release cycle

Plutus follows a [Git Flow](http://nvie.com/posts/a-successful-git-branching-model/) model for branching and release of code.
When you issue a pull request, please ensure that you base your commit on the 'develop' branch. Once the pull has been merged, you won't see
your changes in master until a "release" has been issued, which will merge the develop branch back into master.

Prior to release, Plutus is run through a full suite of integration tests with our application. Depending on the size and number of
updates to the code base, releases might not happen for a while. Typically though, if there is a significant change to functionality, or a bug is fixed,
a release or "hotfix" will be pushed out ASAP.

# Discussing Plutus

If you'd like to discuss features, ask questions, or just engage in general Plutus-focused discussion, please see the [Plutus mailing list](https://groups.google.com/d/forum/plutus-gem) on Google Groups.
32 changes: 18 additions & 14 deletions README.markdown
Expand Up @@ -7,7 +7,7 @@ The Plutus plugin is a Ruby on Rails Engine which provides a double entry accoun
Compatibility
=============

* Ruby versions: MRI 1.9.3, MRI 2.0, MRI 2.1, Rubinius 2.2, JRuby 1.7+
* Ruby versions: MRI 1.9.3 - 2.2, Rubinius 2.2, JRuby 1.7+
* Rails versions: ~> 4.0

For earlier versions, and upgrading, please see the section titled [Previous Versions](https://github.com/mbulat/plutus#previous-versions)
Expand Down Expand Up @@ -85,12 +85,14 @@ Let's assume we're accounting on an [Accrual basis](http://en.wikipedia.org/wiki

Next we'll build the entry we want to record. Plutus uses ActiveRecord conventions to build the transaction and its associated amounts.

entry = Plutus::Entry.new(
:description => "Order placed for widgets",
:debits => [
{:account_name => "Cash", :amount => 100.00}],
:credits => [
{:account_name => "Unearned Revenue", :amount => 100.00}])
```ruby
entry = Plutus::Entry.new(
:description => "Order placed for widgets",
:debits => [
{:account_name => "Cash", :amount => 100.00}],
:credits => [
{:account_name => "Unearned Revenue", :amount => 100.00}])
```

Entries must specify a description, as well as at least one credit and debit amount. `Amount`s must specify an amount value as well as an account, either by providing a `Plutus::Account` to `account` or by passing in an `account_name` string.

Expand Down Expand Up @@ -119,10 +121,10 @@ And here's the entry:
entry = Plutus::Entry.build(
:description => "Sold some widgets",
:debits => [
{:account => "Accounts Receivable", :amount => 50}],
{:account_name => "Accounts Receivable", :amount => 50}],
:credits => [
{:account => "Sales Revenue", :amount => 45},
{:account => "Sales Tax Payable", :amount => 5}])
{:account_name => "Sales Revenue", :amount => 45},
{:account_name => "Sales Tax Payable", :amount => 5}])
entry.save
```

Expand Down Expand Up @@ -244,9 +246,9 @@ Plutus is also compatible with the [Money](https://github.com/RubyMoney/money) g
entry = Plutus::Entry.build(
:description => "Order placed for widgets",
:debits => [
{:account => "Cash", :amount => money.amount}],
{:account_name => "Cash", :amount => money.amount}],
:credits => [
{:account => "Unearned Revenue", :amount => money.amount}])
{:account_name => "Unearned Revenue", :amount => money.amount}])
```

Multitenancy Support
Expand Down Expand Up @@ -325,8 +327,10 @@ Testing

[Rspec](http://rspec.info/) tests are provided. Run `bundle install` then `rake`.

Contributors
============
Contributing and Contributors
=============================

There's a guide to contributing to Plutus (both code and general help) over in [CONTRIBUTING](https://github.com/mbulat/plutus/blob/master/CONTRIBUTING.md)

Many thanks to all our contributors! Check them all at:

Expand Down
55 changes: 55 additions & 0 deletions app/models/plutus/account.rb
Expand Up @@ -30,6 +30,8 @@ module Plutus
#
# @author Michael Bulat
class Account < ActiveRecord::Base
class_attribute :normal_credit_balance

has_many :credit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::CreditAmount'
has_many :debit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::DebitAmount'
has_many :credit_entries, :through => :credit_amounts, :source => :entry, :class_name => 'Plutus::Entry'
Expand All @@ -43,6 +45,32 @@ class Account < ActiveRecord::Base
include Plutus::NoTenancy
end

# The balance of the account. This instance method is intended for use only
# on instances of account subclasses.
#
# If the account has a normal credit balance, the debits are subtracted from the credits
# unless this is a contra account, in which case credits are substracted from debits.
#
# For a normal debit balance, the credits are subtracted from the debits
# unless this is a contra account, in which case debits are subtracted from credits.
#
# @example
# >> liability.balance
# => #<BigDecimal:103259bb8,'0.2E4',4(12)>
#
# @return [BigDecimal] The decimal value balance
def balance
unless self.class == Plutus::Account
if self.normal_credit_balance ^ contra
credits_balance - debits_balance
else
debits_balance - credits_balance
end
else
raise(NoMethodError, "undefined method 'balance'")
end
end

# The credit balance for the account.
#
# @example
Expand All @@ -65,6 +93,33 @@ def debits_balance
debit_amounts.balance
end

# This class method is used to return the balance of all accounts
# for a given class and is intended for use only on account subclasses.
#
# Contra accounts are automatically subtracted from the balance.
#
# @example
# >> Plutus::Liability.balance
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
#
# @return [BigDecimal] The decimal value balance
def self.balance
unless self.new.class == Plutus::Account
accounts_balance = BigDecimal.new('0')
accounts = self.all
accounts.each do |account|
unless account.contra
accounts_balance += account.balance
else
accounts_balance -= account.balance
end
end
accounts_balance
else
raise(NoMethodError, "undefined method 'balance'")
end
end

# The trial balance of all accounts in the system. This should always equal zero,
# otherwise there is an error in the system.
#
Expand Down
19 changes: 4 additions & 15 deletions app/models/plutus/asset.rb
Expand Up @@ -9,6 +9,8 @@ module Plutus
# @author Michael Bulat
class Asset < Account

self.normal_credit_balance = false

# The balance of the account.
#
# Assets have normal debit balances, so the credits are subtracted from the debits
Expand All @@ -20,11 +22,7 @@ class Asset < Account
#
# @return [BigDecimal] The decimal value balance
def balance
unless contra
debits_balance - credits_balance
else
credits_balance - debits_balance
end
super
end

# This class method is used to return
Expand All @@ -38,16 +36,7 @@ def balance
#
# @return [BigDecimal] The decimal value balance
def self.balance
accounts_balance = BigDecimal.new('0')
accounts = self.all
accounts.each do |asset|
unless asset.contra
accounts_balance += asset.balance
else
accounts_balance -= asset.balance
end
end
accounts_balance
super
end
end
end
19 changes: 4 additions & 15 deletions app/models/plutus/equity.rb
Expand Up @@ -9,6 +9,8 @@ module Plutus
# @author Michael Bulat
class Equity < Account

self.normal_credit_balance = true

# The balance of the account.
#
# Equity accounts have normal credit balances, so the debits are subtracted from the credits
Expand All @@ -20,11 +22,7 @@ class Equity < Account
#
# @return [BigDecimal] The decimal value balance
def balance
unless contra
credits_balance - debits_balance
else
debits_balance - credits_balance
end
super
end

# This class method is used to return
Expand All @@ -38,16 +36,7 @@ def balance
#
# @return [BigDecimal] The decimal value balance
def self.balance
accounts_balance = BigDecimal.new('0')
accounts = self.all
accounts.each do |equity|
unless equity.contra
accounts_balance += equity.balance
else
accounts_balance -= equity.balance
end
end
accounts_balance
super
end
end
end
19 changes: 4 additions & 15 deletions app/models/plutus/expense.rb
Expand Up @@ -9,6 +9,8 @@ module Plutus
# @author Michael Bulat
class Expense < Account

self.normal_credit_balance = false

# The balance of the account.
#
# Expenses have normal debit balances, so the credits are subtracted from the debits
Expand All @@ -20,11 +22,7 @@ class Expense < Account
#
# @return [BigDecimal] The decimal value balance
def balance
unless contra
debits_balance - credits_balance
else
credits_balance - debits_balance
end
super
end

# This class method is used to return
Expand All @@ -38,16 +36,7 @@ def balance
#
# @return [BigDecimal] The decimal value balance
def self.balance
accounts_balance = BigDecimal.new('0')
accounts = self.all
accounts.each do |expense|
unless expense.contra
accounts_balance += expense.balance
else
accounts_balance -= expense.balance
end
end
accounts_balance
super
end
end
end
26 changes: 10 additions & 16 deletions app/models/plutus/liability.rb
Expand Up @@ -9,6 +9,8 @@ module Plutus
# @author Michael Bulat
class Liability < Account

self.normal_credit_balance = true

# The balance of the account.
#
# Liability accounts have normal credit balances, so the debits are subtracted from the credits
Expand All @@ -20,29 +22,21 @@ class Liability < Account
#
# @return [BigDecimal] The decimal value balance
def balance
unless contra
credits_balance - debits_balance
else
debits_balance - credits_balance
end
super
end

# Balance of all Liability accounts
# This class method is used to return
# the balance of all Liability accounts.
#
# Contra accounts are automatically subtracted from the balance.
#
# @example
# >> Plutus::Liability.balance
# => #<BigDecimal:1030fcc98,'0.82875E5',8(20)>
#
# @return [BigDecimal] The decimal value balance
def self.balance
accounts_balance = BigDecimal.new('0')
accounts = self.all
accounts.each do |liability|
unless liability.contra
accounts_balance += liability.balance
else
accounts_balance -= liability.balance
end
end
accounts_balance
super
end
end
end

0 comments on commit 209570a

Please sign in to comment.