-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from fylein/accounting_export_apis
Accounting export apis added
- Loading branch information
Showing
16 changed files
with
562 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from django.db import models | ||
from django.contrib.postgres.fields import ArrayField | ||
|
||
from fyle_accounting_mappings.models import ExpenseAttribute | ||
|
||
from sage_desktop_api.models.fields import ( | ||
StringNotNullField, | ||
StringNullField, | ||
CustomJsonField, | ||
CustomDateTimeField, | ||
BooleanFalseField, | ||
TextNotNullField, | ||
StringOptionsField | ||
) | ||
from apps.workspaces.models import BaseForeignWorkspaceModel | ||
from apps.fyle.models import Expense | ||
|
||
TYPE_CHOICES = ( | ||
('INVOICES', 'INVOICES'), | ||
('DIRECT_COST', 'DIRECT_COST'), | ||
('FETCHING_REIMBURSABLE_EXPENSES', 'FETCHING_REIMBURSABLE_EXPENSES'), | ||
('FETCHING_CREDIT_CARD_EXPENENSES', 'FETCHING_CREDIT_CARD_EXPENENSES') | ||
) | ||
|
||
|
||
ERROR_TYPE_CHOICES = (('EMPLOYEE_MAPPING', 'EMPLOYEE_MAPPING'), ('CATEGORY_MAPPING', 'CATEGORY_MAPPING'), ('SAGE300_ERROR', 'SAGE300_ERROR')) | ||
|
||
|
||
class AccountingExport(BaseForeignWorkspaceModel): | ||
""" | ||
Table to store accounting exports | ||
""" | ||
id = models.AutoField(primary_key=True) | ||
type = StringOptionsField(choices=TYPE_CHOICES, help_text='Task type') | ||
fund_source = StringNotNullField(help_text='Expense fund source') | ||
mapping_errors = ArrayField(help_text='Mapping errors', base_field=models.CharField(max_length=255), blank=True, null=True) | ||
expenses = models.ManyToManyField(Expense, help_text="Expenses under this Expense Group") | ||
task_id = StringNullField(help_text='Fyle Jobs task reference') | ||
description = CustomJsonField(help_text='Description') | ||
status = StringNotNullField(help_text='Task Status') | ||
detail = CustomJsonField(help_text='Task Response') | ||
sage_300_errors = CustomJsonField(help_text='Sage 300 Errors') | ||
exported_at = CustomDateTimeField(help_text='time of export') | ||
|
||
class Meta: | ||
db_table = 'accounting_exports' | ||
|
||
|
||
class Error(BaseForeignWorkspaceModel): | ||
""" | ||
Table to store errors | ||
""" | ||
id = models.AutoField(primary_key=True) | ||
type = StringOptionsField(max_length=50, choices=ERROR_TYPE_CHOICES, help_text='Error type') | ||
accounting_export = models.ForeignKey( | ||
AccountingExport, on_delete=models.PROTECT, | ||
null=True, help_text='Reference to Expense group' | ||
) | ||
expense_attribute = models.OneToOneField( | ||
ExpenseAttribute, on_delete=models.PROTECT, | ||
null=True, help_text='Reference to Expense Attribute' | ||
) | ||
is_resolved = BooleanFalseField(help_text='Is resolved') | ||
error_title = StringNotNullField(help_text='Error title') | ||
error_detail = TextNotNullField(help_text='Error detail') | ||
|
||
class Meta: | ||
db_table = 'errors' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import AccountingExport, Error | ||
|
||
|
||
class AccountingExportSerializer(serializers.ModelSerializer): | ||
""" | ||
Accounting Export serializer | ||
""" | ||
|
||
class Meta: | ||
model = AccountingExport | ||
fields = '__all__' | ||
|
||
|
||
class ErrorSerializer(serializers.ModelSerializer): | ||
""" | ||
Serializer for the Errors | ||
""" | ||
|
||
class Meta: | ||
model = Error | ||
fields = '__all__' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""sage_desktop_api URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/3.0/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
from django.urls import path | ||
|
||
from .views import AccountingExportView, ErrorsView | ||
|
||
|
||
urlpatterns = [ | ||
path('', AccountingExportView.as_view(), name='accounting-exports'), | ||
path('errors/', ErrorsView.as_view(), name='errors'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import logging | ||
|
||
from django_filters.rest_framework import DjangoFilterBackend | ||
from rest_framework import generics | ||
from sage_desktop_api.utils import LookupFieldMixin | ||
from apps.accounting_exports.serializers import AccountingExportSerializer, ErrorSerializer | ||
from apps.accounting_exports.models import AccountingExport, Error | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.level = logging.INFO | ||
|
||
|
||
class AccountingExportView(LookupFieldMixin, generics.ListAPIView): | ||
""" | ||
Retrieve or Create Accounting Export | ||
""" | ||
serializer_class = AccountingExportSerializer | ||
queryset = AccountingExport.objects.all().order_by("-updated_at") | ||
filter_backends = (DjangoFilterBackend,) | ||
filterset_fields = {"type": {"in"}, "updated_at": {"lte", "gte"}, "id": {"in"}, "status": {"in"}} | ||
|
||
|
||
class ErrorsView(LookupFieldMixin, generics.ListAPIView): | ||
serializer_class = ErrorSerializer | ||
queryset = Error.objects.all() | ||
filter_backends = (DjangoFilterBackend,) | ||
filterset_fields = {"type": {"exact"}, "is_resolved": {"exact"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.