Skip to content

Commit

Permalink
Fix: Import bugs (#46)
Browse files Browse the repository at this point in the history
* Fix: Import bugs

* requirements updated

* Comments fixed
  • Loading branch information
ruuushhh authored Dec 15, 2023
1 parent d25469e commit befe905
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apps/business_central/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _sync_data(self, data, attribute_type, display_name, workspace_id, field_nam
destination_attributes = []
for item in data:
detail = {field: item[field] for field in field_names}
if (attribute_type == 'EMPLOYEE' and item['status'] == 'Active') or attribute_type == 'LOCATION' or item['blocked'] != True:
if (attribute_type == 'EMPLOYEE' and item.get('status') == 'Active') or (attribute_type == 'LOCATION') or (item.get('blocked') and item['blocked'] != True):
active = True
else:
active = False
Expand Down Expand Up @@ -115,7 +115,7 @@ def sync_employees(self):
"""
workspace = Workspace.objects.get(id=self.workspace_id)
self.connection.company_id = workspace.business_central_company_id
field_names = ['email', 'email', 'personalEmail', 'lastModifiedDateTime']
field_names = ['email', 'personalEmail', 'lastModifiedDateTime']

employees = self.connection.employees.get_all()
self._sync_data(employees, 'EMPLOYEE', 'employee', self.workspace_id, field_names)
Expand Down
25 changes: 24 additions & 1 deletion apps/mappings/imports/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime, timedelta, timezone
from typing import List

from fyle_accounting_mappings.models import DestinationAttribute, ExpenseAttribute, Mapping
from fyle_accounting_mappings.models import CategoryMapping, DestinationAttribute, ExpenseAttribute, Mapping
from fyle_integrations_platform_connector import PlatformConnector

from apps.accounting_exports.models import Error
Expand Down Expand Up @@ -85,6 +85,29 @@ def remove_duplicate_attributes(self, destination_attributes: List[DestinationAt

return unique_attributes

def __get_mapped_attributes_ids(self, errored_attribute_ids: List[int]):
"""
Get mapped attributes ids
:param errored_attribute_ids: list[int]
:return: list[int]
"""
mapped_attribute_ids = []
if self.source_field == "CATEGORY":
params = {
'source_category_id__in': errored_attribute_ids,
}

if self.destination_field == 'EXPENSE_TYPE':
params['destination_expense_head_id__isnull'] = False
else:
params['destination_account_id__isnull'] = False

mapped_attribute_ids: List[int] = CategoryMapping.objects.filter(
**params
).values_list('source_category_id', flat=True)

return mapped_attribute_ids

def resolve_expense_attribute_errors(self):
"""
Resolve Expense Attribute Errors
Expand Down
40 changes: 40 additions & 0 deletions apps/workspaces/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 3.1.14 on 2023-10-20 14:00

import apps.workspaces.models
from django.conf import settings
from django.db import migrations, models
import ms_business_central_api.models.fields


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Workspace',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', ms_business_central_api.models.fields.StringNotNullField(help_text='Name of the workspace', max_length=255)),
('org_id', models.CharField(help_text='org id', max_length=255, unique=True)),
('reimbursable_last_synced_at', ms_business_central_api.models.fields.CustomDateTimeField(help_text='Datetime when expenses were pulled last', null=True)),
('credit_card_last_synced_at', ms_business_central_api.models.fields.CustomDateTimeField(help_text='Datetime when ccc expenses were pulled last', null=True)),
('source_synced_at', ms_business_central_api.models.fields.CustomDateTimeField(help_text='Datetime when source dimensions were pulled', null=True)),
('destination_synced_at', ms_business_central_api.models.fields.CustomDateTimeField(help_text='Datetime when destination dimensions were pulled', null=True)),
('onboarding_state', ms_business_central_api.models.fields.StringOptionsField(choices=[('CONNECTION', 'CONNECTION'), ('EXPORT_SETTINGS', 'EXPORT_SETTINGS'), ('IMPORT_SETTINGS', 'IMPORT_SETTINGS'), ('ADVANCED_CONFIGURATION', 'ADVANCED_CONFIGURATION'), ('COMPLETE', 'COMPLETE')], default=apps.workspaces.models.get_default_onboarding_state, help_text='Onboarding status of the workspace', max_length=50, null=True)),
('ms_business_central_accounts_last_synced_at', ms_business_central_api.models.fields.CustomDateTimeField(help_text='Business Central accounts last synced at time', null=True)),
('business_central_company_name', ms_business_central_api.models.fields.StringNullField(help_text='Business Central Company Name', max_length=255, null=True)),
('business_central_company_id', ms_business_central_api.models.fields.StringNullField(help_text='Business Central Company Id', max_length=255, null=True)),
('created_at', models.DateTimeField(auto_now_add=True, help_text='Created at datetime')),
('updated_at', models.DateTimeField(auto_now=True, help_text='Updated at datetime')),
('user', models.ManyToManyField(help_text='Reference to users table', to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'workspaces',
},
),
]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ gevent==23.9.1
gunicorn==20.1.0

# Platform SDK
fyle==0.35.0
fyle==0.36.0

# Business central sdk
ms-dynamics-business-central-sdk==1.2.0
ms-dynamics-business-central-sdk==1.3.1

# Reusable Fyle Packages
fyle-rest-auth==1.5.0
Expand Down

0 comments on commit befe905

Please sign in to comment.