Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/sage_intacct/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ def post_charge_card_transaction(
charge_card_transaction_payload = construct_charge_card_transaction_payload(
workspace_id=self.workspace_id,
charge_card_transaction=charge_card_transaction,
charge_card_transaction_lineitems=charge_card_transaction_line_items
charge_card_transaction_line_items=charge_card_transaction_line_items
)
charge_card_transaction_payload['txnDate'] = first_day_of_month.strftime('%Y-%m-%d')
created_charge_card_transaction = self.connection.charge_card_transactions.post(charge_card_transaction_payload)
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ services:
FYLE_REFRESH_TOKEN: 'sample.sample.sample'
SI_SENDER_PASSWORD: 'sample'
SI_SENDER_ID: 'sample'
INTACCT_CLIENT_ID: 'sample_client_id'
INTACCT_CLIENT_SECRET: 'sample_client_secret'
ENCRYPTION_KEY: ${ENCRYPTION_KEY}
INTEGRATIONS_SETTINGS_API: http://localhost:8006/api
FYLE_TOKEN_URI: 'https://sample.fyle.tech'
Expand Down
2 changes: 2 additions & 0 deletions fyle_intacct_api/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@
FYLE_SERVER_URL = os.environ.get('FYLE_SERVER_URL')
SI_SENDER_ID = os.environ.get('SI_SENDER_ID')
SI_SENDER_PASSWORD = os.environ.get('SI_SENDER_PASSWORD')
INTACCT_CLIENT_ID = os.environ.get('INTACCT_CLIENT_ID')
INTACCT_CLIENT_SECRET = os.environ.get('INTACCT_CLIENT_SECRET')
INTEGRATIONS_SETTINGS_API = os.environ.get('INTEGRATIONS_SETTINGS_API')
INTACCT_INTEGRATION_APP_URL = os.environ.get('INTACCT_INTEGRATION_APP_URL')
INTEGRATIONS_APP_URL = os.environ.get('INTEGRATIONS_APP_URL')
Expand Down
139 changes: 137 additions & 2 deletions tests/test_sageintacct/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pytest
from unittest import mock

from datetime import datetime

from fyle_accounting_mappings.models import ExpenseAttribute, DestinationAttribute

from apps.tasks.models import TaskLog
from apps.mappings.models import GeneralMapping
from apps.workspaces.models import Configuration
from apps.workspaces.models import Configuration, Workspace, IntacctSyncedTimestamp
from apps.fyle.models import (
Expense,
ExpenseGroup,
Expand All @@ -25,7 +26,8 @@
ChargeCardTransactionLineitem,
APPayment,
APPaymentLineitem,
CostType
CostType,
SageIntacctAttributesCount,
)


Expand Down Expand Up @@ -341,3 +343,136 @@ def add_project_mappings(db):
active=True,
code='10064'
)


@pytest.fixture
def mock_intacct_sdk():
"""Mock the IntacctRESTSDK"""
with mock.patch('apps.sage_intacct.connector.IntacctRESTSDK') as mock_sdk:
mock_instance = mock.Mock()
mock_instance.access_token = 'mock_access_token'
mock_instance.access_token_expires_in = 21600
mock_sdk.return_value = mock_instance
yield mock_sdk, mock_instance


@pytest.fixture
def mock_sage_intacct_sdk():
"""Mock the SageIntacctSDK"""
with mock.patch('apps.sage_intacct.connector.SageIntacctSDK') as mock_sdk:
mock_instance = mock.Mock()
mock_sdk.return_value = mock_instance
yield mock_sdk, mock_instance


@pytest.fixture
def create_intacct_synced_timestamp(db):
"""Create IntacctSyncedTimestamp for workspace_id=1"""
timestamp, _ = IntacctSyncedTimestamp.objects.get_or_create(
workspace_id=1,
defaults={
'account_synced_at': None,
'vendor_synced_at': None,
'customer_synced_at': None,
'class_synced_at': None,
'employee_synced_at': None,
'item_synced_at': None,
'location_synced_at': None,
'department_synced_at': None,
'project_synced_at': None,
'expense_type_synced_at': None,
'location_entity_synced_at': None,
'payment_account_synced_at': None,
'expense_payment_type_synced_at': None,
'allocation_synced_at': None,
'tax_detail_synced_at': None,
}
)
return timestamp


@pytest.fixture
def create_sage_intacct_attributes_count(db):
"""Create SageIntacctAttributesCount for workspace_id=1"""
workspace = Workspace.objects.get(id=1)
count, _ = SageIntacctAttributesCount.objects.get_or_create(
workspace=workspace,
defaults={
'accounts_count': 0,
'vendors_count': 0,
}
)
return count


