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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
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 22:07

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, related_name='children', 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.

14 changes: 8 additions & 6 deletions accounting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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
'''

Account
Expand Down Expand Up @@ -47,10 +47,9 @@ class CurrencyChoices(models.TextChoices):
USD = 'USD', 'USD'
IQD = 'IQD', 'IQD'


class Account(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL)
class Account(MPTTModel):
type = models.CharField(max_length=255, choices=AccountTypeChoices.choices)
parent = TreeForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL ,related_name='children')
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)
Expand All @@ -60,8 +59,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 result
# def save(
# self, force_insert=False, force_update=False, using=None, update_fields=None
# ):
Expand Down
2 changes: 2 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

'restauth',
'accounting',
'rest_framework',
'mptt'
]

AUTH_USER_MODEL = 'restauth.EmailAccount'
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ rsa==4.9
six==1.16.0
sqlparse==0.4.2
typing_extensions==4.3.0
Operations to perform:
Apply all migrations: accounting, admin, auth, contenttypes, restauth, sessions
Running migrations:
No migrations to apply.
Loading