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
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

6 changes: 4 additions & 2 deletions .idea/unicoding.iml

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

22 changes: 20 additions & 2 deletions accounting/api/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ def get_account_balances(request):
return status.HTTP_200_OK, result




class Balance:
def __init__(self, balances):
balance1 = balances[0]
Expand All @@ -85,3 +83,23 @@ def __add__(self, other):
'sum': self.balanceIQD
}]

def __sub__(self, other):
self.balanceIQD -= other.balanceIQD
self.balanceUSD -= other.balanceUSD
return [{
'currency': 'USD',
'sum': self.balanceUSD
}, {
'currency': 'IQD',
'sum': self.balanceIQD
}]

def __gt__(self, other):
return self.balanceUSD > other.balanceUSD, self.balanceIQD > other.balanceIQD

def __lt__(self, other):
return self.balanceUSD < other.balanceUSD, self.balanceIQD < other.balanceIQD

def is_zero(self):
return self.balanceUSD == 0 and self.balanceIQD == 0

29 changes: 21 additions & 8 deletions accounting/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by Django 4.0.6 on 2022-07-20 14:33
# Generated by Django 4.0.6 on 2022-08-02 19:21

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


class Migration(migrations.Migration):
Expand All @@ -16,17 +17,26 @@ class Migration(migrations.Migration):
name='Account',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('type', models.CharField(choices=[('ASSETS', 'ASSETS'), ('LIABILITIES', 'LIABILITIES'), ('INCOME', 'INCOME'), ('EXPENSES', 'EXPENSES')], max_length=255)),
('code', models.CharField(max_length=20)),
('full_code', models.CharField(max_length=25)),
('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounting.account')),
('type', models.CharField(choices=[('ASSETS', 'Assets'), ('LIABILITIES', 'Liabilities'), ('INCOME', 'Income'), ('EXPENSES', 'Expenses')], max_length=255)),
('name', models.CharField(max_length=255)),
('code', models.CharField(blank=True, max_length=20, null=True)),
('full_code', models.CharField(blank=True, max_length=25, null=True)),
('extra', models.JSONField(blank=True, default=dict, null=True)),
('lft', models.PositiveIntegerField(editable=False)),
('rght', models.PositiveIntegerField(editable=False)),
('tree_id', models.PositiveIntegerField(db_index=True, editable=False)),
('level', models.PositiveIntegerField(editable=False)),
('parent', mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounting.account')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Transaction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('type', models.CharField(choices=[('invoice', 'invoice'), ('income', 'income'), ('expense', 'expense'), ('bill', 'bill')], max_length=255)),
('type', models.CharField(choices=[('invoice', 'Invoice'), ('income', 'Income'), ('expense', 'Expense'), ('bill', 'Bill')], max_length=255)),
('description', models.CharField(max_length=255)),
],
),
Expand All @@ -36,8 +46,11 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('amount', models.DecimalField(decimal_places=2, max_digits=19)),
('currency', models.CharField(choices=[('USD', 'USD'), ('IQD', 'IQD')], max_length=3)),
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounting.account')),
('transaction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounting.transaction')),
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='journal_entries', to='accounting.account')),
('transaction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='journal_entries', to='accounting.transaction')),
],
options={
'verbose_name_plural': 'Journal Entries',
},
),
]

This file was deleted.

23 changes: 0 additions & 23 deletions accounting/migrations/0003_account_extra_alter_account_type.py

This file was deleted.

18 changes: 0 additions & 18 deletions accounting/migrations/0004_alter_account_extra.py

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 8 additions & 3 deletions accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.dispatch import receiver
from django.db.models.signals import post_save
from accounting.exceptions import AccountingEquationError
from mptt.models import MPTTModel, TreeForeignKey

'''

Expand Down Expand Up @@ -48,8 +49,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 +61,11 @@ 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=True)
]
return Sum(result)

# def save(
# self, force_insert=False, force_update=False, using=None, update_fields=None
Expand Down
18 changes: 0 additions & 18 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
asgiref==3.5.2
Django==4.0.6
django-ninja==0.19.0
django-rest-framework==0.1.0
djangorestframework==3.13.1
dnspython==2.2.1
ecdsa==0.18.0
email-validator==1.2.1
idna==3.3
psycopg2-binary==2.9.3
pyasn1==0.4.8
pydantic==1.9.1
python-jose==3.3.0
pytz==2022.1
rsa==4.9
six==1.16.0
sqlparse==0.4.2
typing_extensions==4.3.0