diff --git a/apps/qbd/models.py b/apps/qbd/models.py index 069ac74..7482e00 100644 --- a/apps/qbd/models.py +++ b/apps/qbd/models.py @@ -16,14 +16,14 @@ def get_item_and_account_name(field_mapping: FieldMapping, expense: Expense): item_type = field_mapping.item_type expense_item = None - expense_category = expense.get('category') + expense_category = expense.category if item_type.upper() in ['PROJECT', 'COST_CENTER']: - expense_item = expense.get(item_type.lower()) + expense_item = getattr(field_mapping, item_type.lower()) else: # Modify item_type to match the format in custom_properties modified_item_type = item_type.replace('_', ' ').title() - expense_item = expense.get('custom_properties', {}).get(modified_item_type) + expense_item = getattr(expense, 'custom_properties', {}).get(modified_item_type) if item_type and expense_item and expense_category: item_mapped_account = QBDMapping.objects.filter(attribute_type=modified_item_type, source_value=expense_item).first() diff --git a/tests/conftest.py b/tests/conftest.py index 7838d25..7122a27 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -211,6 +211,8 @@ def add_field_mappings(): workspace_id=workspace_id, class_type='COST_CENTER' if workspace_id in [1, 2] else 'PROJECT', project_type='PROJECT' if workspace_id in [1, 2] else 'COST_CENTER', + item_type='ITEM_TYPE_1' if workspace_id == 1 else 'ITEM_TYPE_2' if workspace_id == 2 else 'ITEM_TYPE_3', + custom_fields=['custom_field_1', 'custom_field_2'] if workspace_id in [1, 2] else ['custom_field_3', 'custom_field_4'], )