Skip to content

Commit

Permalink
ccc mapping commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyle authored and Fyle committed Sep 20, 2023
1 parent 158846c commit d493d2a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
17 changes: 16 additions & 1 deletion apps/qbd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
AdvancedSetting, ExportSettings, FieldMapping,
FyleCredential, Workspace
)
from apps.mappings.models import QBDMapping


def get_class_and_project_name(field_mappings: FieldMapping, expense: Expense):
Expand Down Expand Up @@ -125,6 +126,18 @@ def get_top_purpose(workspace_id: str, expense: Expense, default: str) -> str:
return memo


def get_corporate_card_name(corporate_card_id: str, workspace_id: int, export_settings: ExportSettings):
corporate_card_name = export_settings.credit_card_account_name

qbd_mapping = QBDMapping.objects.filter(workspace_id=workspace_id, source_id=corporate_card_id)

if len(qbd_mapping) > 0 and qbd_mapping[0].destination_value:
corporate_card_name = qbd_mapping[0].destination_value

return corporate_card_name



class Bill(models.Model):
"""
Bills Table Model Class
Expand Down Expand Up @@ -386,13 +399,15 @@ def create_credit_card_purchase(

date_preference = export_settings.credit_card_expense_date

corporate_card_name = get_corporate_card_name(expenses[0].corporate_card_id, workspace_id, export_settings)

if export_settings.credit_card_entity_name_preference == 'EMPLOYEE':
name = expenses[0].employee_name

credit_card_purchase = CreditCardPurchase.objects.create(
transaction_type='CREDIT CARD',
date=get_transaction_date(expenses, date_preference),
account=export_settings.credit_card_account_name,
account=corporate_card_name,
name=name,
class_name='',
amount=sum([expense.amount for expense in expenses]) * -1,
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
AdvancedSetting
)
from apps.tasks.models import AccountingExport
from apps.mappings.models import QBDMapping
from quickbooks_desktop_api.tests import settings

from .test_fyle.fixtures import fixtures as fyle_fixtures
from .test_mapping.fixture import fixture as mapping_fixtures


@pytest.fixture
Expand Down Expand Up @@ -268,3 +270,16 @@ def add_expenses():
expense['id'] = expense['id'] + str(workspace_id)

Expense.create_expense_objects(expenses, workspace_id)


@pytest.fixture()
@pytest.mark.django_db(databases=['default'])
def add_ccc_mapping():
"""
Add Expense to a workspace
"""
mappings = mapping_fixtures['create_qbd_mapping']

for workspace_id in [1, 2, 3]:
QBDMapping.update_or_create_mapping_objects(mappings, workspace_id)

15 changes: 8 additions & 7 deletions tests/test_qbd/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_create_credit_card_purchases_iif_file_expense_vendor(
create_temp_workspace, add_accounting_export_bills,
add_accounting_export_expenses, add_fyle_credentials,
add_export_settings, add_field_mappings, add_advanced_settings,
mocker
add_ccc_mapping, mocker
):
"""
Test create credit card purchases iif file
Expand Down Expand Up @@ -321,7 +321,7 @@ def test_create_credit_card_purchases_iif_file_expense_employee(
create_temp_workspace, add_accounting_export_bills,
add_accounting_export_expenses, add_fyle_credentials,
add_export_settings, add_field_mappings, add_advanced_settings,
mocker
add_ccc_mapping, mocker
):
"""
Test create credit card purchases iif file
Expand Down Expand Up @@ -380,9 +380,10 @@ def test_create_credit_card_purchases_iif_file_expense_employee(

@pytest.mark.django_db(databases=['default'])
def test_create_credit_card_purchases_iif_file_expense_fail(
create_temp_workspace, add_accounting_export_bills,
add_accounting_export_expenses, add_fyle_credentials,
add_export_settings, add_advanced_settings, mocker
create_temp_workspace, add_accounting_export_bills,
add_accounting_export_expenses, add_fyle_credentials,
add_export_settings, add_advanced_settings,
add_ccc_mapping, mocker
):
"""
Test create credit card purchases iif file
Expand Down Expand Up @@ -435,7 +436,7 @@ def test_create_credit_card_purchases_iif_file_expense_fatal(
create_temp_workspace, add_accounting_export_bills,
add_accounting_export_expenses, add_fyle_credentials,
add_export_settings, add_field_mappings, add_advanced_settings,
mocker
add_ccc_mapping, mocker
):
"""
Test create credit card purchases iif file
Expand Down Expand Up @@ -785,7 +786,7 @@ def test_email_failure(
create_temp_workspace, add_accounting_export_bills,
add_accounting_export_expenses, add_fyle_credentials,
add_export_settings, add_field_mappings, add_advanced_settings,
mocker
add_ccc_mapping, mocker
):
"""
Test create journals iif file Failed for email failure
Expand Down

0 comments on commit d493d2a

Please sign in to comment.