Skip to content

fastapi + sqlalchemy + postgres backend to get manage invoices & creditlines

Notifications You must be signed in to change notification settings

ArboreumDev/invoice-finance-pilot-backend

Repository files navigation

Invoice Financing Backend

A backend that manages creditlines between suppliers & purchasers. Each creditline is limited by

  • the total credit each supplier can avail to
  • the total credit each purchaser can avail to
  • the individual credit limit of each purchaser-supplier relationship

Credit is given against individual invoices. Invoices correspond to shipments of goods shipped by a delivery-company, which is giving us API-access to see the basic data used as source of truth for (shipper, receiver, value, shipment_status etc..).

A typical invoice lifecycle looks like this:

  • Once requested to be financed, The backend checks whether the invoice-value is within the limits of the associated creditline.
  • If approved, the backend tracks its delivery-status by querying the delivery-company.
  • Once delivered, it marks it as to be financed (Admin-Dashboard)
  • Once per day, the admin can bundle all invoices to be financed into a disbursal and manually trigger the release of the money (external to this backend)
  • Once the money is released, the invoices can be marked as disbursed, and the respective disbursal & loan-ID will be stored with them
  • The dashboards will show the invoice-status, the total credit that is left and the amounts to be repaid (live and at the end of the term)
  • The Admin can use the admin-dashboard to mark invoices as fully repaid, freeing the respective amounts from the creditlines.

Stack & libraries

Setup

rename .example.env to .env and add the missing variables

JWT_SECRET_KEY="someSecretKey"
EMAIL_PASSWORD=""

...and more

Virtualenv

a local virtual env running python version 3.8

e.g. using virtualenv -library:

setup virtualenv (e.g named 'tenv') and point it to your local executable of python 3.8 like this:

virtualenv tenv --python=/usr/bin/python3.8 source tenv/bin/activate pip install -r requirememts.txt

for local development

check the Makefile for a bunch of helpful commands.

Creates a test-db, db & backend

make dev-api-local (-> set # POSTGRES_HOST="localhost" in .env)

then, create the DB-schemas

cd app python -m database.create

or

make create_db

or

alembic head upgrade

Then, seed the db with a user

cd app python -m database.seed

BUG: Not sure how to make the bind-mount use the virtualenv -> you might need to manually install a bunch of python libraries (argon-cff2, fastapi,psycopg2-binary, pendulum, python-multipart,...)

run backend as container

(-> set # POSTGRES_HOST="db" in .env)

make dev-api

attach into backend container & run database.create & database.seed manually

Migrations

Creating a new revision

$ alembic revision --autogenerate -m "Add column last_name to User model"

Don't forget to commit new revision to git.

Switching to the latest migration

$ alembic upgrade head

troubleshooting

delete the docker container (-s stops if running)

docker-compose rm -s -v db

reset the volume the container is mounted on manuallyk

docker-volume ls docker-volume rm

if running the api-containerized:

get a shell into the

docker-compose --profile local-mount exec backend /bin/bash

to reflect changes from compose file to running containers (e.g port mappings)

(tenv) ➜ tusker-pilot-backend git:(docker-setup) ✗ docker-compose --profile testing up

test

make test

Documentation

run the api and check out the swagger-docs at http://localhost:8000/docs# (or http://localhost:8000/redoc )

its possible to use the docs link to do simple testing of the APIs via the "TRY IT OUT" button

PRODUCTION

set .env variable ENVIRONMENT=PRODUCTION

docker-compose build backend docker-compose push backend

test by using the image:

docker-compose up backend db

(-> set # POSTGRES_HOST="localhost" in .env)

About

fastapi + sqlalchemy + postgres backend to get manage invoices & creditlines

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages