Skip to content

Commit

Permalink
Update for Project disable changes in sage300 (#109)
Browse files Browse the repository at this point in the history
* Update for Project disable changes in sage300

* Bump version
  • Loading branch information
Hrishabh17 authored Jun 4, 2024
1 parent dd18940 commit 72da0bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions fyle_accounting_mappings/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib
from typing import List, Dict
from datetime import datetime
from django.utils.module_loading import import_string
from django.db import models, transaction
from django.db.models import JSONField
from django.contrib.postgres.fields import ArrayField
Expand Down Expand Up @@ -318,7 +319,13 @@ def create_or_update_destination_attribute(attribute: Dict, workspace_id):

@staticmethod
def bulk_create_or_update_destination_attributes(
attributes: List[Dict], attribute_type: str, workspace_id: int, update: bool = False, display_name: str = None):
attributes: List[Dict],
attribute_type: str,
workspace_id: int,
update: bool = False,
display_name: str = None,
project_disable_callback_path: str = None,
):
"""
Create Destination Attributes in bulk
:param update: Update Pre-existing records or not
Expand All @@ -331,6 +338,7 @@ def bulk_create_or_update_destination_attributes(
'detail': Extra Details of the attribute
}]
:param workspace_id: Workspace Id
:param project_disable_callback_path: API func to call when project is to be disabled
:return: created / updated attributes
"""
attribute_destination_id_list = [attribute['destination_id'] for attribute in attributes]
Expand Down Expand Up @@ -361,6 +369,7 @@ def bulk_create_or_update_destination_attributes(

attributes_to_be_created = []
attributes_to_be_updated = []
projects_to_disable = {}

destination_ids_appended = []
for attribute in attributes:
Expand All @@ -379,13 +388,17 @@ def bulk_create_or_update_destination_attributes(
)
)
else:
if update and(
if project_disable_callback_path and attribute['value'] != primary_key_map[attribute['destination_id']]['value']:
projects_to_disable[attribute['destination_id']] = {
'value': primary_key_map[attribute['destination_id']]['value'],
'updated_value': attribute['value']
}

if update and (
(attribute['value'] != primary_key_map[attribute['destination_id']]['value'])
or
('detail' in attribute and attribute['detail'] != primary_key_map[attribute['destination_id']]['detail'])
or
('active' in attribute and attribute['active'] != primary_key_map[attribute['destination_id']]['active'])
):
or ('detail' in attribute and attribute['detail'] != primary_key_map[attribute['destination_id']]['detail'])
or ('active' in attribute and attribute['active'] != primary_key_map[attribute['destination_id']]['active'])
):
attributes_to_be_updated.append(
DestinationAttribute(
id=primary_key_map[attribute['destination_id']]['id'],
Expand All @@ -395,6 +408,10 @@ def bulk_create_or_update_destination_attributes(
updated_at=datetime.now()
)
)

if project_disable_callback_path and projects_to_disable:
import_string(project_disable_callback_path)(workspace_id, projects_to_disable)

if attributes_to_be_created:
DestinationAttribute.objects.bulk_create(attributes_to_be_created, batch_size=50)

Expand Down
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.32.3',
version='1.33.0',
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 72da0bc

Please sign in to comment.