Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 committed Nov 22, 2024
2 parents 9e549bb + a2bb92a commit 50183d3
Show file tree
Hide file tree
Showing 22 changed files with 735 additions and 342 deletions.
18 changes: 18 additions & 0 deletions apps/fyle/migrations/0034_expense_is_posted_at_null.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2024-11-17 20:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('fyle', '0033_expense_paid_on_fyle'),
]

operations = [
migrations.AddField(
model_name='expense',
name='is_posted_at_null',
field=models.BooleanField(default=False, help_text='Flag check if posted at is null or not'),
),
]
2 changes: 2 additions & 0 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Expense(models.Model):
spent_at = models.DateTimeField(null=True, help_text='Expense spent at')
approved_at = models.DateTimeField(null=True, help_text='Expense approved at')
posted_at = models.DateTimeField(null=True, help_text='Date when the money is taken from the bank')
is_posted_at_null = models.BooleanField(default=False, help_text='Flag check if posted at is null or not')
expense_created_at = models.DateTimeField(help_text='Expense created at')
expense_updated_at = models.DateTimeField(help_text='Expense created at')
created_at = models.DateTimeField(auto_now_add=True, help_text='Created at')
Expand Down Expand Up @@ -175,6 +176,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id, skip_update: bool
'file_ids': expense['file_ids'],
'spent_at': expense['spent_at'],
'posted_at': expense['posted_at'],
'is_posted_at_null': expense['is_posted_at_null'],
'fund_source': SOURCE_ACCOUNT_MAP[expense['source_account_type']],
'verified_at': expense['verified_at'],
'custom_properties': expense['custom_properties'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2024-11-04 10:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mappings', '0014_auto_20240417_0807'),
]

operations = [
migrations.AddField(
model_name='generalmapping',
name='is_tax_balancing_enabled',
field=models.BooleanField(default=False, help_text='Is tax balancing enabled'),
),
]
1 change: 1 addition & 0 deletions apps/mappings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GeneralMapping(models.Model):
)

override_tax_details = models.BooleanField(default=False, help_text='Override tax details')
is_tax_balancing_enabled = models.BooleanField(default=False, help_text='Is tax balancing enabled')

workspace = models.OneToOneField(Workspace, on_delete=models.PROTECT, help_text='Reference to Workspace model', related_name='general_mappings')
created_at = models.DateTimeField(auto_now_add=True, help_text='Created at datetime')
Expand Down
474 changes: 235 additions & 239 deletions apps/netsuite/connector.py

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions apps/netsuite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,18 @@ def get_tax_group_mapping(lineitem: Expense = None, workspace_id: int = None):

def get_tax_item_id_or_none(expense_group: ExpenseGroup, general_mapping: GeneralMapping, lineitem: Expense = None):
tax_code = None
mapping = get_tax_group_mapping(lineitem, expense_group.workspace_id)
tax_setting: MappingSetting = MappingSetting.objects.filter(
workspace_id=expense_group.workspace_id,
destination_field='TAX_ITEM'
).first()

if tax_setting:
mapping = get_tax_group_mapping(lineitem, expense_group.workspace_id)

if mapping:
tax_code = mapping.destination.destination_id
else:
tax_code = general_mapping.default_tax_code_id
if mapping:
tax_code = mapping.destination.destination_id
else:
tax_code = general_mapping.default_tax_code_id

return tax_code

