From a8dd23da4be2ff6768cd46ab735cd747766bb63e Mon Sep 17 00:00:00 2001 From: Ashutosh singh <55102089+Ashutosh619-sudo@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:27:30 -0800 Subject: [PATCH] update export url script (#467) * script changes * minor change * employee name field length increased --- .../fyle/migrations/0029_auto_20231130_0821.py | 18 ++++++++++++++++++ apps/fyle/models.py | 2 +- fyle_netsuite_api/utils.py | 6 +++--- scripts/python/update-export-url.py | 17 +++++++++-------- 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 apps/fyle/migrations/0029_auto_20231130_0821.py diff --git a/apps/fyle/migrations/0029_auto_20231130_0821.py b/apps/fyle/migrations/0029_auto_20231130_0821.py new file mode 100644 index 00000000..66b7f285 --- /dev/null +++ b/apps/fyle/migrations/0029_auto_20231130_0821.py @@ -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), + ), + ] diff --git a/apps/fyle/models.py b/apps/fyle/models.py index 9fcf76bb..75b1de3d 100644 --- a/apps/fyle/models.py +++ b/apps/fyle/models.py @@ -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) diff --git a/fyle_netsuite_api/utils.py b/fyle_netsuite_api/utils.py index 376d3b5d..f4cc03f5 100644 --- a/fyle_netsuite_api/utils.py +++ b/fyle_netsuite_api/utils.py @@ -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}) diff --git a/scripts/python/update-export-url.py b/scripts/python/update-export-url.py index c5ae7d0b..3fce4c70 100644 --- a/scripts/python/update-export-url.py +++ b/scripts/python/update-export-url.py @@ -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()