Skip to content

Commit

Permalink
implement simple transactions import and add to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmurilo75 committed May 6, 2024
1 parent de58a30 commit bc02c0d
Show file tree
Hide file tree
Showing 12 changed files with 456 additions and 131 deletions.
58 changes: 58 additions & 0 deletions development_notebook/2024-05-05.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# State Of Work

* Project has been fully configured from cookiecutter-django using MySQL.
* Deployed to production at [negligentoctopus.pythonanywhere.com](negligentoctopus.pythonanywhere.com).

Core models are defined and added to the django-admin.
Account and Transactions have been implemented with balance as prefix-sum.
Transfers are implemented as coupled transactions.

We have implemented a SimpleTransactionImport model and admin, which processes on save and creates SimpleImportedTransactions. These can be validated by a checkbox and if so, will create a Transaction on save.

Created a custom admin site to use as prototype, currently in phase preparation for alpha testing. Pages, for example list view, will be slowly redirect to main site as they are implemented.
Sign up on main site is fully functionational, with email confirmation.

## Update

# Today

## Work Log
__InProgress__
* Add simple import for transactions (for example from edenred csv)
* Once this is defined, rewrite Activo using the extension points

* Write selenium script to get edenred - use js from browser

__ToDo__
* Implement alpha prototype admin login.
* Implement Forms for admin

* Create homepage with reporting.

* Define DRF for core
* Write admin tests


__Done__
* Add simple import for transactions (for example from edenred csv)
* Currently in progress to define an API - since this is first version of a general solution doesnt really matter
* Define SimpleImport then define SimpleTransaction
* Add it to admin and test

* Change existing user mrmurilo73 to use group permissions. (in local)

__Discarded__

# To Do
* Write tests
* For uploading activo file thru admin
* Setting name from filename
* only allowed extensions files
* For Activo transaction

__Next on road map:__
Export transactions to file.
v2. -> extended management command to be more modular. Code option to load Montepio export.
v3. -> define budget loadedTransaction as inherited from transaction and give the option to associate as previous transaction, filter by value and not associated, or validate auto create new transaction.
v4. -> create association between certain titles/transactions loaded into categories/ template transactions
Create new admin for end users.
58 changes: 58 additions & 0 deletions development_notebook/2024-05-06.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# State Of Work

* Project has been fully configured from cookiecutter-django using MySQL.
* Deployed to production at [negligentoctopus.pythonanywhere.com](negligentoctopus.pythonanywhere.com).

Core models are defined and added to the django-admin.
Account and Transactions have been implemented with balance as prefix-sum.
Transfers are implemented as coupled transactions.

We have implemented a SimpleTransactionImport model and admin, which processes on save and creates SimpleImportedTransactions. These can be validated by a checkbox and if so, will create a Transaction on save.

Created a custom admin site to use as prototype, currently in phase preparation for alpha testing. Pages, for example list view, will be slowly redirect to main site as they are implemented.
Sign up on main site is fully functionational, with email confirmation.

## Update

# Today

## Work Log
__InProgress__
* Add simple import for transactions (for example from edenred csv)
* Once this is defined, rewrite Activo using the extension points

* Write selenium script to get edenred - use js from browser

__ToDo__
* Implement alpha prototype admin login.
* Implement Forms for admin

* Create homepage with reporting.

* Define DRF for core
* Write admin tests


__Done__
* Add simple import for transactions (for example from edenred csv)
* Currently in progress to define an API - since this is first version of a general solution doesnt really matter
* Define SimpleImport then define SimpleTransaction
* Add it to admin and test

* Change existing user mrmurilo73 to use group permissions. (in local)

__Discarded__

# To Do
* Write tests
* For uploading activo file thru admin
* Setting name from filename
* only allowed extensions files
* For Activo transaction

__Next on road map:__
Export transactions to file.
v2. -> extended management command to be more modular. Code option to load Montepio export.
v3. -> define budget loadedTransaction as inherited from transaction and give the option to associate as previous transaction, filter by value and not associated, or validate auto create new transaction.
v4. -> create association between certain titles/transactions loaded into categories/ template transactions
Create new admin for end users.
4 changes: 2 additions & 2 deletions negligent_octopus/alpha_prototype/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .models import OpenAccountAdmin # noqa: F401
from .models import OpenCategoryAdmin # noqa: F401
from .models import OpenImportActivoAdmin # noqa: F401
from .models import OpenImportedActivoTransactionAdmin # noqa: F401
from .models import OpenSimpleImportedTransactionAdmin # noqa: F401
from .models import OpenSimpleTransactionsImportAdmin # noqa: F401
from .models import OpenTransactionAdmin # noqa: F401
from .site import alpha_admin_site # noqa: F401
16 changes: 8 additions & 8 deletions negligent_octopus/alpha_prototype/admin/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from negligent_octopus.budget.admin import ImportActivoAdmin
from negligent_octopus.budget.admin import ImportedActivoTransactionAdmin
from negligent_octopus.budget.models import ImportActivo
from negligent_octopus.budget.models import ImportedActivoTransaction
from negligent_octopus.budget.admin import SimpleImportedTransactionAdmin
from negligent_octopus.budget.admin import SimpleTransactionsImportAdmin
from negligent_octopus.budget.models import SimpleImportedTransaction
from negligent_octopus.budget.models import SimpleTransactionsImport
from negligent_octopus.core.admin import AccountAdmin
from negligent_octopus.core.admin import CategoryAdmin
from negligent_octopus.core.admin import TransactionAdmin
Expand All @@ -20,11 +20,11 @@ def get_queryset(self, request):
return qs.filter(**{self.user_relation_field: request.user})


class OpenImportActivoAdmin(ImportActivoAdmin, BaseOpenAdmin):
class OpenSimpleTransactionsImportAdmin(SimpleTransactionsImportAdmin, BaseOpenAdmin):
pass


class OpenImportedActivoTransactionAdmin(ImportedActivoTransactionAdmin, BaseOpenAdmin):
class OpenSimpleImportedTransactionAdmin(SimpleImportedTransactionAdmin, BaseOpenAdmin):
user_relation_field = "loaded_from__owner"


Expand All @@ -40,8 +40,8 @@ class OpenAccountAdmin(AccountAdmin, BaseOpenAdmin):
pass


alpha_admin_site.register(ImportActivo, OpenImportActivoAdmin)
alpha_admin_site.register(ImportedActivoTransaction, OpenImportedActivoTransactionAdmin)
alpha_admin_site.register(SimpleTransactionsImport, OpenSimpleTransactionsImportAdmin)
alpha_admin_site.register(SimpleImportedTransaction, OpenSimpleImportedTransactionAdmin)
alpha_admin_site.register(Account, OpenAccountAdmin)
alpha_admin_site.register(Category, OpenCategoryAdmin)
alpha_admin_site.register(Transaction, OpenTransactionAdmin)
61 changes: 28 additions & 33 deletions negligent_octopus/budget/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@
from negligent_octopus.utils.admin import LimitedQuerysetInlineAdmin
from negligent_octopus.utils.admin import LimitedQuerysetInlineFormset

from .models import ImportActivo
from .models import ImportedActivoTransaction
from .models import SimpleImportedTransaction
from .models import SimpleTransactionsImport


class ImportedActivoTransactionInlineFormset(LimitedQuerysetInlineFormset):
class SimpleImportedTransactionInlineFormset(LimitedQuerysetInlineFormset):
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs)[::-1]


class ImportedActivoTransactionInlineAdmin(LimitedQuerysetInlineAdmin):
model = ImportedActivoTransaction
class SimpleImportedTransactionInlineAdmin(LimitedQuerysetInlineAdmin):
model = SimpleImportedTransaction
fk_name = "loaded_from"
fields = [
"loaded_from",
"date_of_movement",
"date_of_process",
"description",
"value",
"date",
"title",
"amount",
"balance",
"validated",
"transaction",
]
extra = 0
formset = ImportedActivoTransactionInlineFormset
formset = SimpleImportedTransactionInlineFormset


@admin.register(ImportActivo)
class ImportActivoAdmin(admin.ModelAdmin):
@admin.register(SimpleTransactionsImport)
class SimpleTransactionsImportAdmin(admin.ModelAdmin):
list_display = ["owner", "name", "account", "processed", "created"]
list_display_links = ["name"]
search_fields = ["name", "account__name", "owner__name"]
Expand All @@ -40,7 +39,7 @@ class ImportActivoAdmin(admin.ModelAdmin):
"processed",
"created",
]
inlines = [ImportedActivoTransactionInlineAdmin]
inlines = [SimpleImportedTransactionInlineAdmin]

def get_inlines(self, request, obj):
if obj is None:
Expand All @@ -50,7 +49,7 @@ def get_inlines(self, request, obj):
def get_readonly_fields(
self,
request,
obj: ImportActivo | None = None,
obj=None,
):
if obj is None:
return self.readonly_fields
Expand All @@ -60,38 +59,35 @@ def get_readonly_fields(
return readonly_fields


@admin.register(ImportedActivoTransaction)
class ImportedActivoTransactionAdmin(admin.ModelAdmin):
@admin.register(SimpleImportedTransaction)
class SimpleImportedTransactionAdmin(admin.ModelAdmin):
fields = [
"loaded_from",
"date_of_movement",
"date_of_process",
"description",
"value",
"date",
"title",
"amount",
"balance",
"validated",
"transaction",
]
list_display = [
"get_load_owner",
"date_of_movement",
"date_of_process",
"description",
"value",
"date",
"title",
"amount",
"balance",
"validated",
"has_transaction",
]
list_display_links = ["description"]
list_display_links = ["title"]
search_fields = [
"description",
"value",
"title",
"amount",
"balance",
]
list_filter = [
"loaded_from__owner",
"date_of_movement",
"date_of_process",
"date",
"validated",
]
readonly_fields = ["loaded_from"]
Expand All @@ -100,10 +96,9 @@ def get_readonly_fields(self, request, obj=None):
if obj is not None and obj.validated and obj.transaction is not None:
return [
*self.readonly_fields,
"date_of_movement",
"date_of_process",
"description",
"value",
"date",
"title",
"amount",
"balance",
"validated",
"transaction",
Expand Down
2 changes: 1 addition & 1 deletion negligent_octopus/budget/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Migration(migrations.Migration):
(
"load",
models.FileField(
upload_to=negligent_octopus.budget.models.upload_activo_import_to,
upload_to=negligent_octopus.budget.models.upload_import_file_to,
validators=[
negligent_octopus.utils.validators.FileExtensionValidator(
("csv", "xsls")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Migration(migrations.Migration):
model_name="importactivo",
name="load",
field=models.FileField(
upload_to=negligent_octopus.budget.models.upload_activo_import_to,
upload_to=negligent_octopus.budget.models.upload_import_file_to,
validators=[
negligent_octopus.utils.validators.FileExtensionValidator(
(
Expand Down
Loading

0 comments on commit bc02c0d

Please sign in to comment.