Expand Down
18 changes: 10 additions & 8 deletions apps/netsuite/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ def construct_payload_and_update_export(expense_id_receipt_url_map: dict, task_l
construct_lines = getattr(netsuite_connection, func)

# calling the target construct payload function with credit and debit
credit_line = construct_lines(export_line_items, credit='Credit', org_id=workspace.fyle_org_id)
credit_line = construct_lines(export_line_items, general_mappings, credit='Credit', org_id=workspace.fyle_org_id)
debit_line = construct_lines(
export_line_items, debit='Debit', attachment_links=expense_id_receipt_url_map,
export_line_items, general_mappings, debit='Debit', attachment_links=expense_id_receipt_url_map,
cluster_domain=cluster_domain, org_id=workspace.fyle_org_id
)
lines.extend(credit_line)
Expand All @@ -337,11 +337,11 @@ def construct_payload_and_update_export(expense_id_receipt_url_map: dict, task_l
elif task_log.type == 'CREATING_BILL':
construct_lines = getattr(netsuite_connection, func)
# calling the target construct payload function
expense_list, item_list = construct_lines(export_line_items, expense_id_receipt_url_map, cluster_domain, workspace.fyle_org_id, general_mappings.override_tax_details)
expense_list, item_list = construct_lines(export_line_items, expense_id_receipt_url_map, cluster_domain, workspace.fyle_org_id, general_mappings.override_tax_details, general_mappings)
else:
construct_lines = getattr(netsuite_connection, func)
# calling the target construct payload function
lines = construct_lines(export_line_items, expense_id_receipt_url_map, cluster_domain, workspace.fyle_org_id)
lines = construct_lines(export_line_items, general_mappings, expense_id_receipt_url_map, cluster_domain, workspace.fyle_org_id)

# final payload to be sent to netsuite, since this is an update operation, we need to pass the external id
if task_log.type == 'CREATING_BILL':
Expand Down Expand Up @@ -487,7 +487,7 @@ def create_bill(expense_group: ExpenseGroup, task_log_id, last_export):

bill_lineitems_objects = BillLineitem.create_bill_lineitems(expense_group, configuration)

created_bill = netsuite_connection.post_bill(bill_object, bill_lineitems_objects)
created_bill = netsuite_connection.post_bill(bill_object, bill_lineitems_objects, general_mappings)
logger.info('Created Bill with Expense Group %s successfully', expense_group.id)

task_log.detail = created_bill
Expand Down Expand Up @@ -567,7 +567,7 @@ def create_credit_card_charge(expense_group, task_log_id, last_export):
attachment_links[expense.expense_id] = attachment_link

created_credit_card_charge = netsuite_connection.post_credit_card_charge(
credit_card_charge_object, credit_card_charge_lineitems_object, attachment_links, refund
credit_card_charge_object, credit_card_charge_lineitems_object, general_mappings, attachment_links, refund
)
worker_logger.info('Created Credit Card Charge with Expense Group %s successfully', expense_group.id)

Expand Down Expand Up @@ -612,6 +612,7 @@ def create_expense_report(expense_group, task_log_id, last_export):
return

configuration = Configuration.objects.get(workspace_id=expense_group.workspace_id)
general_mapping = GeneralMapping.objects.get(workspace_id=expense_group.workspace_id)

fyle_credentials = FyleCredential.objects.get(workspace_id=expense_group.workspace_id)
netsuite_credentials = NetSuiteCredentials.objects.get(workspace_id=expense_group.workspace_id)
Expand All @@ -633,7 +634,7 @@ def create_expense_report(expense_group, task_log_id, last_export):
)

created_expense_report = netsuite_connection.post_expense_report(
expense_report_object, expense_report_lineitems_objects
expense_report_object, expense_report_lineitems_objects, general_mapping
)
worker_logger.info('Created Expense Report with Expense Group %s successfully', expense_group.id)

Expand Down Expand Up @@ -676,6 +677,7 @@ def create_journal_entry(expense_group, task_log_id, last_export):
return

configuration = Configuration.objects.get(workspace_id=expense_group.workspace_id)
general_mapping = GeneralMapping.objects.get(workspace_id=expense_group.workspace_id)


fyle_credentials = FyleCredential.objects.get(workspace_id=expense_group.workspace_id)
Expand All @@ -698,7 +700,7 @@ def create_journal_entry(expense_group, task_log_id, last_export):
)

created_journal_entry = netsuite_connection.post_journal_entry(
journal_entry_object, journal_entry_lineitems_objects, configuration
journal_entry_object, journal_entry_lineitems_objects, configuration, general_mapping
)
worker_logger.info('Created Journal Entry with Expense Group %s successfully', expense_group.id)

Expand Down
20 changes: 20 additions & 0 deletions apps/tasks/migrations/0012_alter_tasklog_expense_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.14 on 2024-11-14 10:35

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('fyle', '0033_expense_paid_on_fyle'),
('tasks', '0011_error_repetition_count'),
]

operations = [
migrations.AlterField(
model_name='tasklog',
name='expense_group',
field=models.ForeignKey(help_text='Reference to Expense group', null=True, on_delete=django.db.models.deletion.PROTECT, to='fyle.expensegroup', unique=True),
),
]
2 changes: 1 addition & 1 deletion apps/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TaskLog(models.Model):
type = models.CharField(max_length=50, choices=TASK_TYPE, help_text='Task type (FETCH_EXPENSES / CREATE_BILL)')
task_id = models.CharField(max_length=255, null=True, help_text='Django Q task reference')
expense_group = models.ForeignKey(ExpenseGroup, on_delete=models.PROTECT,
null=True, help_text='Reference to Expense group')
null=True, help_text='Reference to Expense group', unique=True)
bill = models.ForeignKey(Bill, on_delete=models.PROTECT, help_text='Reference to Bill', null=True)
expense_report = models.ForeignKey(ExpenseReport, on_delete=models.PROTECT, help_text='Reference to Expense Report',
null=True)
Expand Down
24 changes: 0 additions & 24 deletions apps/workspaces/apis/import_settings/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ def add_department_grouping(self, source_field: str):

expense_group_settings.save()

def __update_expense_group_settings_for_departments(self):
"""
Should group expenses by department source field in case the export is journal entries
"""
department_setting = list(filter(lambda setting: setting['destination_field'] == 'DEPARTMENT', self.__mapping_settings))

if department_setting:
department_setting = department_setting[0]

self.add_department_grouping(department_setting['source_field'])

