Skip to main content

A Flask accounting module.

Project description

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.

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.

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 or do not know how to start one, you may start with the test site.

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 UserUtils(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

After database tables are created, 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

Documentation

Refer to the documentation on Read the Docs.

Authors

imacat
2023/1/27

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mia-accounting-1.2.0.tar.gz (220.4 kB view hashes)

Uploaded Source

Built Distribution

mia_accounting-1.2.0-py3-none-any.whl (297.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page