Code Monkey home page Code Monkey logo

cashly's Introduction

Cashly

Collect due cash

Built with Cookiecutter Django Ruff

License: MIT

Design Decisions

cashly.jpg A general view of the system , it is not meant to be a full UML, or even a valid one.

1. Where do tasks come from?

  • I decided to make the tasks be created from the admin panel, also i'll provide a crud only to managers, so they can use to create tasks
  • I also decided to separate the Customer, so the tasks crud would need a customers' crud, which i'll also create.

2. Multiple cash collectors and multiple managers.

  • It makes sense that there will be multiple cash collectors and multiple managers, so the following decisions where made.
  • Managers assign tasks to specific cash collectors when creating tasks.
    • So, we will need a crud for cash collectors.
  • We will not care which manager collects the money from the cash collector, we can assume it's the manager who created the task.
    • For that to make more sense, task creator cannot be changed.

3. Different user table ?

  • For simplicity, we will use django's auth system, and we will just add a field called System Role, which can be manager or cash collector.
    • Update #1: On a second thought let's create a separate model for manager and collector, and make it inherit from User, this will make the relationships between the manager and task, and between the collector and its pocket make more sense.
  • What about the superuser thing ?
    • We will ignore the superuser status in all the api endpoints, for example if a cash collector is also a superuser, he will still not be able to call endpoints that need a manager.

4. Keeping history

  • We will try to keep as much history as possible, for example when moving money for a cash collector's pocket to a safe, we will not delete the value from the pocket, but instead will mark it as collected.
  • This might require more storage for the DB, and might make us optimize queries as possible, but in cash related systems, transaction data are important (I think).

5. Freezing cash collectors.

  • At a first glance I thought we would need a celery beat to execute every specific period, and look for cash collectors that has the freezing criteria and freeze them.
  • But it seemed like over engineering, and also there is the possibility of requests coming between the beats.
  • So instead, with every write to a cash collector's pocket, we will check if it passes the specified amount and then store the time in the future when this cash collector would be frozen.
  • This might slow the writes a little bit, but the gains are better.

Deliverables

Models

There are 7 models

  • users:Manager: extends normal user model.
  • users:CacheCollector: extends normal user model.
  • billing:Customer: So we don't repeat customer details on every bill(task), 1NF.
  • billing:CustomerBill: A task assigned to specific CashCollector.
  • accounting:CashCollectorPocket: A task collected by a CashCollector (The money is in his pocket).
  • accounting:CentralSafe: The money paid to Managers from CashCollectors.
  • accounting:CashCollectorTimeline: Store CashCollector events.

Status at different points.

  • You can log in to admin panel and see the CashCollectorTimeline list, search with a specific collector username.
  • You can use /api/v1/collector-status-report/ rest api while logged in with the desired collector.

Restfull APIs

  • Please download this postman collection, it has all the details on the endpoints.
  • In the postman collection variables, update MANAGER_AUTH_KEY, COLLECTOR_AUTH_KEY, these are the keys used for manager, collector operations respectively.
  • The 1,2,3,4 folders are manager operations, the 5,6 folders are collectors operations.

Test cases

  • I've written integration tests for the main scenario, in 2 different ways, one directly using orm, and other using apis.
    • You can run it using DJANGO_SETTINGS_MODULE=config.settings.test pytest -s -vv -k main_scenario
  • I've also written tests for the most important edge cases.
    • You can run it using DJANGO_SETTINGS_MODULE=config.settings.test pytest -s -vv -k edge_cases

Running project.

  • Create a virtualenv, activate it, install requirements/local.txt.
  • Migrate database python manage.py migrate.
  • Create a super user DJANGO_SUPERUSER_PASSWORD=superadmin python manage.py createsuperuser --username superadmin --email [email protected] --noinput
    • This creates a superuser with username superadmin and password superadmin.
  • Create a manager echo "from cashly.users.models import Manager;manager=Manager.objects.create(username='manager1');manager.set_password('Cashly@2024');manager.save()" | python manage.py shell
    • This creates a manager with username manager1 and password Cashly@2024.
  • Run the server python manage.py runserver.
  • You can now use the manager in the Rest API to create collectors and customer and bills.
  • You can then use the created collectors, customers and bills to test the collecting functionality.
  • You can use the created superuser to browse the admin panel.

cashly's People

Contributors

eibrahim95 avatar dependabot[bot] avatar

Watchers

 avatar

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.