-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* onboarding state implementation * tests migrations * added onboarding state * changed comment * added subsidiary state to onboarding state * changed script to add subsidiary state and fixed some bug * bug fix * state change on connection and subsidiary change * map employees v2 api * map_employees typos * bug fix * export setting changes * export settings V2 api * added test for export settings api * resolved comments * import settings v2 api * test added for import settings v2 api * advanced settings v2 api * advanced settings v2 api with test case * resolved comments * First schedule should be triggered after interval hours and Handle Admin GET in a safer way (#437) * First schedule should be triggered after interval hours * Handle Admin GET in a safer way * Making reimbursable expense object nullable and checking edge cases (#438) * Making reimbursbale expense object nullable and checking edge cases for the same * comment resolved * resolving comments * all comment resolved * added code in test for the changes * added test code for the changes --------- Co-authored-by: Ashutosh619-sudo <[email protected]> --------- Co-authored-by: Ashutosh619-sudo <[email protected]> * changes as per comments --------- Co-authored-by: Ashutosh619-sudo <[email protected]> Co-authored-by: Nilesh Pant <[email protected]>
- Loading branch information
1 parent
d26f22e
commit 64d953d
Showing
17 changed files
with
366 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
from rest_framework import serializers | ||
|
||
from apps.workspaces.models import Configuration, Workspace, WorkspaceSchedule | ||
from apps.mappings.models import GeneralMapping | ||
from apps.workspaces.apis.advanced_settings.triggers import AdvancedConfigurationsTriggers | ||
|
||
|
||
class ReadWriteSerializerMethodField(serializers.SerializerMethodField): | ||
""" | ||
Serializer Method Field to Read and Write from values | ||
Inherits serializers.SerializerMethodField | ||
""" | ||
|
||
def __init__(self, method_name=None, **kwargs): | ||
self.method_name = method_name | ||
kwargs['source'] = '*' | ||
super(serializers.SerializerMethodField, self).__init__(**kwargs) | ||
|
||
def to_internal_value(self, data): | ||
return {self.field_name: data} | ||
|
||
|
||
class ConfigurationSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = Configuration | ||
fields = [ | ||
'change_accounting_period', | ||
'sync_fyle_to_netsuite_payments', | ||
'sync_netsuite_to_fyle_payments', | ||
'auto_create_destination_entity', | ||
'memo_structure' | ||
] | ||
|
||
|
||
class GeneralMappingsSerializer(serializers.ModelSerializer): | ||
|
||
netsuite_location = ReadWriteSerializerMethodField() | ||
netsuite_location_level = ReadWriteSerializerMethodField() | ||
department_level = ReadWriteSerializerMethodField() | ||
use_employee_location = ReadWriteSerializerMethodField() | ||
use_employee_department = ReadWriteSerializerMethodField() | ||
use_employee_class = ReadWriteSerializerMethodField() | ||
|
||
class Meta: | ||
model = GeneralMapping | ||
fields = [ | ||
'netsuite_location', | ||
'netsuite_location_level', | ||
'department_level', | ||
'use_employee_location', | ||
'use_employee_department', | ||
'use_employee_class' | ||
] | ||
|
||
|
||
def get_netsuite_location(self, instance: GeneralMapping): | ||
return { | ||
'name': instance.location_name, | ||
'id': instance.location_id | ||
} | ||
|
||
def get_netsuite_location_level(self, instance: GeneralMapping): | ||
return instance.location_level | ||
|
||
def get_department_level(self, instance: GeneralMapping): | ||
return instance.department_level | ||
|
||
def get_use_employee_location(self, instance: GeneralMapping): | ||
return instance.use_employee_location | ||
|
||
def get_use_employee_department(self, instance: GeneralMapping): | ||
return instance.use_employee_department | ||
|
||
def get_use_employee_class(self, instance: GeneralMapping): | ||
return instance.use_employee_class | ||
|
||
class WorkspaceSchedulesSerializer(serializers.ModelSerializer): | ||
emails_selected = serializers.ListField(allow_null=True, required=False) | ||
|
||
class Meta: | ||
model = WorkspaceSchedule | ||
fields = [ | ||
'enabled', | ||
'interval_hours', | ||
'additional_email_options', | ||
'emails_selected' | ||
] | ||
|
||
class AdvancedSettingsSerializer(serializers.ModelSerializer): | ||
""" | ||
Serializer for the Advanced Configurations Form/API | ||
""" | ||
configuration = ConfigurationSerializer() | ||
general_mappings = GeneralMappingsSerializer() | ||
workspace_schedules = WorkspaceSchedulesSerializer() | ||
workspace_id = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = Workspace | ||
fields = [ | ||
'configuration', | ||
'general_mappings', | ||
'workspace_schedules', | ||
'workspace_id' | ||
] | ||
read_only_fields = ['workspace_id'] | ||
|
||
|
||
def get_workspace_id(self, instance): | ||
return instance.id | ||
|
||
def update(self, instance, validated): | ||
configurations = validated.pop('configuration') | ||
general_mappings = validated.pop('general_mappings') | ||
workspace_schedules = validated.pop('workspace_schedules') | ||
|
||
configuration_instance, _ = Configuration.objects.update_or_create( | ||
workspace=instance, | ||
defaults={ | ||
'sync_fyle_to_netsuite_payments': configurations.get('sync_fyle_to_netsuite_payments'), | ||
'sync_netsuite_to_fyle_payments': configurations.get('sync_netsuite_to_fyle_payments'), | ||
'auto_create_destination_entity': configurations.get('auto_create_destination_entity'), | ||
'change_accounting_period': configurations.get('change_accounting_period'), | ||
'memo_structure': configurations.get('memo_structure') | ||
} | ||
) | ||
|
||
GeneralMapping.objects.update_or_create( | ||
workspace=instance, | ||
defaults={ | ||
'netsuite_location': general_mappings.get('netsuite_location'), | ||
'netsuite_location_level': general_mappings.get('netsuite_location_level'), | ||
'department_level': general_mappings.get('department_level'), | ||
'use_employee_location': general_mappings.get('use_employee_location'), | ||
'use_employee_department': general_mappings.get('use_employee_department'), | ||
'use_employee_class': general_mappings.get('use_employee_class') | ||
} | ||
) | ||
|
||
AdvancedConfigurationsTriggers.run_post_configurations_triggers(instance.id, workspace_schedule=workspace_schedules, configuration=configuration_instance) | ||
|
||
if instance.onboarding_state == 'ADVANCED_CONFIGURATION': | ||
instance.onboarding_state = 'COMPLETE' | ||
instance.save() | ||
|
||
return instance | ||
|
||
def validate(self, data): | ||
if not data.get('configuration'): | ||
raise serializers.ValidationError('Configurations are required') | ||
|
||
if not data.get('general_mappings'): | ||
raise serializers.ValidationError('General mappings are required') | ||
|
||
if not data.get('workspace_schedules'): | ||
raise serializers.ValidationError('Workspace Schedules are required') | ||
|
||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from apps.netsuite.helpers import schedule_payment_sync | ||
from apps.workspaces.models import Configuration, WorkspaceSchedule | ||
from apps.workspaces.tasks import schedule_sync | ||
|
||
|
||
class AdvancedConfigurationsTriggers: | ||
""" | ||
Class containing all triggers for advanced_configurations | ||
""" | ||
@staticmethod | ||
def run_post_configurations_triggers(workspace_id, workspace_schedule: WorkspaceSchedule, configuration: Configuration): | ||
""" | ||
Run workspace general settings triggers | ||
""" | ||
|
||
schedule_sync( | ||
workspace_id=workspace_id, | ||
schedule_enabled=workspace_schedule.get('enabled'), | ||
hours=workspace_schedule.get('interval_hours'), | ||
email_added=workspace_schedule.get('additional_email_options'), | ||
emails_selected=workspace_schedule.get('emails_selected') | ||
) | ||
|
||
schedule_payment_sync(configuration=configuration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from rest_framework import generics | ||
|
||
from apps.workspaces.models import Workspace | ||
from apps.workspaces.apis.advanced_settings.serializers import AdvancedSettingsSerializer | ||
|
||
|
||
class AdvancedSettingsView(generics.RetrieveUpdateAPIView): | ||
serializer_class = AdvancedSettingsSerializer | ||
|
||
def get_object(self): | ||
return Workspace.objects.filter(id=self.kwargs['workspace_id']).first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.1.14 on 2023-10-27 07:09 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('workspaces', '0035_auto_20231019_1025'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='workspaceschedule', | ||
name='workspace', | ||
field=models.OneToOneField(help_text='Reference to Workspace model', on_delete=django.db.models.deletion.PROTECT, related_name='workspace_schedules', to='workspaces.workspace'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.