Skip to content
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

Feat: Add toggle for enabling uploading attachments #687

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions apps/netsuite/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,11 @@ def create_bill(expense_group: ExpenseGroup, task_log_id, last_export):
logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e)

logger.info('Updated Expense Group %s successfully', expense_group.id)
async_task(
'apps.netsuite.tasks.upload_attachments_and_update_export',
expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id
)
if configuration.is_attachment_upload_enabled:
async_task(
'apps.netsuite.tasks.upload_attachments_and_update_export',
expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id
)


@handle_netsuite_exceptions(payment=False)
Expand Down Expand Up @@ -561,11 +562,12 @@ def create_credit_card_charge(expense_group, task_log_id, last_export):
if expense.amount < 0:
refund = True

for expense in expense_group.expenses.all():
attachment_link = load_attachments(netsuite_connection, expense, expense_group, credit_card_charge_object)
if configuration.is_attachment_upload_enabled:
for expense in expense_group.expenses.all():
attachment_link = load_attachments(netsuite_connection, expense, expense_group, credit_card_charge_object)

if attachment_link:
attachment_links[expense.expense_id] = attachment_link
if attachment_link:
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_objects, general_mappings, attachment_links, refund
Expand Down Expand Up @@ -659,10 +661,11 @@ def create_expense_report(expense_group, task_log_id, last_export):
logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e)

worker_logger.info('Updated Expense Group %s successfully', expense_group.id)
async_task(
'apps.netsuite.tasks.upload_attachments_and_update_export',
expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id
)
if configuration.is_attachment_upload_enabled:
async_task(
'apps.netsuite.tasks.upload_attachments_and_update_export',
expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id
)



Expand Down Expand Up @@ -724,10 +727,11 @@ def create_journal_entry(expense_group, task_log_id, last_export):
logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e)

worker_logger.info('Updated Expense Group %s successfully', expense_group.id)
async_task(
'apps.netsuite.tasks.upload_attachments_and_update_export',
expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id
)
if configuration.is_attachment_upload_enabled:
async_task(
'apps.netsuite.tasks.upload_attachments_and_update_export',
expense_group.expenses.all(), task_log, fyle_credentials, expense_group.workspace_id
)


def __validate_general_mapping(expense_group: ExpenseGroup, configuration: Configuration) -> List[BulkError]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2024-12-18 05:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0040_alter_configuration_change_accounting_period'),
]

operations = [
migrations.AddField(
model_name='configuration',
name='is_attachment_upload_enabled',
field=models.BooleanField(default=True, help_text='Is Attachment upload enabled'),
),
]
1 change: 1 addition & 0 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class Configuration(models.Model):
name_in_journal_entry = models.CharField(max_length=100, help_text='Name in jounral entry for ccc expense only', default='MERCHANT',choices=NAME_IN_JOURNAL_ENTRY)
allow_intercompany_vendors = models.BooleanField(default=False, help_text='Allow intercompany vendors')
je_single_credit_line = models.BooleanField(default=False, help_text='Journal Entry Single Credit Line')
is_attachment_upload_enabled = models.BooleanField(default=True, help_text='Is Attachment upload enabled')

class Meta:
db_table = 'configurations'
Expand Down
32 changes: 18 additions & 14 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--

