Skip to content

Transaction support for multiple accounts. #7

mbulat opened this Issue May 11, 2012 · 4 comments

3 participants

mbulat commented May 11, 2012

A single transaction needs to support multiple credit and/or debit accounts.

A simple example would be a transaction that incurs a sales tax. We might have a transaction that looks like this:

Description                                                  |  Debit   |  Credit  |         
Accounts Receivable                                          |  106.00  |          |
     Sales                                                   |          |  100.00  |
     Sales Tax Payable                                       |          |    6.00  |

At the moment, we'd have to create two separate transactions, when really we need to create one transaction with a relation to 1 debit account and 2 credit accounts.

I plan in implementing this shortly with a simple has_and_belongs_to_many as I don't think we need an intervening model for the association.

@mbulat mbulat was assigned May 11, 2012
mbulat commented May 13, 2012

After mulling this over, it looks like we do need a has_many :through. Each transaction will need one or more "credit amounts" and one or more "debit amounts". The "credit amounts" and "debit amounts" are themselves associated with the Transaction and the Account models.

Here's a UML of the proposed design (my UML is a bit rusty, so this is just a general idea)


Obviously a Transaction will need to ensure that it's total_credit_amount and total_debit_amount sum to 0.

@knewter just want to make sure you're in the loop on this as I'm not sure how this effects your effort to implement Mongoid support. I assume this type of relationship might be complicated in MongoDB. If there's a simpler design I'm open to it.

knewter commented May 14, 2012

@mbulat So we've got a version of plutus working entirely, with tests passing in both ARecord and Mongoid. We need to get you to have a look at it, but there's nothing awkward about making that relationship work for what it's worth. @benolee will you send @mbulat or me a link to the current best representation of our work with a quickie explanation?


@mbulat mbulat added a commit that referenced this issue May 14, 2012
@mbulat transactions support for multiple debit and credit amounts - provides…
… models and tests for #7
@mbulat mbulat added a commit that referenced this issue May 14, 2012
@mbulat view and style updates for #7 464a802
crftr commented May 14, 2012

Great timing! I was just contemplating this exact concern.

mbulat commented May 15, 2012

I've got this feature working in the many_to_many branch. Since creating a transaction requires creating multiple associated credit and debit amount objects, I've added a method to simplify the process. (documented in readme and class)

@knewter @benolee I plan on merging this into master. Let me know if you'd like me to wait or go ahead.

@mbulat mbulat closed this in a8443ca May 30, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.