Skip to content

Commit

Permalink
Imports Folder Structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ruuushhh committed Nov 27, 2023
1 parent b09d0bc commit 7855b5b
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 6 deletions.
45 changes: 45 additions & 0 deletions apps/mappings/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FYLE_EXPENSE_SYSTEM_FIELDS = [
'employee id',
'organisation name',
'employee name',
'employee email',
'expense date',
'expense id',
'report id',
'employee id',
'department',
'state',
'reporter',
'report',
'purpose',
'vendor',
'category',
'category code',
'mileage distance',
'mileage unit',
'flight from city',
'flight to city',
'flight from date',
'flight to date',
'flight from class',
'flight to class',
'hotel checkin',
'hotel checkout',
'hotel location',
'hotel breakfast',
'currency',
'amount',
'foreign currency',
'foreign amount',
'tax',
'approver',
'project',
'billable',
'cost center',
'cost center code',
'approved on',
'reimbursable',
'receipts',
'paid date',
'expense created date'
]
Empty file added apps/mappings/exceptions.py
Empty file.
Empty file added apps/mappings/imports/queues.py
Empty file.
Empty file.
Empty file added apps/mappings/imports/tasks.py
Empty file.
35 changes: 35 additions & 0 deletions apps/mappings/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.db import models

from apps.workspaces.models import BaseForeignWorkspaceModel
from ms_business_central_api.models.fields import (
CustomDateTimeField,
CustomJsonField,
IntegerNotNullField,
StringNotNullField,
StringOptionsField,
)

IMPORT_STATUS_CHOICES = (
('FATAL', 'FATAL'),
('COMPLETE', 'COMPLETE'),
('IN_PROGRESS', 'IN_PROGRESS'),
('FAILED', 'FAILED')
)


class ImportLog(BaseForeignWorkspaceModel):
"""
Table to store import logs
"""

id = models.AutoField(auto_created=True, primary_key=True, verbose_name='ID', serialize=False)
attribute_type = StringNotNullField(max_length=150, help_text='Attribute type')
status = StringOptionsField(help_text='Status', choices=IMPORT_STATUS_CHOICES)
error_log = CustomJsonField(help_text='Emails Selected For Email Notification')
total_batches_count = IntegerNotNullField(help_text='Queued batches', default=0)
processed_batches_count = IntegerNotNullField(help_text='Processed batches', default=0)
last_successful_run_at = CustomDateTimeField(help_text='Last successful run')

class Meta:
db_table = 'import_logs'
unique_together = ('workspace', 'attribute_type')
Empty file added apps/mappings/signals.py
Empty file.
22 changes: 22 additions & 0 deletions apps/mappings/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from apps.business_central.utils import BusinessCentralConnector
from apps.workspaces.models import BusinessCentralCredentials


def sync_business_central_attributes(business_central_attribute_type: str, workspace_id: int):
business_central_credentials: BusinessCentralCredentials = BusinessCentralCredentials.objects.get(workspace_id=workspace_id)

business_central_connection = BusinessCentralConnector(
credentials_object=business_central_credentials,
workspace_id=workspace_id
)

sync_functions = {
'ACCOUNT': business_central_connection.sync_accounts,
'COMPANY': business_central_connection.sync_companies,
'LOCATION': business_central_connection.sync_locations,
'EMPLOYEE': business_central_connection.sync_employees,
'VENDOR': business_central_connection.sync_vendors,
}

sync_function = sync_functions[business_central_attribute_type]
sync_function()
20 changes: 20 additions & 0 deletions apps/mappings/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""ms_business_central_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 include, path

urlpatterns = [
path('', include('fyle_accounting_mappings.urls'))
]
12 changes: 6 additions & 6 deletions apps/workspaces/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from django.urls import path, include
from django.urls import include, path

from apps.workspaces.views import (
ReadyView,
WorkspaceView,
AdvancedSettingView,
ConnectBusinessCentralView,
ExportSettingView,
ImportSettingView,
AdvancedSettingView,
ReadyView,
WorkspaceAdminsView,
ConnectBusinessCentralView
WorkspaceView,
)


workspace_app_paths = [
path('', WorkspaceView.as_view(), name='workspaces'),
path('ready/', ReadyView.as_view(), name='ready'),
Expand All @@ -26,6 +25,7 @@
path('<int:workspace_id>/accounting_exports/', include('apps.accounting_exports.urls')),
path('<int:workspace_id>/fyle/', include('apps.fyle.urls')),
path('<int:workspace_id>/business_central/', include('apps.business_central.urls')),
path('<int:workspace_id>/mappings/', include('apps.mappings.urls'))
]

urlpatterns = []
Expand Down

0 comments on commit 7855b5b

Please sign in to comment.