-
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 Export setting api #433
Merged
Merged
Changes from all commits
Commits
Show all changes
21 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
5972c5c
export setting changes
cfb791b
export settings V2 api
02095ab
Merge branch 'master' into v2-api
Ashutosh619-sudo e9a0b17
added test for export settings api
8016d3d
Merge branch 'v2-api' of https://github.com/fylein/fyle-netsuite-api …
aa56ca4
resolved comments
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,4 +159,4 @@ cache.db-journal | |
test_scripts/ | ||
fyle_accounting_mappings/ | ||
fyle_integrations_platform_connector/ | ||
fyle/ | ||
./fyle |
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,20 @@ | ||
# Generated by Django 3.1.14 on 2023-10-25 09:13 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('workspaces', '0035_auto_20231019_1025'), | ||
('fyle', '0025_auto_20230622_0516'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='expensegroupsettings', | ||
name='workspace', | ||
field=models.OneToOneField(help_text='To which workspace this expense group setting belongs to', on_delete=django.db.models.deletion.PROTECT, related_name='expense_group_settings', 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 3.1.14 on 2023-10-25 09:15 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('workspaces', '0035_auto_20231019_1025'), | ||
('mappings', '0009_auto_20211022_0702'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='generalmapping', | ||
name='workspace', | ||
field=models.OneToOneField(help_text='Reference to Workspace model', on_delete=django.db.models.deletion.PROTECT, related_name='general_mappings', 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
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,173 @@ | ||
from apps.fyle.models import ExpenseGroupSettings | ||
from apps.mappings.models import GeneralMapping | ||
from apps.workspaces.models import Configuration, Workspace | ||
from rest_framework import serializers | ||
|
||
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 = [ | ||
'reimbursable_expenses_object', | ||
'corporate_credit_card_expenses_object', | ||
'is_simplify_report_closure_enabled', | ||
] | ||
|
||
read_only_fields = ['is_simplify_report_closure_enabled'] | ||
|
||
class GeneralMappingsSerializer(serializers.ModelSerializer): | ||
reimbursable_account = ReadWriteSerializerMethodField() | ||
default_ccc_account = ReadWriteSerializerMethodField() | ||
accounts_payable = ReadWriteSerializerMethodField() | ||
default_ccc_vendor = ReadWriteSerializerMethodField() | ||
|
||
class Meta: | ||
model = GeneralMapping | ||
fields = [ | ||
'reimbursable_account', | ||
'default_ccc_account', | ||
'accounts_payable', | ||
'default_ccc_vendor', | ||
] | ||
|
||
def get_reimbursable_account(self, instance: GeneralMapping): | ||
return { | ||
'id': instance.reimbursable_account_id, | ||
'name': instance.reimbursable_account_name | ||
} | ||
|
||
def get_default_ccc_account(self, instance: GeneralMapping): | ||
return { | ||
'id': instance.default_ccc_account_id, | ||
'name': instance.default_ccc_account_name | ||
} | ||
|
||
def get_accounts_payable(self, instance: GeneralMapping): | ||
return { | ||
'id': instance.accounts_payable_id, | ||
'name': instance.accounts_payable_name | ||
} | ||
|
||
def get_default_ccc_vendor(self, instance: GeneralMapping): | ||
return { | ||
'id': instance.default_ccc_vendor_id, | ||
'name': instance.default_ccc_vendor_name | ||
} | ||
|
||
class ExpenseGroupSettingsSerializer(serializers.ModelSerializer): | ||
reimbursable_expense_group_fields = serializers.ListField(allow_null=True, required=False) | ||
reimbursable_export_date_type = serializers.CharField(allow_null=True, allow_blank=True, required=False) | ||
expense_state = serializers.CharField(allow_null=True, allow_blank=True, required=False) | ||
corporate_credit_card_expense_group_fields = serializers.ListField(allow_null=True, required=False) | ||
ccc_export_date_type = serializers.CharField(allow_null=True, allow_blank=True, required=False) | ||
ccc_expense_state = serializers.CharField(allow_null=True, allow_blank=True, required=False) | ||
|
||
class Meta: | ||
model = ExpenseGroupSettings | ||
fields = [ | ||
'reimbursable_expense_group_fields', | ||
'reimbursable_export_date_type', | ||
'expense_state', | ||
'corporate_credit_card_expense_group_fields', | ||
'ccc_export_date_type', | ||
'ccc_expense_state' | ||
] | ||
|
||
|
||
class ExportSettingsSerializer(serializers.ModelSerializer): | ||
expense_group_settings = ExpenseGroupSettingsSerializer() | ||
configuration = ConfigurationSerializer() | ||
general_mappings = GeneralMappingsSerializer() | ||
workspace_id = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = Workspace | ||
fields = [ | ||
'expense_group_settings', | ||
'configuration', | ||
'general_mappings', | ||
'workspace_id' | ||
] | ||
read_only_fields = ['workspace_id'] | ||
|
||
|
||
def get_workspace_id(self, instance): | ||
return instance.id | ||
|
||
def update(self, instance: Workspace, validated_data): | ||
|
||
configurations = validated_data.pop('configuration') | ||
expense_group_settings = validated_data.pop('expense_group_settings') | ||
general_mappings = validated_data.pop('general_mappings') | ||
workspace_id = instance.id | ||
|
||
Configuration.objects.update_or_create( | ||
workspace_id=workspace_id, | ||
defaults={ | ||
'reimbursable_expenses_object': configurations['reimbursable_expenses_object'], | ||
'corporate_credit_card_expenses_object': configurations['corporate_credit_card_expenses_object'], | ||
} | ||
) | ||
|
||
if not expense_group_settings['reimbursable_expense_group_fields']: | ||
expense_group_settings['reimbursable_expense_group_fields'] = ['employee_email', 'report_id', 'fund_source', 'claim_number'] | ||
|
||
if not expense_group_settings['corporate_credit_card_expense_group_fields']: | ||
expense_group_settings['corporate_credit_card_expense_group_fields'] = ['employee_email', 'report_id', 'fund_source', 'claim_number'] | ||
|
||
if not expense_group_settings['reimbursable_export_date_type']: | ||
expense_group_settings['reimbursable_export_date_type'] = 'current_date' | ||
|
||
if not expense_group_settings['ccc_export_date_type']: | ||
expense_group_settings['ccc_export_date_type'] = 'current_date' | ||
|
||
ExpenseGroupSettings.update_expense_group_settings(expense_group_settings, workspace_id=workspace_id) | ||
|
||
GeneralMapping.objects.update_or_create( | ||
workspace = instance, | ||
defaults={ | ||
'reimbursable_account_id': general_mappings['reimbursable_account']['id'], | ||
'reimbursable_account_name': general_mappings['reimbursable_account']['name'], | ||
'default_ccc_account_id': general_mappings['default_ccc_account']['id'], | ||
'default_ccc_account_name': general_mappings['default_ccc_account']['name'], | ||
'accounts_payable_id': general_mappings['accounts_payable']['id'], | ||
'accounts_payable_name': general_mappings['accounts_payable']['name'], | ||
'default_ccc_vendor_id': general_mappings['default_ccc_vendor']['id'], | ||
'default_ccc_vendor_name': general_mappings['default_ccc_vendor']['name'] | ||
} | ||
) | ||
|
||
if instance.onboarding_state == 'EXPORT_SETTINGS': | ||
instance.onboarding_state = 'IMPORT_SETTINGS' | ||
instance.save() | ||
|
||
return instance | ||
|
||
def validate(self, data): | ||
|
||
if not data.get('expense_group_settings'): | ||
raise serializers.ValidationError('Expense group settings are required') | ||
|
||
if not data.get('configuration'): | ||
raise serializers.ValidationError('Configurations settings are required') | ||
|
||
if not data.get('general_mappings'): | ||
raise serializers.ValidationError('General mappings 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,12 @@ | ||
from rest_framework import generics | ||
|
||
from apps.workspaces.models import Workspace | ||
|
||
from apps.workspaces.apis.export_settings.serializers import ExportSettingsSerializer | ||
|
||
|
||
class ExportSettingsView(generics.RetrieveUpdateAPIView): | ||
serializer_class = ExportSettingsSerializer | ||
|
||
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from django.urls import path | ||
|
||
from apps.workspaces.apis.map_employees.views import MapEmployeesView | ||
from apps.workspaces.apis.export_settings.views import ExportSettingsView | ||
|
||
|
||
urlpatterns = [ | ||
path('<int:workspace_id>/map_employees/', MapEmployeesView.as_view()), | ||
path('<int:workspace_id>/map_employees/', MapEmployeesView.as_view(), name='map-employees'), | ||
path('<int:workspace_id>/export_settings/', ExportSettingsView.as_view(), name='export-settings'), | ||
] |
Empty file.
Empty file.
Oops, something went wrong.
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.
can we add linespaces between each function