@pytest.fixture
def create_existing_vendor_attribute(db):
"""Create an existing VENDOR DestinationAttribute for testing"""
attribute = DestinationAttribute.objects.create(
workspace_id=1,
attribute_type='VENDOR',
value='Existing Vendor',
destination_id='VND_EXISTING',
active=True
)
return attribute


@pytest.fixture
def create_tax_detail_attribute(db):
"""
Create TAX_DETAIL DestinationAttribute for tax calculations
"""
workspace_id = 1

attribute = DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='TAX_DETAIL',
display_name='Tax Detail',
value='GST 10%',
destination_id='TAX001',
detail={'tax_rate': 10},
active=True
)

return attribute


@pytest.fixture
def create_tax_detail_with_solution_id(db):
"""
Create TAX_DETAIL DestinationAttribute with tax_solution_id
"""
workspace_id = 1

attribute = DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='TAX_DETAIL',
display_name='Tax Detail',
value='TestTaxCode',
destination_id='TAX_TEST',
detail={'tax_solution_id': 'TAX_SOL_001'},
active=True
)

return attribute


@pytest.fixture
def create_allocation_attribute(db):
"""
Create ALLOCATION DestinationAttribute for allocation tests
"""
workspace_id = 1

attribute = DestinationAttribute.objects.create(
workspace_id=workspace_id,
attribute_type='ALLOCATION',
display_name='Allocation',
value='ALLOC001',
destination_id='ALLOC001',
detail={'location': 'LOC001', 'department': 'DEPT001'},
active=True
)

return attribute
Empty file.
92 changes: 92 additions & 0 deletions tests/test_sageintacct/exports/test_ap_payments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from datetime import datetime

from apps.sage_intacct.exports.ap_payments import construct_ap_payment_payload
from tests.test_sageintacct.fixtures import data


def test_construct_ap_payment_payload(db, create_ap_payment):
"""
Test construct_ap_payment_payload creates correct payload
"""
workspace_id = 1
ap_payment, ap_payment_lineitems = create_ap_payment

payloads = construct_ap_payment_payload(
workspace_id=workspace_id,
ap_payment=ap_payment,
ap_payment_line_items=ap_payment_lineitems
)

assert payloads is not None
assert len(payloads) == len(ap_payment_lineitems)

for payload in payloads:
for key in data['ap_payment_payload_expected_keys']:
assert key in payload
assert payload['financialEntity']['id'] == ap_payment.payment_account_id
assert payload['baseCurrency']['currency'] == ap_payment.currency
assert payload['txnCurrency']['currency'] == ap_payment.currency
assert payload['paymentMethod'] == 'Cash'
assert payload['vendor']['id'] == ap_payment.vendor_id


def test_construct_ap_payment_payload_details(db, create_ap_payment):
"""
Test construct_ap_payment_payload creates correct details structure
"""
workspace_id = 1
ap_payment, ap_payment_lineitems = create_ap_payment

payloads = construct_ap_payment_payload(
workspace_id=workspace_id,
ap_payment=ap_payment,
ap_payment_line_items=ap_payment_lineitems
)

for i, payload in enumerate(payloads):
details = payload['details']
assert len(details) == 1

detail = details[0]
for key in data['ap_payment_detail_expected_keys']:
assert key in detail
assert detail['txnCurrency']['paymentAmount'] == str(ap_payment_lineitems[i].amount)
assert detail['bill']['key'] == ap_payment_lineitems[i].record_key


def test_construct_ap_payment_payload_payment_date(db, create_ap_payment):
"""
Test construct_ap_payment_payload has today's date as payment date
"""
workspace_id = 1
ap_payment, ap_payment_lineitems = create_ap_payment

payloads = construct_ap_payment_payload(
workspace_id=workspace_id,
ap_payment=ap_payment,
ap_payment_line_items=ap_payment_lineitems
)

today_date = datetime.today().strftime('%Y-%m-%d')

for payload in payloads:
assert payload['paymentDate'] == today_date


def test_construct_ap_payment_payload_multiple_line_items(db, create_ap_payment):
"""
Test construct_ap_payment_payload with multiple line items
"""
workspace_id = 1
ap_payment, ap_payment_lineitems = create_ap_payment

payloads = construct_ap_payment_payload(
workspace_id=workspace_id,
ap_payment=ap_payment,
ap_payment_line_items=ap_payment_lineitems
)

assert len(payloads) == len(ap_payment_lineitems)

for i, payload in enumerate(payloads):
assert payload['details'][0]['bill']['key'] == ap_payment_lineitems[i].record_key
Loading
Loading