The Mia! Accounting Project https://accounting.imacat.idv.tw
Go to file
2023-04-06 02:54:45 +08:00
docs Added the documentation. 2023-04-06 02:54:45 +08:00
src/accounting Removed the rows with zero balance from the income statement. 2023-04-05 12:59:50 +08:00
tests Revised the inclusion in the base template of the test site. 2023-04-06 02:01:05 +08:00
.gitignore Renamed the project from "Mia! Accounting Flask" to "Mia! Accounting". 2023-04-04 18:26:54 +08:00
.readthedocs.yaml Revised the Read the Docs configuration, and removed the redundant requirements.txt for Read the Docs. 2023-04-05 22:01:53 +08:00
LICENSE Added the initial application with the main account list, the pagination, the query, the permission, the localization, the documentation, the test case, and a test demonstration site. 2023-02-03 12:55:33 +08:00
MANIFEST.in Replaced setup.cfg with pyproject.toml for the package settings, and rewrote the packaging rules in MANIFEST.in. 2023-04-05 19:49:52 +08:00
pyproject.toml Updated the copyright year in pyproject.toml. 2023-04-05 22:50:54 +08:00
README.rst Added the documentation. 2023-04-06 02:54:45 +08:00

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> </head>

Mia! Accounting

Description

Mia! Accounting is an accounting module for Flask applications. It implements double-entry bookkeeping, and generates the following accounting reports:

  • Trial balance
  • Income statement
  • Balance sheet

In addition, Mia! Accounting tracks offsets for unpaid payables and receivables.

You may try the Mia! Accounting live demonstration.

History

I created my own private accounting application in Perl/mod_perl in 2007, as part of my personal website. The first revision was made using Perl/Mojolicious in 2019, with the aim of making it mobile-friendly using Bootstrap, and with modern back-end and front-end technologies such as jQuery.

The second revision was done in Python/Django in 2020, as I was looking to change my career from PHP/Laravel to Python, but lacked experience with large Python projects. I wanted to add something new to my portfolio and decided to work on the somewhat outdated Mojolicious project.

Despite having no prior experience with Django, I spent two months working late nights to create the Mia! Account Django application. It took me another 1.5 months to make it an independent module, which I later released as an open source project.

The application worked nicely for my household bookkeeping for two years. However, new demands arose over time, especially with tracking payables and receivables, which became difficult with credit card payments. This was critical during the pandemic as more payments were made online with credit cards.

The biggest issue I encountered was with Django's MVT framework. Due to my lack of experience with Django during development, I ended up with mixed function-based view controllers and class-based views. It became very difficult to track whether problems originated from my overridden methods or not-overridden methods, or from the Django base views themselves. I did not fully understand how everything worked.

Therefore, I decided to turn to microframeworks like Flask. After working with modularized Flask and FastAPI applications for two years, I returned to the project and wrote its third revision using Flask in 2023.

Installation

Install Mia! Accounting with pip:

pip install mia-accounting

You may also download the from the PyPI project page or the release page on the Git repository.

Prerequisites

You need a running Flask application with database user login. The primary key of the user data model must be integer.

The following front-end JavaScript libraries must be loaded. You may download it locally or use CDN.

Configuration

You need to pass the Flask app and an implementation of UserUtilityInterface to the init_app function. UserUtilityInterface contains everything Mia! Accounting needs.

The following is an example configuration for Mia! Accounting.

from flask import Response, redirect
from .auth import current_user()
from .modules import User

def create_app(test_config=None) -> Flask:
    app: Flask = Flask(__name__)

    ... (Configuration of SQLAlchemy, CSRF, Babel_JS, ... etc) ...

    import accounting

    class UserUtilities(accounting.UserUtilityInterface[User]):

        def can_view(self) -> bool:
            return True

        def can_edit(self) -> bool:
            return "editor" in current_user().roles

        def can_admin(self) -> bool:
            return current_user().is_admin

        def unauthorized(self) -> Response:
            return redirect("/login")

        @property
        def cls(self) -> t.Type[User]:
            return User

        @property
        def pk_column(self) -> Column:
            return User.id

        @property
        def current_user(self) -> User | None:
            return current_user()

        def get_by_username(self, username: str) -> User | None:
            return User.query.filter(User.username == username).first()

        def get_pk(self, user: User) -> int:
            return user.id

    accounting.init_app(app, UserUtils())

    ... (Any other configuration) ...

    return app

Database Initialization

After the configuration, you need to run flask_sqlalchemy.SQLAlchemy.create_all to create the database tables that Mia! Accounting uses.

Mia! Accounting adds three console commands:

  • accounting-init-base
  • accounting-init-accounts
  • accounting-init-currencies

You need to run accounting-init-base first, and then the other two commands.

% flask --app myapp accounting-init-base
% flask --app myapp accounting-init-accounts
% flask --app myapp accounting-init-currencies

Navigation Menu

Include the navigation menu in the Bootstrap navigation bar in your base template:

<nav class="navbar navbar-expand-lg bg-body-tertiary bg-dark navbar-dark">
  <div class="container-fluid">
    ...
    <div id="collapsible-navbar" class="collapse navbar-collapse">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        ...
        {% include "accounting/include/nav.html" %}
        ...
      </ul>
      ...
    </div>
  </div>
</nav>

Check your Flask application and see how it works.

Test Site and Live Demonstration

You may find a working example in the test site in the source distribution. It is the simplest website that works with Mia! Accounting. It is used in the automatic tests. It is the same code run for live demonstration.

If you do not have a running Flask application, you may start with the test site.

Documentation

Refer to the documentation on Read the Docs.

Authors

imacat
2023/1/27
</html>