From 8c5d0da1f928ce76ff87be85d056c2f216c2137f Mon Sep 17 00:00:00 2001 From: HaiderAlalawi Date: Mon, 1 Aug 2022 16:02:16 +0300 Subject: [PATCH 1/2] haider abdulameer task3 --- accounting/api/account.py | 43 ++++++++++++++++++++++---------------- db.sqlite3 | Bin 159744 -> 159744 bytes 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/accounting/api/account.py b/accounting/api/account.py index e843e61..c73e67b 100644 --- a/accounting/api/account.py +++ b/accounting/api/account.py @@ -1,9 +1,14 @@ +from asyncio.windows_events import NULL +from decimal import Decimal +from importlib.abc import PathEntryFinder +from typing_extensions import Self +from django.http import Http404, HttpRequest from ninja import Router from ninja.security import django_auth from django.shortcuts import get_object_or_404 from accounting.models import Account, AccountTypeChoices from accounting.schemas import AccountOut, FourOFourOut, GeneralLedgerOut -from typing import List +from typing import List, final from django.db.models import Sum, Avg from rest_framework import status @@ -49,30 +54,33 @@ def get_account_balance(request, account_id: int): def get_account_balances(request): accounts = Account.objects.all() result = [] + for a in accounts: result.append({ - 'account': a.name, 'balance': list(a.balance()) - }) + 'account': a.name, 'balance': list(a.balance()),'id':a.id + }) + + for b in accounts: + if b.parent_id == None: + result[next((i for i, x in enumerate(result) if x["id"] == b.id))]['balance'] = (Balance.__add__(Balance(result[next((i for i, x in enumerate(result) if x["id"] == b.id))]['balance']), Balance(list(b.balance())))) + else: + result[next((i for i, x in enumerate(result) if x["id"] == b.parent_id))]['balance'] = (Balance.__add__(Balance(result[next((i for i, x in enumerate(result) if x["id"] == b.parent_id))]['balance']), Balance(list(b.balance())))) return status.HTTP_200_OK, result - - class Balance: def __init__(self, balances): - balance1 = balances[0] - balance2 = balances[1] + balanceIQD = [] + balanceUSD = [] + for i in balances: + if i['currency'] == 'USD': + balanceUSD.append(int(i['sum'])) + if i['currency'] == 'IQD': + balanceIQD.append(int(i['sum'])) - if balance1['currency'] == 'USD': - balanceUSD = balance1['sum'] - balanceIQD = balance2['sum'] - else: - balanceIQD = balance1['sum'] - balanceUSD = balance2['sum'] - - self.balanceUSD = balanceUSD - self.balanceIQD = balanceIQD + self.balanceUSD = sum(balanceUSD) + self.balanceIQD = sum(balanceIQD) def __add__(self, other): self.balanceIQD += other.balanceIQD @@ -83,5 +91,4 @@ def __add__(self, other): }, { 'currency': 'IQD', 'sum': self.balanceIQD - }] - + }] \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 3cb73d59be6da4a2a0517a8aae2d66cff6d9bafd..59b836fb606ff3e5e0b701d427c92ef105562662 100644 GIT binary patch delta 1636 zcmai!Yiv_x7{}jpy0+)6mxqBccTqYvf`+s^xAvTtOl)`Q+O;cN$JnN1>2>Ya_Ox4f zY3DK!LohK>X~I63XfOmmVU&d|F*AHnz5vE4iTeVALJS&_NH8W~qVMS-AeVSPJm)0u z^ZcIY{h$B)?z>9wyGp-TM|8Yj->U9FmOb9jq91OqegVj;*O*WqmtVHXtPS2zlb z4a|9C>AIzk&>U{ASL+~#YD*2x?Zm~>NV8o-)qqMQ7T7*wBSDsyn_Fvil?WjURuTLS zH{d2*hQHu8`~<6*bOuT*^A*)vszQYbty)D8>I&sktpv^D?Van_ZK7cc!5_HbB76m> z;W!+DgD{1QUx#%@od&5k5QO%q$K0h*Q2%iWF{h~W2Mh!FCO$9g1hiL9`$>;gWF$%6*!06ep=ooN$K!rg$HSOaN-S| zdI=~0CryLX-W7~$IEmmE`~Y9$O`OD(4*(3B3bdgHkG$4(arvW86Ga+NA?P=rT5K>K zH_q>GAdP5$i<34OXxdqaP&PakjdQ~ji4bSCHSrvSpQhg4@xWwiS2mEF8O(D-@lM8* z8u2%^7u!7DIe%*VNNX`39B|pPgXwYJR~*`I4cH1?SCSvd6cWvyQ-Y_3V>r&th-RKK zv4X?OIRw#SleTh#XnkUd7c4fG5kx-mYQlo`D)oQ!2}Qy+WrNoit5#M)uT#|#_gBdS zx2`PRxaY8Ng8 zxeYVUD%Mj>cM~iA2n91vlo^d=nL(BrWSK#h8KkyCMH3n&lz#i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ider Abdulameer --- accounting/api/account.py | 14 +++++++++++++- db.sqlite3 | Bin 159744 -> 159744 bytes 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/accounting/api/account.py b/accounting/api/account.py index c73e67b..f449a24 100644 --- a/accounting/api/account.py +++ b/accounting/api/account.py @@ -91,4 +91,16 @@ def __add__(self, other): }, { 'currency': 'IQD', 'sum': self.balanceIQD - }] \ No newline at end of file + }] + + + def __gt__(self,other): + return(self.balanceIQD > other.balanceIQD , self.balanceUSD > other.balanceUSD) + + + def __ls__(self,other): + return(self.balanceIQD < other.balanceIQD , self.balanceUSD < other.balanceUSD) + + + def is_zero(self): + return(self.balanceIQD == 0 and self.balanceUSD == 0) \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 59b836fb606ff3e5e0b701d427c92ef105562662..c9edebb6f4d523cc01f69a88b4ab10ef1a0c857d 100644 GIT binary patch delta 238 zcmZp8z}fJCbAmLZ-$WT_M!$^-2hWLE=o%O)7@Arcm{=KF>X{iCn;V-qo1WipdY-W@ zS3WP(w7|qH*TTp&xjZE|$+Eb_G_SBY&otS{Br7AWeEKaLrWIbEB|#xpMz@U#2hWL^>lzy<7@Am_8d;f`>zP>?nV6e4o1WipdY-W@ zSH99R(V(QF%E%%!J+IWf#Go)cKR3;=BriERGuy-