Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions accounting/api/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import List
from django.db.models import Sum, Avg
from rest_framework import status
import mptt

from restauth.authorization import AuthBearer

Expand Down Expand Up @@ -60,17 +61,15 @@ def get_account_balances(request):


class Balance:
def __init__(self, balances):
balance1 = balances[0]
balance2 = balances[1]

if balance1['currency'] == 'USD':
balanceUSD = balance1['sum']
balanceIQD = balance2['sum']
else:
balanceIQD = balance1['sum']
balanceUSD = balance2['sum']

def __init__(self, balances):
balanceIQD = 0
balanceUSD = 0
for i in balances:
if i['currency'] == 'USD':
balanceUSD = i['sum']
if i['currency'] == 'IQD':
balanceIQD = i['sum']
self.balanceUSD = balanceUSD
self.balanceIQD = balanceIQD

Expand All @@ -85,3 +84,8 @@ def __add__(self, other):
'sum': self.balanceIQD
}]

def __radd__(self,other):
if other == 0:
return self
else:
return self.__add__(other)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.0.6 on 2022-08-03 14:02

from django.db import migrations, models
import django.db.models.deletion
import mptt.fields


class Migration(migrations.Migration):

dependencies = [
('accounting', '0006_alter_account_code_alter_account_full_code_and_more'),
]

operations = [
migrations.AddField(
model_name='account',
name='level',
field=models.PositiveIntegerField(default=0, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='account',
name='lft',
field=models.PositiveIntegerField(default=0, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='account',
name='rght',
field=models.PositiveIntegerField(default=0, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='account',
name='tree_id',
field=models.PositiveIntegerField(db_index=True, default=0, editable=False),
preserve_default=False,
),
migrations.AlterField(
model_name='account',
name='parent',
field=mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounting.account'),
),
]
20 changes: 17 additions & 3 deletions accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from django.dispatch import receiver
from django.db.models.signals import post_save
from accounting.exceptions import AccountingEquationError
from mptt.models import TreeForeignKey,MPTTModel
from mptt.fields import TreeForeignKey
from django.shortcuts import get_object_or_404



'''

Expand Down Expand Up @@ -48,8 +53,8 @@ class CurrencyChoices(models.TextChoices):
IQD = 'IQD', 'IQD'


class Account(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL)
class Account(MPTTModel):
parent = TreeForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL)
type = models.CharField(max_length=255, choices=AccountTypeChoices.choices)
name = models.CharField(max_length=255)
code = models.CharField(max_length=20, null=True, blank=True)
Expand All @@ -60,7 +65,16 @@ def __str__(self):
return f'{self.full_code} - {self.name}'

def balance(self):
return self.journal_entries.values('currency').annotate(sum=Sum('amount')).order_by()
result = [
account.journal_entries.values('currency').annotate(sum=Sum('amount')).order_by()
for account in self.get_descendants(include_self=False)

]
return result



#return self.journal_entries.values('currency').annotate(sum=Sum('amount')).order_by()

# def save(
# self, force_insert=False, force_update=False, using=None, update_fields=None
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
28 changes: 28 additions & 0 deletions task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
iqd = 50
usd = 40
def __gt__(self, other):
IQD = bool(self.balanceiqd > other.balanceIQD)
USD = bool(self.balanceUSD > other.balanceUSD)
return IQD, USD


def __lt__(self, other):
IQD = bool(self.balanceiqd < other.balanceIQD)
USD = bool(self.balanceUSD < other.balanceUSD)
return IQD, USD


def other_than_gt_and_ls(self, other):
if self.balanceIQD > other.balanceIQD and self.balanceUSD < other.balanceUSD:
return True, False
else:
return False, True


def is_zero(self):
if self.balanceIQD == 0 and self.balanceUSD == 0:
return True
else:
return False

print(iqd.__lt__(50))