Skip to content

Commit

Permalink
fix: handle post accounting export (#675)
Browse files Browse the repository at this point in the history
* fix: handle post accounting export

* Add tests

---------

Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
ruuushhh and GitHub Actions authored Sep 27, 2024
1 parent 7d8ef97 commit 6554347
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
29 changes: 22 additions & 7 deletions apps/quickbooks_online/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
from typing import List

from django.db import transaction
from fyle_qbo_api.logging_middleware import get_logger
from apps.fyle.helpers import get_filter_credit_expenses
from fyle_accounting_mappings.models import DestinationAttribute, EmployeeMapping, ExpenseAttribute, Mapping
from fyle_integrations_platform_connector import PlatformConnector
from qbosdk.exceptions import InvalidTokenError, WrongParamsError

from apps.fyle.actions import update_expenses_in_progress
from apps.fyle.helpers import get_filter_credit_expenses
from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings
from apps.fyle.tasks import post_accounting_export_summary
from apps.mappings.models import GeneralMapping
Expand All @@ -35,6 +34,7 @@
from apps.tasks.models import Error, TaskLog
from apps.workspaces.models import FyleCredential, QBOCredential, Workspace, WorkspaceGeneralSettings
from fyle_qbo_api.exceptions import BulkError
from fyle_qbo_api.logging_middleware import get_logger

logger = logging.getLogger(__name__)
logger.level = logging.INFO
Expand Down Expand Up @@ -220,7 +220,10 @@ def create_bill(expense_group, task_log_id, last_export: bool):
if last_export:
update_last_export_details(expense_group.workspace_id)

generate_export_url_and_update_expense(expense_group)
try:
generate_export_url_and_update_expense(expense_group)
except Exception as e:
logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e)
logger.info('Updated Expense Group %s successfully', expense_group.id)

load_attachments(qbo_connection, created_bill['Bill']['Id'], 'Bill', expense_group)
Expand Down Expand Up @@ -397,7 +400,10 @@ def create_cheque(expense_group, task_log_id, last_export: bool):
if last_export:
update_last_export_details(expense_group.workspace_id)

generate_export_url_and_update_expense(expense_group)
try:
generate_export_url_and_update_expense(expense_group)
except Exception as e:
logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e)
worker_logger.info('Updated Expense Group %s successfully', expense_group.id)

load_attachments(qbo_connection, created_cheque['Purchase']['Id'], 'Purchase', expense_group)
Expand Down Expand Up @@ -456,7 +462,10 @@ def create_qbo_expense(expense_group, task_log_id, last_export: bool):
if last_export:
update_last_export_details(expense_group.workspace_id)

generate_export_url_and_update_expense(expense_group)
try:
generate_export_url_and_update_expense(expense_group)
except Exception as e:
logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e)
worker_logger.info('Updated Expense Group %s successfully', expense_group.id)

load_attachments(qbo_connection, created_qbo_expense['Purchase']['Id'], 'Purchase', expense_group)
Expand Down Expand Up @@ -514,7 +523,10 @@ def create_credit_card_purchase(expense_group: ExpenseGroup, task_log_id, last_e
if last_export:
update_last_export_details(expense_group.workspace_id)

generate_export_url_and_update_expense(expense_group)
try:
generate_export_url_and_update_expense(expense_group)
except Exception as e:
logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e)
worker_logger.info('Updated Expense Group %s successfully', expense_group.id)

load_attachments(qbo_connection, created_credit_card_purchase['Purchase']['Id'], 'Purchase', expense_group)
Expand Down Expand Up @@ -570,7 +582,10 @@ def create_journal_entry(expense_group, task_log_id, last_export: bool):
if last_export:
update_last_export_details(expense_group.workspace_id)

generate_export_url_and_update_expense(expense_group)
try:
generate_export_url_and_update_expense(expense_group)
except Exception as e:
logger.error('Error while updating expenses for expense_group_id: %s and posting accounting export summary %s', expense_group.id, e)
worker_logger.info('Updated Expense Group %s successfully', expense_group.id)

load_attachments(qbo_connection, created_journal_entry['JournalEntry']['Id'], 'JournalEntry', expense_group)
Expand Down
8 changes: 5 additions & 3 deletions tests/test_quickbooks_online/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import json
import logging
from datetime import datetime
import random
from datetime import datetime
from unittest import mock

from django_q.models import Schedule
from fyle_accounting_mappings.models import DestinationAttribute, EmployeeMapping, ExpenseAttribute, Mapping
from apps.quickbooks_online.models import CreditCardPurchaseLineitem
from qbosdk.exceptions import WrongParamsError

from apps.fyle.models import Expense, ExpenseGroup, Reimbursement
from apps.mappings.queues import schedule_bill_payment_creation
from apps.quickbooks_online.exceptions import handle_quickbooks_error
from apps.quickbooks_online.models import CreditCardPurchaseLineitem
from apps.quickbooks_online.queue import (
schedule_bills_creation,
schedule_cheques_creation,
Expand Down Expand Up @@ -900,9 +900,11 @@ def test_process_reimbursements(db, mocker):

reimbursements = data['reimbursements']

expenses = Expense.objects.filter(fund_source='PERSONAL')
expenses = Expense.objects.filter(fund_source='PERSONAL', org_id='or79Cob97KSh').all()
for expense in expenses:
expense.paid_on_qbo = True
expense.paid_on_fyle = False
expense.workspace_id = workspace_id
expense.save()

Reimbursement.create_or_update_reimbursement_objects(reimbursements=reimbursements, workspace_id=workspace_id)
Expand Down

0 comments on commit 6554347

Please sign in to comment.