-- Dumped from database version 15.10 (Debian 15.10-1.pgdg120+1)
-- Dumped by pg_dump version 15.9 (Debian 15.9-1.pgdg120+1)
-- Dumped by pg_dump version 15.10 (Debian 15.10-1.pgdg120+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down Expand Up @@ -323,7 +323,8 @@ CREATE TABLE public.configurations (
import_items boolean NOT NULL,
name_in_journal_entry character varying(100) NOT NULL,
allow_intercompany_vendors boolean NOT NULL,
je_single_credit_line boolean NOT NULL
je_single_credit_line boolean NOT NULL,
is_attachment_upload_enabled boolean NOT NULL
);


Expand Down Expand Up @@ -2697,10 +2698,10 @@ COPY public.category_mappings (id, created_at, updated_at, destination_account_i
-- Data for Name: configurations; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.configurations (id, reimbursable_expenses_object, corporate_credit_card_expenses_object, created_at, updated_at, workspace_id, sync_fyle_to_netsuite_payments, sync_netsuite_to_fyle_payments, import_projects, auto_map_employees, import_categories, auto_create_destination_entity, auto_create_merchants, employee_field_mapping, import_tax_items, change_accounting_period, memo_structure, map_fyle_cards_netsuite_account, skip_cards_mapping, import_vendors_as_merchants, import_netsuite_employees, is_simplify_report_closure_enabled, import_items, name_in_journal_entry, allow_intercompany_vendors, je_single_credit_line) FROM stdin;
1 EXPENSE REPORT BILL 2021-11-15 08:56:07.193743+00 2021-11-15 08:56:07.193795+00 1 f f f \N f f f EMPLOYEE f f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f
2 JOURNAL ENTRY CREDIT CARD CHARGE 2021-11-16 04:18:15.836271+00 2021-11-16 04:20:09.969589+00 2 f f f \N f f f EMPLOYEE t f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f
3 JOURNAL ENTRY CREDIT CARD CHARGE 2021-12-03 11:04:00.194287+00 2021-12-03 11:04:00.1943+00 49 f f f \N f f f EMPLOYEE f f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f
COPY public.configurations (id, reimbursable_expenses_object, corporate_credit_card_expenses_object, created_at, updated_at, workspace_id, sync_fyle_to_netsuite_payments, sync_netsuite_to_fyle_payments, import_projects, auto_map_employees, import_categories, auto_create_destination_entity, auto_create_merchants, employee_field_mapping, import_tax_items, change_accounting_period, memo_structure, map_fyle_cards_netsuite_account, skip_cards_mapping, import_vendors_as_merchants, import_netsuite_employees, is_simplify_report_closure_enabled, import_items, name_in_journal_entry, allow_intercompany_vendors, je_single_credit_line, is_attachment_upload_enabled) FROM stdin;
1 EXPENSE REPORT BILL 2021-11-15 08:56:07.193743+00 2021-11-15 08:56:07.193795+00 1 f f f \N f f f EMPLOYEE f f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f t
2 JOURNAL ENTRY CREDIT CARD CHARGE 2021-11-16 04:18:15.836271+00 2021-11-16 04:20:09.969589+00 2 f f f \N f f f EMPLOYEE t f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f t
3 JOURNAL ENTRY CREDIT CARD CHARGE 2021-12-03 11:04:00.194287+00 2021-12-03 11:04:00.1943+00 49 f f f \N f f f EMPLOYEE f f {employee_email,category,spent_on,report_number,purpose} t f f f f f MERCHANT f f t
\.


Expand Down Expand Up @@ -7997,6 +7998,8 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin;
204 workspaces 0040_alter_configuration_change_accounting_period 2024-11-18 04:28:36.094429+00
205 fyle 0035_support_split_expense_grouping 2024-11-22 10:40:59.441051+00
206 fyle 0036_expense_masked_corporate_card_number 2024-11-26 09:24:50.240658+00
207 fyle_accounting_mappings 0027_alter_employeemapping_source_employee 2024-12-18 05:34:34.929303+00
208 workspaces 0041_configuration_is_attachment_upload_enabled 2024-12-18 05:34:34.968096+00
\.


Expand Down Expand Up @@ -11908,7 +11911,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 47, true);
-- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.django_migrations_id_seq', 206, true);
SELECT pg_catalog.setval('public.django_migrations_id_seq', 208, true);


--
Expand Down Expand Up @@ -12396,6 +12399,14 @@ ALTER TABLE ONLY public.employee_mappings
ADD CONSTRAINT employee_mappings_pkey PRIMARY KEY (id);


--
-- Name: employee_mappings employee_mappings_source_employee_id_dd9948ba_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.employee_mappings
ADD CONSTRAINT employee_mappings_source_employee_id_dd9948ba_uniq UNIQUE (source_employee_id);


--
-- Name: errors errors_expense_attribute_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--
Expand Down Expand Up @@ -13054,13 +13065,6 @@ CREATE INDEX employee_mappings_destination_employee_id_b6764819 ON public.employ
CREATE INDEX employee_mappings_destination_vendor_id_c4bd73df ON public.employee_mappings USING btree (destination_vendor_id);


--
-- Name: employee_mappings_source_employee_id_dd9948ba; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX employee_mappings_source_employee_id_dd9948ba ON public.employee_mappings USING btree (source_employee_id);


--
-- Name: employee_mappings_workspace_id_4a25f8c9; Type: INDEX; Schema: public; Owner: postgres
--
Expand Down
3 changes: 2 additions & 1 deletion tests/test_workspaces/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"is_simplify_report_closure_enabled": true,
"name_in_journal_entry": "MERCHANT",
"allow_intercompany_vendors": false,
"je_single_credit_line": false
"je_single_credit_line": false,
"is_attachment_upload_enabled": true
Comment on lines +28 to +29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix JSON formatting

Ensure proper comma separation between properties.

Apply this fix:

     "allow_intercompany_vendors": false,
-    "je_single_credit_line": false,
+    "je_single_credit_line": false,
     "is_attachment_upload_enabled": true

Committable suggestion skipped: line range outside the PR's diff.

},
"workspace": {
"id":1,
Expand Down
Loading