Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,23 @@ def update_workspace_name(workspace_id: int, access_token: str) -> None:

except Exception as e:
logger.exception("Error updating workspace name for workspace_id: %s | Error: %s", workspace_id, str(e))


def sync_org_settings(workspace_id: int) -> None:
"""
Fetch and store org settings for a workspace
:param workspace_id: Workspace ID
:return: None
"""
try:
fyle_credential = FyleCredential.objects.get(workspace_id=workspace_id)
platform = PlatformConnector(fyle_credential)
org_settings = platform.org_settings.get()

workspace = Workspace.objects.get(id=workspace_id)
workspace.org_settings = {
'regional_settings': org_settings.get('regional_settings', {})
}
workspace.save(update_fields=['org_settings', 'updated_at'])
except Exception as e:
logger.error('Error fetching org settings for workspace %s: %s', workspace_id, str(e))
4 changes: 3 additions & 1 deletion apps/workspaces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from apps.fyle.helpers import get_cluster_domain
from apps.fyle.models import ExpenseGroupSettings
from apps.workspaces.actions import export_to_intacct
from apps.workspaces.tasks import patch_integration_settings
from apps.workspaces.tasks import patch_integration_settings, sync_org_settings
from apps.sage_intacct.models import SageIntacctAttributesCount
from apps.sage_intacct.helpers import get_sage_intacct_connection
from apps.sage_intacct.enums import SageIntacctRestConnectionTypeEnum
Expand Down Expand Up @@ -162,6 +162,8 @@ def post(self, request: Request) -> Response:
cluster_domain=cluster_domain
)

sync_org_settings(workspace_id=workspace.id)

return Response(
data=WorkspaceSerializer(workspace).data,
status=status.HTTP_200_OK
Expand Down
33 changes: 33 additions & 0 deletions tests/test_workspaces/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
post_to_integration_settings,
run_sync_schedule,
schedule_sync,
sync_org_settings,
trigger_email_notification,
update_workspace_name,
)
Expand Down Expand Up @@ -824,3 +825,35 @@ def test_update_workspace_name_invalid_token(db, mocker):
side_effect=Exception('General error')
)
update_workspace_name(1, 'Bearer access_token')


def test_sync_org_settings(db, mocker):
"""
Test sync org settings
"""
workspace_id = 1
workspace = Workspace.objects.get(id=workspace_id)
workspace.org_settings = {}
workspace.save()

mock_platform = mocker.patch('apps.workspaces.tasks.PlatformConnector')
mock_platform.return_value.org_settings.get.return_value = {
'regional_settings': {
'locale': {
'date_format': 'DD/MM/YYYY',
'timezone': 'Asia/Kolkata'
}
}
}

sync_org_settings(workspace_id=workspace_id)

workspace.refresh_from_db()
assert workspace.org_settings == {
'regional_settings': {
'locale': {
'date_format': 'DD/MM/YYYY',
'timezone': 'Asia/Kolkata'
}
}
}
Loading