Coder Social home page Coder Social logo

multi currency account about medici HOT 14 CLOSED

flash-oss avatar flash-oss commented on August 13, 2024
multi currency account

from medici.

Comments (14)

nicolasburtey avatar nicolasburtey commented on August 13, 2024 4

I have currently being using

.credit('Alice', 10,  {currency: 'USD'})
.debit('Alice', 9, {currency: 'EUR'})
.credit('Bob', 9,  {currency: 'EUR'})
.debit('Bob', 10, {currency: 'USD'})

with no issue so far. as long as every balance() call includes currency the balance seems correctly fetch with the currency flag.

closing this for now.

from medici.

nicolasburtey avatar nicolasburtey commented on August 13, 2024 1

Just proposed a PR to remove what I believe is not correct in the README

from medici.

koresar avatar koresar commented on August 13, 2024

Hm... Having multiple currencies in a same book? That doesn't sound like a double-entry accounting system. I'd recommend creating a separate book for a new currency. That the only safe way to go. Otherwise you can get yourself into a lot of troubles.

Medici checks every commit is zero balanced. See source code: https://github.com/koresar/medici/blob/a1d43c3cee03f0d2f84badad29324bef678c67de/src/entry.js#L130
Every commit must balance out to zero.

I would discourage the two following solutions because adding dollars to euros is plain wrong.

The Medici module have a feature of "sub accounts".

You can have a "USD" account and then sub accounts for Alice and Bob.

.credit('USD:Alice', 10)
.debit('USD:Bob", 10)
.debit('EUR:Alice', 12)
.credit('EUR:Alice', 12)

Or Alice and Bob can have a USD wallet sub account.

.credit('Alice:USD', 10)
.debit('Bob:USD", 10)
.debit('Alice:EUR', 12)
.credit('Alice:EUR', 12)

from medici.

nicolasburtey avatar nicolasburtey commented on August 13, 2024

Thanks for the quick feedback!

Hm... Having multiple currencies in the same book? That doesn't sound like a double-entry accounting system. I'd recommend creating a separate book for a new currency. That the only safe way to go.

The issue is if you do cross-currency transactions. I don't think you could do such transaction atomically if you have them in 2 books?

Ledger has a useful wiki on it.

Would there be some constraint to have more than 3 sub accounts (performance?). If accounts need to finish with currency, there 3 may not be enough.

But as shown on the ledger page and their -X option, there could be a need to convert between currency as well.

from medici.

koresar avatar koresar commented on August 13, 2024

Can be done in one book.

Alice converting AUD->EUR within her multicurrency wallet:

books
  .credit("AUD:Expenses:Marketing", 2000.00, { client: 'Alice' })
  .debit("AUD:Equity:Trading:Currency:AUD:EUR", 2000.00, { client: 'Alice' })
  .credit("EUR:Equity:Trading:Currency:AUD:EUR", 1000.00, { client: 'Alice' })
  .debit("EUR:Liabilities:Accounts Payable:EUR", 1000.00, { client: 'Alice' })

Just make sure that the sum for AUD is always 0. And for EUR.

To get total AUD balance:

const balance = await myBook.balance({
  account: "AUD",
  client: "Alice"
});

Not sure if that's helpful.

from medici.

nicolasburtey avatar nicolasburtey commented on August 13, 2024

Let me play with it and see. Just a question to understand the behavior or Medici.

The documentation says:

Accounts are divided into up to three levels, separated by a colon

But after skimming through the code I have not seen this limitation. Ie: AUD:Equity:Trading:Currency:AUD:EUR will have 6 sub-accounts (and not be limited by 3) in total.

Is that correct?

from medici.

koresar avatar koresar commented on August 13, 2024

from medici.

nicolasburtey avatar nicolasburtey commented on August 13, 2024

actually I might have talked too quickly: https://github.com/koresar/medici/blob/e6a2c27fa28fd748bb7c349b16a9e4ccc0f943d5/src/entry.js#L38

from medici.

nicolasburtey avatar nicolasburtey commented on August 13, 2024

will continue seeing how to integrate multi-currency and will try to pull a PR if I find a good way forward

from medici.

koresar avatar koresar commented on August 13, 2024

from medici.

koresar avatar koresar commented on August 13, 2024

Thinking out loud, maybe we should just remove this limitation?

from medici.

nicolasburtey avatar nicolasburtey commented on August 13, 2024

probably. do you know why it was here in the first place? to limit index size?

from medici.

koresar avatar koresar commented on August 13, 2024

I don't know exactly. But I suspect that the first version of the medici API allowed to pass
account, subaccount, subsubaccount.

The newer (current) API let you pass these as a concatenated string
"Assets:Something:Somethingelse"

from medici.

koresar avatar koresar commented on August 13, 2024

thank you for the thread!

from medici.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.