-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V2 map employees api #430
Merged
Merged
V2 map employees api #430
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5c31b3f
onboarding state implementation
798e2bc
tests migrations
NileshPant1999 fdd7a9e
added onboarding state
609594d
changed comment
d15a8f5
added subsidiary state to onboarding state
ec4f4d1
changed script to add subsidiary state and fixed some bug
c64ff14
Merge branch 'master' into onboarding-state
67ddf59
bug fix
b9e5d3b
Merge branch 'master' into onboarding-state
Ashutosh619-sudo 3bce538
state change on connection and subsidiary change
ac37706
Merge branch 'master' into onboarding-state-sub
4d291b3
map employees v2 api
173c5bb
map_employees typos
932cf3f
bug fix
8f6cbb7
Merge branch 'master' into v2-api
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,55 @@ | ||
from apps.workspaces.apis.map_employees.triggers import MapEmplyeesTriggers | ||
from apps.workspaces.models import Configuration, Workspace | ||
from rest_framework import serializers | ||
|
||
|
||
class ConfigurationSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Configuration | ||
fields = ['employee_field_mapping', 'auto_map_employees'] | ||
|
||
|
||
class MapEmployeesSerializer(serializers.ModelSerializer): | ||
|
||
configuration = ConfigurationSerializer() | ||
workspace_id = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = Workspace | ||
fields = ['configuration', 'workspace_id'] | ||
read_only_fields = ['workspace_id'] | ||
|
||
def get_workspace_id(self, instance): | ||
return instance.id | ||
|
||
def update(self, instance, validated_data): | ||
|
||
workspace_id = instance.id | ||
configuration = validated_data.pop('configuration') | ||
|
||
configuration_instance = Configuration.objects.filter(workspace_id=workspace_id).first() | ||
|
||
if configuration and (configuration_instance.employee_field_mapping != configuration['employee_field_mapping']): | ||
configuration_instance.reimbursable_expenses_object = None | ||
configuration_instance.save() | ||
|
||
configuration_instance, _ = Configuration.objects.update_or_create( | ||
workspace_id=workspace_id, defaults={'employee_field_mapping': configuration['employee_field_mapping'], 'auto_map_employees': configuration['auto_map_employees']} | ||
) | ||
|
||
MapEmplyeesTriggers.run_workspace_general_settings_triggers(configuration=configuration_instance) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. run_configurations_triggers |
||
|
||
if instance.onboarding_state == 'MAP_EMPLOYEES': | ||
instance.onboarding_state = 'EXPORT_SETTINGS' | ||
instance.save() | ||
|
||
return instance | ||
|
||
def validate(self,data): | ||
if not data.get('configuration').get('employee_field_mapping'): | ||
raise serializers.ValidationError('employee_field_mapping field is required') | ||
|
||
if data.get('configuration').get('auto_map_employees') and data.get('configuration').get('auto_map_employees') not in ['EMAIL', 'NAME', 'EMPLOYEE_CODE']: | ||
raise serializers.ValidationError('auto_map_employees can have only EMAIL / NAME / EMPLOYEE_CODE') | ||
|
||
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,10 @@ | ||
from apps.mappings.tasks import schedule_auto_map_employees | ||
from apps.workspaces.models import Configuration | ||
|
||
|
||
class MapEmplyeesTriggers: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MapEmployeesTriggers |
||
|
||
@staticmethod | ||
def run_workspace_general_settings_triggers(configuration: Configuration): | ||
|
||
schedule_auto_map_employees(configuration.auto_map_employees, configuration.workspace.id) |
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.apis.map_employees.serializers import MapEmployeesSerializer | ||
from apps.workspaces.models import Workspace | ||
|
||
|
||
class MapEmployeesView(generics.RetrieveUpdateAPIView): | ||
|
||
serializer_class = MapEmployeesSerializer | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
|
||
from apps.workspaces.apis.map_employees.views import MapEmployeesView | ||
|
||
|
||
urlpatterns = [ | ||
path('<int:workspace_id>/map_employees/', MapEmployeesView.as_view()), | ||
] |
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,18 @@ | ||
# Generated by Django 3.1.14 on 2023-10-19 10:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('workspaces', '0034_auto_20231012_0750'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='configuration', | ||
name='reimbursable_expenses_object', | ||
field=models.CharField(choices=[('EXPENSE REPORT', 'EXPENSE REPORT'), ('JOURNAL ENTRY', 'JOURNAL ENTRY'), ('BILL', 'BILL')], help_text='Reimbursable Expenses type', max_length=50, null=True), | ||
), | ||
] |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this block required?