File tree Expand file tree Collapse file tree 3 files changed +56
-1
lines changed
Expand file tree Collapse file tree 3 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -402,3 +402,23 @@ def update_workspace_name(workspace_id: int, access_token: str) -> None:
402402
403403 except Exception as e :
404404 logger .exception ("Error updating workspace name for workspace_id: %s | Error: %s" , workspace_id , str (e ))
405+
406+
407+ def sync_org_settings (workspace_id : int ) -> None :
408+ """
409+ Fetch and store org settings for a workspace
410+ :param workspace_id: Workspace ID
411+ :return: None
412+ """
413+ try :
414+ fyle_credential = FyleCredential .objects .get (workspace_id = workspace_id )
415+ platform = PlatformConnector (fyle_credential )
416+ org_settings = platform .org_settings .get ()
417+
418+ workspace = Workspace .objects .get (id = workspace_id )
419+ workspace .org_settings = {
420+ 'regional_settings' : org_settings .get ('regional_settings' , {})
421+ }
422+ workspace .save (update_fields = ['org_settings' , 'updated_at' ])
423+ except Exception as e :
424+ logger .error ('Error fetching org settings for workspace %s: %s' , workspace_id , str (e ))
Original file line number Diff line number Diff line change 3434from apps .fyle .helpers import get_cluster_domain
3535from apps .fyle .models import ExpenseGroupSettings
3636from apps .workspaces .actions import export_to_intacct
37- from apps .workspaces .tasks import patch_integration_settings
37+ from apps .workspaces .tasks import patch_integration_settings , sync_org_settings
3838from apps .sage_intacct .models import SageIntacctAttributesCount
3939from apps .sage_intacct .helpers import get_sage_intacct_connection
4040from apps .sage_intacct .enums import SageIntacctRestConnectionTypeEnum
@@ -162,6 +162,8 @@ def post(self, request: Request) -> Response:
162162 cluster_domain = cluster_domain
163163 )
164164
165+ sync_org_settings (workspace_id = workspace .id )
166+
165167 return Response (
166168 data = WorkspaceSerializer (workspace ).data ,
167169 status = status .HTTP_200_OK
Original file line number Diff line number Diff line change 2323 post_to_integration_settings ,
2424 run_sync_schedule ,
2525 schedule_sync ,
26+ sync_org_settings ,
2627 trigger_email_notification ,
2728 update_workspace_name ,
2829)
@@ -824,3 +825,35 @@ def test_update_workspace_name_invalid_token(db, mocker):
824825 side_effect = Exception ('General error' )
825826 )
826827 update_workspace_name (1 , 'Bearer access_token' )
828+
829+
830+ def test_sync_org_settings (db , mocker ):
831+ """
832+ Test sync org settings
833+ """
834+ workspace_id = 1
835+ workspace = Workspace .objects .get (id = workspace_id )
836+ workspace .org_settings = {}
837+ workspace .save ()
838+
839+ mock_platform = mocker .patch ('apps.workspaces.tasks.PlatformConnector' )
840+ mock_platform .return_value .org_settings .get .return_value = {
841+ 'regional_settings' : {
842+ 'locale' : {
843+ 'date_format' : 'DD/MM/YYYY' ,
844+ 'timezone' : 'Asia/Kolkata'
845+ }
846+ }
847+ }
848+
849+ sync_org_settings (workspace_id = workspace_id )
850+
851+ workspace .refresh_from_db ()
852+ assert workspace .org_settings == {
853+ 'regional_settings' : {
854+ 'locale' : {
855+ 'date_format' : 'DD/MM/YYYY' ,
856+ 'timezone' : 'Asia/Kolkata'
857+ }
858+ }
859+ }
You can’t perform that action at this time.
0 commit comments