Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ahmed Mudhier Habeeb #88

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
1 change: 0 additions & 1 deletion accounting/api/account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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
Expand Down
60 changes: 60 additions & 0 deletions accounting/api/task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

class Balance:

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

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

self.balanceUSD = balanceUSD
self.balanceIQD = balanceIQD

def __add__(self, other):

self.balanceIQD += other.balanceIQD
self.balanceUSD += other.balanceUSD
result=[{
'currency': 'USD',
'sum': self.balanceUSD
}, {
'currency': 'IQD',
'sum': self.balanceIQD
}]

return result
#Old
def __Othan__ (self, other):
if self.balanceIQD > other.balanceIQD:
theIQD = True
else:
theIQD = False
if self.balanceUSD > other.balanceUSD:
theUSD = True
else:
theUSD = False
return {'BalanceIQD': theIQD, 'BalanceUSD': theUSD}

#Younger
def __Ythan__ (self, other):
if self.balanceIQD < other.balanceIQD:
theIQD = True
else:
theIQD = False
if self.balanceUSD < other.balanceUSD:
theUSD = True
else:
theUSD = False
return {'BalanceIQD': theIQD, 'BalanceUSD': theUSD}

# zero
def __isZero__(self):
if self.balanceIQD == 0 and self.balanceUSD==0:
return True
else:
return False
25 changes: 17 additions & 8 deletions accounting/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.db import models
from django.db.models import Sum
from django.dispatch import receiver
from django.db.models.signals import post_save
from mptt.models import MPTTModel, TreeForeignKey
from accounting.exceptions import AccountingEquationError

'''
Expand Down Expand Up @@ -48,19 +47,26 @@ 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)
full_code = models.CharField(max_length=25, null=True, blank=True)
extra = models.JSONField(default=dict, null=True, blank=True)

class MPTTMeta:
order_insertion_by = ['full_code']

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.ournal_entries.values('currency').annotate(sum=Sum('amount')).order_by()
for account in self.get_descendants(include_self=True)
]
return result

# def save(
# self, force_insert=False, force_update=False, using=None, update_fields=None
Expand Down Expand Up @@ -89,7 +95,7 @@ def balance(self):
# instance.full_code = f'{instance.id}'


class Transaction(models.Model):
class Transaction(MPTTModel):
type = models.CharField(max_length=255, choices=TransactionTypeChoices.choices)
description = models.CharField(max_length=255)

Expand All @@ -100,11 +106,14 @@ def validate_accounting_equation(self):
raise AccountingEquationError


class JournalEntry(models.Model):
class JournalEntry(MPTTModel):
class Meta:
verbose_name_plural = 'Journal Entries'

account = models.ForeignKey(Account, on_delete=models.CASCADE, related_name='journal_entries')
class MPTTMeta:
order_insertion_by = ['full_code']

account = TreeForeignKey(Account, on_delete=models.CASCADE, related_name='journal_entries')
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE, related_name='journal_entries')
amount = models.DecimalField(max_digits=19, decimal_places=2)
currency = models.CharField(max_length=3, choices=CurrencyChoices.choices)
Expand Down
1 change: 1 addition & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'mptt',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
Expand Down