Skip to content

Commit

Permalink
update export url script (#467)
Browse files Browse the repository at this point in the history
* script changes

* minor change

* employee name field length increased
  • Loading branch information
Ashutosh619-sudo authored Nov 30, 2023
1 parent c3ad245 commit a8dd23d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
18 changes: 18 additions & 0 deletions apps/fyle/migrations/0029_auto_20231130_0821.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.14 on 2023-11-30 08:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('fyle', '0028_expensegroup_export_url'),
]

operations = [
migrations.AlterField(
model_name='expensegroup',
name='employee_name',
field=models.CharField(help_text='Expense Group Employee Name', max_length=255, null=True),
),
]
2 changes: 1 addition & 1 deletion apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class ExpenseGroup(models.Model):
help_text='To which workspace this expense group belongs to')
fund_source = models.CharField(max_length=255, help_text='Expense fund source')
expenses = models.ManyToManyField(Expense, help_text="Expenses under this Expense Group")
employee_name = models.CharField(max_length=100, help_text='Expense Group Employee Name', null=True)
employee_name = models.CharField(max_length=255, help_text='Expense Group Employee Name', null=True)
description = JSONField(max_length=255, help_text='Description', null=True)
response_logs = JSONField(help_text='Reponse log of the export', null=True)
export_url = models.CharField(max_length=255, help_text='Netsuite URL for the exported expenses', null=True)
Expand Down
6 changes: 3 additions & 3 deletions fyle_netsuite_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def generate_netsuite_export_url(response_logs : OrderedDict, netsuite_credentia

if response_logs:
try:
ns_account_id = netsuite_credentials.ns_account_id
export_type = response_logs['type'] if response_logs['type'] else 'chargeCard'
ns_account_id = netsuite_credentials.ns_account_id.lower()
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]
url = f'https://{ns_account_id}.app.netsuite.com/app/accounting/transactions/${redirection}.nl?id={internal_id}'
url = f'https://{ns_account_id}.app.netsuite.com/app/accounting/transactions/{redirection}.nl?id={internal_id}'
return url
except Exception as exception:
logger.exception({'error': exception})
Expand Down
17 changes: 9 additions & 8 deletions scripts/python/update-export-url.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
for workspace in prod_workspaces:
page_size = 200
expense_group_counts = ExpenseGroup.objects.filter(workspace_id=workspace.id, response_logs__isnull=False).count()
for offset in range(0, expense_group_counts, page_size):
expense_to_be_updated = []
limit = offset + page_size
paginated_expense_groups = ExpenseGroup.objects.filter(workspace_id=workspace.id, response_logs__isnull=False)[offset:limit]
for expense_group in paginated_expense_groups:
netsuite_credentials = NetSuiteCredentials.objects.get(workspace_id=workspace.id)
expense_group.export_url = generate_netsuite_export_url(response_logs=expense_group.response_logs, netsuite_credentials=netsuite_credentials)
expense_group.save()
netsuite_credentials = NetSuiteCredentials.objects.filter(workspace_id=workspace.id).first()
if netsuite_credentials:
for offset in range(0, expense_group_counts, page_size):
expense_to_be_updated = []
limit = offset + page_size
paginated_expense_groups = ExpenseGroup.objects.filter(workspace_id=workspace.id, response_logs__isnull=False)[offset:limit]
for expense_group in paginated_expense_groups:
expense_group.export_url = generate_netsuite_export_url(response_logs=expense_group.response_logs, netsuite_credentials=netsuite_credentials)
expense_group.save()

0 comments on commit a8dd23d

Please sign in to comment.