B
B
Bunzuk2018-11-14 13:11:51
Django
Bunzuk, 2018-11-14 13:11:51

Django how to properly implement storage and retrieval of leftovers?

Good day or evening to all.
I'm new to django - so I need a "kick" from the pros). There is a task to implement a system for charging fees for kindergarten. The problem is in the correct implementation of storing and retrieving balances by child or list of children.
Models:
1. Child
2. Document (document type: Accrual, Payment) 3.
DocumentItems
4. Transactions (turnover type: Income, Expenditure)
any date or date range. In fact, I have to recalculate the data from this intermediate table with each manipulation from the transaction table.
Example #1
Date Document type Amount Child
01.10.2018 "Account" 50.00 Child No. 1
02.10.2018 "Account" 55.00 Child No. 1
03.10.2018 "Payment" 50.00 Child No. 1
10.11.2018 "Account" 50.00 Child No.
1 in an intermediate table of the form:
Date Child Starting Balance Turnover Ending Balance
01.10.2018 Child No. 1 0.00 55.00 55.00
01.11.2018 Child No. 1 55.00 50.00 105.00
An intermediate table is needed in order not to recalculate the balances for the child every time you need to display information. This is a simplified version, in fact, the possibility of making payments or charges retroactively, their removal retroactively (operator errors), recalculation when changing the tariff fee from a certain date should also be taken into account.
Maybe you have ideas on how to properly store or implement all this, whether I'm going the right way, or maybe I'm complicating the task myself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Shatalov, 2018-11-14
@netpastor

Accrual - with a plus sign
Payment - with a minus sign
All calculations for you will be done by the database very famously
Intermediate table is not needed in direct form - in its place I would make SQL View + managed=False model
All errors, backdated payments and backdated deletion - will not affect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question