Skip to content

Commit

Permalink
Adding support for category_ccc_mapping (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
labhvam5 authored Sep 7, 2023
1 parent c20c763 commit ba882d5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ indent-after-paren=4
indent-string=' '

# Maximum number of characters on a single line.
max-line-length=130
max-line-length=135

# Maximum number of lines in a module.
max-module-lines=1000
Expand Down
57 changes: 57 additions & 0 deletions fyle_accounting_mappings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,60 @@ def bulk_create_mappings(destination_attributes: List[DestinationAttribute],
)

return create_mappings_and_update_flag(mapping_creation_batch, set_auto_mapped_flag, model_type=CategoryMapping)

@staticmethod
def bulk_create_ccc_category_mappings(workspace_id: int):
"""
Create Category Mappings for CCC Expenses
:param workspace_id: Workspace ID
"""
category_mappings = CategoryMapping.objects.filter(
workspace_id=workspace_id,
destination_account__isnull=True
).all()

destination_account_internal_ids = []

for category_mapping in category_mappings:
if category_mapping.destination_expense_head.detail and \
'gl_account_no' in category_mapping.destination_expense_head.detail and \
category_mapping.destination_expense_head.detail['gl_account_no']:
destination_account_internal_ids.append(category_mapping.destination_expense_head.detail['gl_account_no'])

elif category_mapping.destination_expense_head.detail and \
'account_internal_id' in category_mapping.destination_expense_head.detail and \
category_mapping.destination_expense_head.detail['account_internal_id']:
destination_account_internal_ids.append(category_mapping.destination_expense_head.detail['account_internal_id'])

# Retreiving accounts for creating ccc mapping
destination_attributes = DestinationAttribute.objects.filter(
workspace_id=workspace_id,
attribute_type='ACCOUNT',
destination_id__in=destination_account_internal_ids
).values('id', 'destination_id')

destination_id_pk_map = {}
for attribute in destination_attributes:
destination_id_pk_map[attribute['destination_id'].lower()] = attribute['id']

mapping_updation_batch = []

for category_mapping in category_mappings:
ccc_account_id = None
if category_mapping.destination_expense_head.detail['gl_account_no'].lower() in destination_id_pk_map:
ccc_account_id = destination_id_pk_map[category_mapping.destination_expense_head.detail['gl_account_no'].lower()]
elif category_mapping.destination_expense_head.detail['account_internal_id'].lower() in destination_id_pk_map:
ccc_account_id = destination_id_pk_map[category_mapping.destination_expense_head.detail['account_internal_id'].lower()]

mapping_updation_batch.append(
CategoryMapping(
id=category_mapping.id,
source_category_id=category_mapping.source_category.id,
destination_account_id=ccc_account_id
)
)

if mapping_updation_batch:
CategoryMapping.objects.bulk_update(
mapping_updation_batch, fields=['destination_account'], batch_size=50
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='fyle-accounting-mappings',
version='1.26.3',
version='1.26.4',
author='Shwetabh Kumar',
author_email='[email protected]',
description='Django application to store the fyle accounting mappings in a generic manner',
Expand Down

0 comments on commit ba882d5

Please sign in to comment.