def post_save_configurations(self, configurations_instance: Configuration):
"""
Expand All @@ -77,16 +67,6 @@ def post_save_configurations(self, configurations_instance: Configuration):
mapping_settings=self.__mapping_settings
)

def __remove_old_department_source_field(self, current_mappings_settings: List[MappingSetting], new_mappings_settings: List[Dict]):
"""
Should remove Department Source field from Reimbursable settings in case of deletion and updation
"""
old_department_setting = current_mappings_settings.filter(destination_field='DEPARTMENT').first()

new_department_setting = list(filter(lambda setting: setting['destination_field'] == 'DEPARTMENT', new_mappings_settings))

if old_department_setting and new_department_setting and old_department_setting.source_field != new_department_setting[0]['source_field']:
self.remove_department_grouping(old_department_setting.source_field.lower())

def __unset_auto_mapped_flag(self, current_mapping_settings: List[MappingSetting], new_mappings_settings: List[Dict]):
"""
Expand Down Expand Up @@ -119,8 +99,6 @@ def pre_save_mapping_settings(self):

# Update department mapping to some other Fyle field
current_mapping_settings = MappingSetting.objects.filter(workspace_id=self.__workspace_id).all()

self.__remove_old_department_source_field(current_mappings_settings=current_mapping_settings, new_mappings_settings=mapping_settings)
self.__unset_auto_mapped_flag(current_mapping_settings=current_mapping_settings, new_mappings_settings=mapping_settings)

def post_save_mapping_settings(self, configurations_instance: Configuration):
Expand All @@ -139,8 +117,6 @@ def post_save_mapping_settings(self, configurations_instance: Configuration):

MappingSetting.objects.filter(~Q(destination_field__in=destination_fields), workspace_id=self.__workspace_id).delete()

self.__update_expense_group_settings_for_departments()

new_schedule_or_delete_fyle_import_tasks(
configuration_instance=configurations_instance,
mapping_settings=self.__mapping_settings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2024-11-18 02:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0039_configuration_je_single_credit_line'),
]

operations = [
migrations.AlterField(
model_name='configuration',
name='change_accounting_period',
field=models.BooleanField(default=True, help_text='Change the accounting period'),
),
]
2 changes: 1 addition & 1 deletion apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Configuration(models.Model):
import_projects = models.BooleanField(default=False, help_text='Auto import projects to Fyle')
import_vendors_as_merchants = models.BooleanField(default=False, help_text='Auto import vendors from netsuite as merchants to Fyle')
import_netsuite_employees = models.BooleanField(default=False, help_text='Auto import employees from netsuite as employees to Fyle')
change_accounting_period = models.BooleanField(default=False, help_text='Change the accounting period')
change_accounting_period = models.BooleanField(default=True, help_text='Change the accounting period')
sync_fyle_to_netsuite_payments = models.BooleanField(
default=False, help_text='Auto Sync Payments from Fyle to Netsuite'
)
Expand Down
9 changes: 0 additions & 9 deletions fyle_netsuite_api/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def init():
send_default_pii=True,
integrations=[DjangoIntegration()],
environment=os.environ.get('SENTRY_ENV'),
traces_sampler=Sentry.traces_sampler,
attach_stacktrace=True,
before_send=Sentry.before_send,
request_bodies='small',
Expand All @@ -29,14 +28,6 @@ def init():
)

@staticmethod
def traces_sampler(sampling_context):
# avoiding ready APIs in performance tracing
if sampling_context.get('wsgi_environ') is not None:
if 'ready/' in sampling_context['wsgi_environ']['PATH_INFO']:
return 0

return 1
@staticmethod
def before_send(event, hint):
if 'exc_info' in hint:
exc_type, exc_value, tb = hint['exc_info']
Expand Down
3 changes: 3 additions & 0 deletions fyle_netsuite_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def generate_netsuite_export_url(response_logs : OrderedDict, netsuite_credentia
if response_logs:
try:
ns_account_id = netsuite_credentials.ns_account_id.lower()
if '_sb' in ns_account_id:
ns_account_id = ns_account_id.replace('_sb', '-sb')

export_type = response_logs['type'] if 'type' in response_logs and response_logs['type'] else 'chargeCard'
internal_id = response_logs['internalId']
redirection = EXPORT_TYPE_REDIRECTION[export_type]
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum34==1.1.10
future==0.18.2
fyle==0.37.0
fyle-accounting-mappings==1.34.8
fyle-integrations-platform-connector==1.38.4
fyle-integrations-platform-connector==1.39.3
fyle-rest-auth==1.7.2
gunicorn==20.1.0
gevent==23.9.1
Expand All @@ -33,7 +33,7 @@ isort==5.10.1
lazy-object-proxy==1.6.0
lxml==4.6.5
mccabe==0.6.1
netsuitesdk==2.23.0
netsuitesdk==3.0.0
oauthlib==3.2.1
packaging==21.3
platformdirs==2.4.0
Expand Down
17 changes: 17 additions & 0 deletions scripts/sql/scripts/029-update-sandbox-export-urls.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rollback;
begin;

-- These values should be swapped after running the script
-- netsuite=> select count(export_url) from expense_groups where export_url like '%_sb%';
-- count
-- -------
-- 240
-- (1 row)

-- netsuite=> select count(export_url) from expense_groups where export_url like '%-sb%';
-- count
-- -------
-- 0
-- (1 row)

update expense_groups set export_url = replace(export_url, '_sb', '-sb');
Loading

0 comments on commit 50183d3

Please sign in to comment.