From 1f32f8d22a3eab19a6fb936e92bafc8faaaea955 Mon Sep 17 00:00:00 2001 From: Nilesh Date: Mon, 1 Apr 2024 12:38:55 +0530 Subject: [PATCH] use .get method instead of Index brackets --- apps/sage300/dependent_fields.py | 14 ++++++++------ apps/sage300/utils.py | 17 +++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/apps/sage300/dependent_fields.py b/apps/sage300/dependent_fields.py index 3186b798..77211c82 100644 --- a/apps/sage300/dependent_fields.py +++ b/apps/sage300/dependent_fields.py @@ -93,9 +93,11 @@ def post_dependent_cost_code(dependent_field_setting: DependentFieldSetting, pla 'expense_field_value': cost_code, 'is_enabled': True }) - sleep(0.2) - platform.dependent_fields.bulk_post_dependent_expense_field_values(payload) - posted_cost_codes.append(cost_code) + + if payload: + sleep(0.2) + platform.dependent_fields.bulk_post_dependent_expense_field_values(payload) + posted_cost_codes.append(cost_code) return posted_cost_codes @@ -127,11 +129,11 @@ def post_dependent_expense_field_values(workspace_id: int, dependent_field_setti 'workspace_id': workspace_id } - if dependent_field_setting.last_successful_import_at: - filters['updated_at__gte'] = dependent_field_setting.last_successful_import_at + # if dependent_field_setting.last_successful_import_at: + # filters['updated_at__gte'] = dependent_field_setting.last_successful_import_at posted_cost_types = post_dependent_cost_code(dependent_field_setting, platform, filters) - + print('postted cost tyoes', posted_cost_types) if posted_cost_types: filters['cost_code_name__in'] = posted_cost_types post_dependent_cost_type(dependent_field_setting, platform, filters) diff --git a/apps/sage300/utils.py b/apps/sage300/utils.py index 19220597..8366d103 100644 --- a/apps/sage300/utils.py +++ b/apps/sage300/utils.py @@ -79,14 +79,15 @@ def _sync_data(self, data, attribute_type, display_name, workspace_id, field_nam destination_attributes = [] for item in data: detail = {field: getattr(item, field) for field in field_names} - destination_attributes.append(self._create_destination_attribute( - attribute_type, - display_name, - item.name, - item.id, - item.is_active, - detail - )) + if item.name: + destination_attributes.append(self._create_destination_attribute( + attribute_type, + display_name, + item.name, + item.id, + item.is_active, + detail + )) DestinationAttribute.bulk_create_or_update_destination_attributes( destination_attributes, attribute_type, workspace_id, True)