diff --git a/apps/business_central/utils.py b/apps/business_central/utils.py index 0fd0acf..ecdb99f 100644 --- a/apps/business_central/utils.py +++ b/apps/business_central/utils.py @@ -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 @@ -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) diff --git a/apps/mappings/imports/modules/base.py b/apps/mappings/imports/modules/base.py index 82af8bf..3a72c89 100644 --- a/apps/mappings/imports/modules/base.py +++ b/apps/mappings/imports/modules/base.py @@ -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 @@ -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 diff --git a/apps/workspaces/migrations/0001_initial.py b/apps/workspaces/migrations/0001_initial.py new file mode 100644 index 0000000..c10f8b2 --- /dev/null +++ b/apps/workspaces/migrations/0001_initial.py @@ -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', + }, + ), + ] diff --git a/requirements.txt b/requirements.txt index 3c4ec7f..e447359 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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