Skip to content

Commit

Permalink
v0.5.5.5 (#174)
Browse files Browse the repository at this point in the history
* v0.5.5.5

* v0.5.5.5
New Django Ledger Admin Interface

* v0.5.5.5
EntityUnitInLine Admin

* v0.5.5.5
README.md update
  • Loading branch information
elarroba committed Dec 15, 2023
1 parent 5310e2f commit 0791439
Show file tree
Hide file tree
Showing 23 changed files with 2,121 additions and 1,031 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Finance and Accounting is a complicated subject. Django Ledger is different from
as it aims to provide a developer-friendly accounting engine while providing a reliable and extensible API to
power financially driven applications. This project in particular, not only requires Python AND Django programming
experience, but also finance and accounting experience. So, that's the long way of saying, we need your help!
Join our Discord Channel [here](https://discord.gg/c7PZcbYgrc) to learn more.
Join our Discord Channel [here](https://discord.gg/J7KDFgCCsw) to learn more.

__This project can greatly benefit from contributions towards Documentation and Unit Tests.__
__This is the best way to get started twith this project if you are not familiar with the models.__
Expand Down
2 changes: 1 addition & 1 deletion django_ledger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
default_app_config = 'django_ledger.apps.DjangoLedgerConfig'

"""Django Ledger"""
__version__ = '0.5.5.4'
__version__ = '0.5.5.5'
__license__ = 'GPLv3 License'

__author__ = 'Miguel Sanda'
Expand Down
160 changes: 0 additions & 160 deletions django_ledger/admin.py

This file was deleted.

10 changes: 10 additions & 0 deletions django_ledger/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib import admin

from django_ledger.admin.coa import ChartOfAccountsModelAdmin
from django_ledger.admin.entity import EntityModelAdmin
from django_ledger.admin.ledger import LedgerModelAdmin
from django_ledger.models import EntityModel, ChartOfAccountModel, LedgerModel

admin.site.register(EntityModel, EntityModelAdmin)
admin.site.register(ChartOfAccountModel, ChartOfAccountsModelAdmin)
admin.site.register(LedgerModel, LedgerModelAdmin)
135 changes: 135 additions & 0 deletions django_ledger/admin/coa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from django.contrib.admin import TabularInline, ModelAdmin
from django.db.models import Count
from django.forms import ModelForm, BooleanField, BaseInlineFormSet

from django_ledger.models.accounts import AccountModel
from django_ledger.models.coa import ChartOfAccountModel
from django_ledger.models.entity import EntityModel


class AccountModelInLineForm(ModelForm):
role_default = BooleanField(initial=False, required=False)

class Meta:
model = AccountModel
fields = []


class AccountModelInLineFormSet(BaseInlineFormSet):

def save_new(self, form, commit=True):
setattr(form.instance, self.fk.name, self.instance)
if commit:
account_model = AccountModel.add_root(
instance=super().save_new(form, commit=False)
)
return account_model
return super().save_new(form, commit=False)


class AccountModelInLine(TabularInline):
extra = 0
form = AccountModelInLineForm
formset = AccountModelInLineFormSet
show_change_link = True
exclude = [
'path',
'depth',
'numchild'
]
model = AccountModel
fieldsets = [
('', {
'fields': [
'role',
'balance_type',
'code',
'name',
'role_default',
'locked',
'active'
]
})
]

def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.not_coa_root()


class ChartOfAccountsAdminForm(ModelForm):
assign_as_default = BooleanField(initial=False, required=False)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.instance.is_default():
self.fields['assign_as_default'].initial = True
self.fields['assign_as_default'].disabled = True

def save(self, commit=True):
if commit:
if self.cleaned_data['assign_as_default']:
entity_model: EntityModel = self.instance.entity
entity_model.default_coa = self.instance
entity_model.save(update_fields=[
'default_coa'
])
return super().save(commit=commit)


class ChartOfAccountsInLine(TabularInline):
form = ChartOfAccountsAdminForm
model = ChartOfAccountModel
extra = 0
show_change_link = True
fields = [
'name',
'locked',
'assign_as_default'
]


class ChartOfAccountsModelAdmin(ModelAdmin):
list_filter = [
'entity__name',
'locked'
]
list_display = [
'entity_name',
'name',
'slug',
'locked',
'account_model_count'
]
search_fields = [
'slug',
'entity__name'
]
list_display_links = ['name']
fields = [
'name',
'locked',
'description',
]
inlines = [
AccountModelInLine
]

class Meta:
model = ChartOfAccountModel

def entity_name(self, obj):
return obj.entity.name

def get_queryset(self, request):
qs = ChartOfAccountModel.objects.for_user(user_model=request.user)
ordering = self.get_ordering(request)
if ordering:
qs = qs.order_by(*ordering)
qs = qs.select_related('entity').annotate(Count('accountmodel'))
return qs

def account_model_count(self, obj):
return obj.accountmodel__count

account_model_count.short_description = 'Accounts'

0 comments on commit 0791439

Please sign in to comment.