adamcharnock / django-hordak

Double entry accounting in Django
http://django-hordak.readthedocs.io
MIT License
231 stars 55 forks source link

Subclass Account for Multi-tenancy #77

Closed nitsujri closed 1 year ago

nitsujri commented 1 year ago

Thanks for this great library! Apologies if issues is not the right place to ask this question. It's got everything we're evaluating for, multi-currency, strong tests.

For us, we need multi-tenancy and was hoping for some guidance. In our setup we have multiple Organizations and each org can have multiple Companys that are isolated groups.

out_organization_svg

Each org and company should have its own ledger. Money flows only between a company and its parent org. So not between companies and not between orgs.

What would be the recommended way of extending the current library to achieve this?

Would it be:

Thanks! Justin

darahsten commented 1 year ago

What you are asking seems more related to business logic than to modeling.

Do you intend to have each organization run off its own database?

Over-engineering can be bad for the design and development of systems.

I believe it would be sufficient to write tests that ensure that transactions do not cross over into other organizations even though that in my view is already a form of over-engineering.

A simple thing you can do is to attach an account to an organization see below.

      class Company(models.Model)
             organisation = models.ForeignKey('Organisation' ...)
             (type)_account = models.One2OneField(HordakAccount...)   # where type could be asset, liability...
nitsujri commented 1 year ago

@darahsten oh this is extremely helpful! I had this weird assumption that I should have an arbitrary number of accounts but clearly there should be a set number of root accounts and specific objects point to sub accounts.

like if a company has multiple bank accounts?

i am new to all this so it was super helpful. I think this is enough for me to move forward!

darahsten commented 1 year ago

Yes, absolutely, you can have multiple accounts attached to a single root account. Glad, this was helpful.