Skip to content

Commit

Permalink
reverted changes (#398)
Browse files Browse the repository at this point in the history
* reverted changes

* Revert "Ccc jounral entry allow to add name or mechant (#396)"

This reverts commit ead762b.
  • Loading branch information
labhvam5 committed Jun 19, 2023
1 parent ead762b commit 8c33eae
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 106 deletions.
80 changes: 26 additions & 54 deletions apps/netsuite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -138,18 +129,22 @@ 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',
'value': unidecode.unidecode(u'{0}'.format(account['acctName'])).replace('/', '-'),
'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({
Expand All @@ -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(
Expand All @@ -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',
Expand All @@ -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(
Expand Down
18 changes: 7 additions & 11 deletions apps/netsuite/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions apps/netsuite/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -982,15 +982,14 @@ 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(
source_employee=employee,
workspace_id=expense_group.workspace_id
)


if configuration.employee_field_mapping == 'EMPLOYEE':
entity = entity.destination_employee
else:
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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'
1 change: 0 additions & 1 deletion apps/workspaces/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
)

Expand Down
17 changes: 7 additions & 10 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);


Expand Down Expand Up @@ -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
\.


Expand Down Expand Up @@ -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
\.


Expand Down Expand Up @@ -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);


--
Expand Down
3 changes: 1 addition & 2 deletions tests/test_workspaces/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_workspaces/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c33eae

Please sign in to comment.