From 8c33eae86e1d7615ee8572ee9957b7ee7e2e0a7f Mon Sep 17 00:00:00 2001 From: labhvam5 <88420539+labhvam5@users.noreply.github.com> Date: Mon, 19 Jun 2023 14:46:03 +0530 Subject: [PATCH] reverted changes (#398) * reverted changes * Revert "Ccc jounral entry allow to add name or mechant (#396)" This reverts commit ead762b1379bc7c1b53e6ae0d3aa192ee3bccb12. --- apps/netsuite/connector.py | 80 ++++++------------- apps/netsuite/models.py | 18 ++--- apps/netsuite/tasks.py | 5 +- ...032_configuration_name_in_journal_entry.py | 18 ----- apps/workspaces/models.py | 5 -- apps/workspaces/serializers.py | 1 - .../reset_db_fixtures/reset_db.sql | 17 ++-- tests/test_workspaces/data.json | 3 +- tests/test_workspaces/fixtures.py | 3 +- 9 files changed, 44 insertions(+), 106 deletions(-) delete mode 100644 apps/workspaces/migrations/0032_configuration_name_in_journal_entry.py diff --git a/apps/netsuite/connector.py b/apps/netsuite/connector.py index f13f5672..eca750ea 100644 --- a/apps/netsuite/connector.py +++ b/apps/netsuite/connector.py @@ -94,17 +94,8 @@ def sync_accounts(self): 'ccc_account': [], 'vendor_payment_account': [] } - # get all the destination attributes for accounts - destination_attributes = DestinationAttribute.objects.filter(workspace_id=self.workspace_id, - attribute_type='ACCOUNT', display_name='Account').values('destination_id', 'value') - - # store the destination attributes in disabled_fields_map with destination_id as key and value and detail as value - # destination_id : {value: value, detail: detail} - disabled_fields_map = {} - for destination_attribute in destination_attributes: - disabled_fields_map[destination_attribute['destination_id']] = { - 'value': destination_attribute['value'] - } + destination_ids = DestinationAttribute.objects.filter(workspace_id=self.workspace_id, + attribute_type='ACCOUNT', display_name='Account').values_list('destination_id', flat=True) for account in list(accounts): if account['acctType'] != '_expense': @@ -138,8 +129,15 @@ def sync_accounts(self): if account['acctType'] in ['_expense', '_costOfGoodsSold', '_otherCurrentAsset', '_otherExpense', '_fixedAsset', '_deferredExpense', '_otherCurrentLiability', '_income', '_otherAsset']: - # if the account is active append it to the list of account as active=true - if not account['isInactive']: + if account['internalId'] in destination_ids: + attributes['account'].append({ + 'attribute_type': 'ACCOUNT', + 'display_name': 'Account', + 'value': unidecode.unidecode(u'{0}'.format(account['acctName'])).replace('/', '-'), + 'destination_id': account['internalId'], + 'active': not account['isInactive'] + }) + elif not account['isInactive']: attributes['account'].append({ 'attribute_type': 'ACCOUNT', 'display_name': 'Account', @@ -147,9 +145,6 @@ def sync_accounts(self): 'destination_id': account['internalId'], 'active': True }) - # the account is active so remove it from the map - if account['internalId'] in disabled_fields_map: - disabled_fields_map.pop(account['internalId']) if account['acctType'] == '_bank' or account['acctType'] == '_creditCard': attributes['vendor_payment_account'].append({ @@ -160,16 +155,6 @@ def sync_accounts(self): 'active': not account['isInactive'] }) - # for all the accounts in the map are inactive so add them to the list of accounts as as active=false - for destination_id in disabled_fields_map: - attributes['account'].append({ - 'attribute_type': 'ACCOUNT', - 'display_name': 'Account', - 'value': disabled_fields_map[destination_id]['value'], - 'destination_id': destination_id, - 'active': False - }) - for attribute_type, attribute in attributes.items(): if attribute: DestinationAttribute.bulk_create_or_update_destination_attributes( @@ -188,26 +173,27 @@ def sync_expense_categories(self): 'expense_category': [], 'ccc_expense_category': [] } - # get all the destination attributes for expense category - destination_attributes = DestinationAttribute.objects.filter(workspace_id=self.workspace_id, - attribute_type='EXPENSE_CATEGORY', display_name='Expense Category').values('destination_id', 'value', 'detail') - - # store the destination attributes in disabled_fields_map with destination_id as key and value and detail as value - # destination_id : {value: value, detail: detail} - disabled_fields_map = {} - for destination_attribute in destination_attributes: - disabled_fields_map[destination_attribute['destination_id']] = { - 'value': destination_attribute['value'], - 'detail': destination_attribute['detail'] - } + destination_ids = DestinationAttribute.objects.filter(workspace_id=self.workspace_id, + attribute_type='EXPENSE_CATEGORY', display_name='Expense Category').values_list('destination_id', flat=True) for category in categories: detail = { 'account_name': category['expenseAcct']['name'], 'account_internal_id': category['expenseAcct']['internalId'] } - # if the category is active append it to the list of expense categories as active=true - if not category['isInactive']: + + if category['internalId'] in destination_ids: + attributes['expense_category'].append( + { + 'attribute_type': 'EXPENSE_CATEGORY', + 'display_name': 'Expense Category', + 'value': unidecode.unidecode(u'{0}'.format(category['name'])).replace('/', '-'), + 'destination_id': category['internalId'], + 'detail': detail, + 'active': not category['isInactive'] + } + ) + elif not category['isInactive']: attributes['expense_category'].append( { 'attribute_type': 'EXPENSE_CATEGORY', @@ -218,20 +204,6 @@ def sync_expense_categories(self): 'active': True } ) - # the category is active so remove it from the map - if category['internalId'] in disabled_fields_map: - disabled_fields_map.pop(category['internalId']) - - # for all the categories in the map are inactive so add them to the list of expense categories as active=false - for destination_id in disabled_fields_map: - attributes['expense_category'].append({ - 'attribute_type': 'EXPENSE_CATEGORY', - 'display_name': 'Expense Category', - 'value': disabled_fields_map[destination_id]['value'], - 'destination_id': destination_id, - 'detail': disabled_fields_map[destination_id]['detail'], - 'active': False - }) for attribute_type, attribute in attributes.items(): DestinationAttribute.bulk_create_or_update_destination_attributes( diff --git a/apps/netsuite/models.py b/apps/netsuite/models.py index 071bba18..af72a0f6 100644 --- a/apps/netsuite/models.py +++ b/apps/netsuite/models.py @@ -1078,17 +1078,13 @@ def create_journal_entry_lineitems(expense_group: ExpenseGroup, configuration: C elif employee_field_mapping == 'EMPLOYEE': debit_account_id = general_mappings.reimbursable_account_id elif expense_group.fund_source == 'CCC': - if configuration.name_in_journal_entry == 'MERCHANT': - vendor = None - merchant = lineitem.vendor if lineitem.vendor else '' - if merchant: - vendor = DestinationAttribute.objects.filter( - value__iexact=merchant, attribute_type='VENDOR', workspace_id=expense_group.workspace_id - ).first() - entity_id = vendor.destination_id if vendor else general_mappings.default_ccc_vendor_id - else: - entity_id = employee_mapping.destination_employee.destination_id if employee_field_mapping == 'EMPLOYEE' \ - else employee_mapping.destination_vendor.destination_id + vendor = None + merchant = lineitem.vendor if lineitem.vendor else '' + if merchant: + vendor = DestinationAttribute.objects.filter( + value__iexact=merchant, attribute_type='VENDOR', workspace_id=expense_group.workspace_id + ).first() + entity_id = vendor.destination_id if vendor else general_mappings.default_ccc_vendor_id debit_account_id = get_ccc_account_id(configuration, general_mappings, lineitem, description) account = CategoryMapping.objects.filter( diff --git a/apps/netsuite/tasks.py b/apps/netsuite/tasks.py index 157871ec..d0ab1912 100644 --- a/apps/netsuite/tasks.py +++ b/apps/netsuite/tasks.py @@ -874,7 +874,7 @@ def __validate_general_mapping(expense_group: ExpenseGroup, configuration: Confi if not (general_mapping.default_ccc_vendor_id or general_mapping.default_ccc_vendor_name) and \ expense_group.fund_source == 'CCC' and \ - configuration.corporate_credit_card_expenses_object == 'JOURNAL ENTRY' and configuration.name_in_journal_entry == 'MERCHANT' : + configuration.corporate_credit_card_expenses_object == 'JOURNAL ENTRY': bulk_errors.append({ 'row': None, 'expense_group_id': expense_group.id, @@ -982,7 +982,7 @@ def __validate_employee_mapping(expense_group: ExpenseGroup, configuration: Conf employee = sync_inactive_employee(expense_group) bulk_errors = [] - if expense_group.fund_source == 'PERSONAL' or configuration.name_in_journal_entry == 'EMPLOYEE' or \ + if expense_group.fund_source == 'PERSONAL' or \ (expense_group.fund_source == 'CCC' and configuration.corporate_credit_card_expenses_object == 'EXPENSE REPORT'): try: entity = EmployeeMapping.objects.get( @@ -990,7 +990,6 @@ def __validate_employee_mapping(expense_group: ExpenseGroup, configuration: Conf workspace_id=expense_group.workspace_id ) - if configuration.employee_field_mapping == 'EMPLOYEE': entity = entity.destination_employee else: diff --git a/apps/workspaces/migrations/0032_configuration_name_in_journal_entry.py b/apps/workspaces/migrations/0032_configuration_name_in_journal_entry.py deleted file mode 100644 index 4462dd9f..00000000 --- a/apps/workspaces/migrations/0032_configuration_name_in_journal_entry.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.1.14 on 2023-06-16 09:45 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('workspaces', '0031_configuration_import_items'), - ] - - operations = [ - migrations.AddField( - model_name='configuration', - name='name_in_journal_entry', - field=models.CharField(choices=[('MERCHANT', 'MERCHANT'), ('EMPLOYEE', 'EMPLOYEE')], default='MERCHANT', help_text='Name in jounral entry for ccc expense only', max_length=100), - ), - ] diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index eb7a503c..e3bb8106 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -109,10 +109,6 @@ class Meta: ('EMPLOYEE_CODE', 'EMPLOYEE_CODE'), ) -NAME_IN_JOURNAL_ENTRY = ( - ('MERCHANT', 'MERCHANT'), - ('EMPLOYEE', 'EMPLOYEE') -) def get_default_memo_fields(): return ['employee_email', 'category', 'merchant', 'spent_on', 'report_number', 'purpose'] @@ -163,7 +159,6 @@ class Configuration(models.Model): is_simplify_report_closure_enabled = models.BooleanField(default=True, help_text='Simplify report closure is enbaled') created_at = models.DateTimeField(auto_now_add=True, help_text='Created at') updated_at = models.DateTimeField(auto_now=True, help_text='Updated at') - 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) class Meta: db_table = 'configurations' diff --git a/apps/workspaces/serializers.py b/apps/workspaces/serializers.py index 914b5381..bc422bf1 100644 --- a/apps/workspaces/serializers.py +++ b/apps/workspaces/serializers.py @@ -78,7 +78,6 @@ def create(self, validated_data): 'import_vendors_as_merchants': validated_data['import_vendors_as_merchants'], 'import_netsuite_employees': validated_data['import_netsuite_employees'], 'import_items': validated_data['import_items'], - 'name_in_journal_entry' : validated_data.get('name_in_journal_entry') } ) diff --git a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql index b88b3b0d..aafa8990 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -2,7 +2,7 @@ -- PostgreSQL database dump -- --- Dumped from database version 15.3 (Debian 15.3-1.pgdg120+1) +-- Dumped from database version 15.3 (Debian 15.3-1.pgdg110+1) -- Dumped by pg_dump version 15.3 (Debian 15.3-1.pgdg100+1) SET statement_timeout = 0; @@ -315,8 +315,7 @@ CREATE TABLE public.configurations ( import_vendors_as_merchants boolean NOT NULL, import_netsuite_employees boolean NOT NULL, is_simplify_report_closure_enabled boolean NOT NULL, - import_items boolean NOT NULL, - name_in_journal_entry character varying(100) NOT NULL + import_items boolean NOT NULL ); @@ -2449,10 +2448,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) 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 -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 -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 +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) 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 +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 +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 \. @@ -7699,8 +7698,6 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 157 fyle_accounting_mappings 0023_auto_20230523_1047 2023-05-29 07:05:46.20766+00 158 netsuite 0021_auto_20230523_1047 2023-05-29 07:05:46.232192+00 159 workspaces 0031_configuration_import_items 2023-05-29 07:05:46.247343+00 -160 fyle 0025_auto_20230608_0837 2023-06-15 13:20:07.816654+00 -161 workspaces 0032_configuration_name_in_journal_entry 2023-06-15 13:20:08.00105+00 \. @@ -11580,7 +11577,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 43, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 161, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 159, true); -- diff --git a/tests/test_workspaces/data.json b/tests/test_workspaces/data.json index 367c79c8..ad0e17db 100644 --- a/tests/test_workspaces/data.json +++ b/tests/test_workspaces/data.json @@ -22,8 +22,7 @@ "created_at":"2021-11-10T20:19:39.312089Z", "updated_at":"2021-11-10T20:19:39.312105Z", "import_netsuite_employees": true, - "is_simplify_report_closure_enabled": true, - "name_in_journal_entry": "MERCHANT" + "is_simplify_report_closure_enabled": true }, "workspace": { "id":1, diff --git a/tests/test_workspaces/fixtures.py b/tests/test_workspaces/fixtures.py index 8f8f4272..621cc05d 100644 --- a/tests/test_workspaces/fixtures.py +++ b/tests/test_workspaces/fixtures.py @@ -39,8 +39,7 @@ def create_configurations_object_payload(workspace_id): 'auto_create_merchants': False, 'employee_field_mapping': 'VENDOR', 'memo_structure': memo_structure, - 'import_netsuite_employees': True, - 'name_in_journal_entry': 'MERCHANT' + 'import_netsuite_employees': True } return workspace_general_settings_payload