Skip to content

Commit

Permalink
made changes to diff func
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Aug 28, 2024
1 parent 7cb8b68 commit 0e9e5e7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 27 deletions.
15 changes: 2 additions & 13 deletions apps/sage300/exports/direct_cost/queues.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone, timedelta
from datetime import datetime
from typing import List
import logging

Expand All @@ -8,7 +8,7 @@

from apps.accounting_exports.models import AccountingExport, Error
from apps.sage300.actions import update_accounting_export_summary
from apps.sage300.exports.helpers import resolve_errors_for_exported_accounting_export
from apps.sage300.exports.helpers import resolve_errors_for_exported_accounting_export, validate_failing_export
from apps.sage300.utils import SageDesktopConnector
from apps.workspaces.models import FyleCredential, Sage300Credential

Expand All @@ -17,17 +17,6 @@
logger.level = logging.INFO


def validate_failing_export(is_auto_export: bool, interval_hours: int, error: Error):
"""
Validate failing export
:param is_auto_export: Is auto export
:param interval_hours: Interval hours
:param error: Error
"""
# If auto export is enabled and interval hours is set and error repetition count is greater than 100, export only once a day
return is_auto_export and interval_hours and error and error.repetition_count > 100 and datetime.now().replace(tzinfo=timezone.utc) - error.updated_at <= timedelta(hours=24)


def check_accounting_export_and_start_import(workspace_id: int, accounting_export_ids: List[str], is_auto_export: bool, interval_hours: int):
"""
Check accounting export group and start export
Expand Down
12 changes: 12 additions & 0 deletions apps/sage300/exports/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itertools
from datetime import datetime, timedelta, timezone

from fyle_accounting_mappings.models import CategoryMapping, EmployeeMapping, ExpenseAttribute, Mapping

Expand Down Expand Up @@ -147,3 +148,14 @@ def resolve_errors_for_exported_accounting_export(accounting_export: AccountingE
:param accounting_export: Accounting Export
"""
Error.objects.filter(workspace_id=accounting_export.workspace_id, accounting_export=accounting_export, is_resolved=False).update(is_resolved=True)


def validate_failing_export(is_auto_export: bool, interval_hours: int, error: Error):
"""
Validate failing export
:param is_auto_export: Is auto export
:param interval_hours: Interval hours
:param error: Error
"""
# If auto export is enabled and interval hours is set and error repetition count is greater than 100, export only once a day
return is_auto_export and interval_hours and error and error.repetition_count > 100 and datetime.now().replace(tzinfo=timezone.utc) - error.updated_at <= timedelta(hours=24)
13 changes: 1 addition & 12 deletions apps/sage300/exports/purchase_invoice/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from apps.accounting_exports.models import AccountingExport, Error
from apps.sage300.actions import update_accounting_export_summary
from apps.sage300.exports.helpers import resolve_errors_for_exported_accounting_export
from apps.sage300.exports.helpers import resolve_errors_for_exported_accounting_export, validate_failing_export
from apps.sage300.exports.purchase_invoice.models import PurchaseInvoice, PurchaseInvoiceLineitems
from apps.sage300.utils import SageDesktopConnector
from apps.workspaces.models import FyleCredential, Sage300Credential
Expand All @@ -24,17 +24,6 @@ def import_fyle_dimensions(fyle_credentials: FyleCredential):
platform.import_fyle_dimensions()


def validate_failing_export(is_auto_export: bool, interval_hours: int, error: Error):
"""
Validate failing export
:param is_auto_export: Is auto export
:param interval_hours: Interval hours
:param error: Error
"""
# If auto export is enabled and interval hours is set and error repetition count is greater than 100, export only once a day
return is_auto_export and interval_hours and error and error.repetition_count > 100 and datetime.now().replace(tzinfo=timezone.utc) - error.updated_at <= timedelta(hours=24)


def check_accounting_export_and_start_import(workspace_id: int, accounting_export_ids: List[str], is_auto_export: bool, interval_hours: int):
"""
Check accounting export group and start export
Expand Down
4 changes: 2 additions & 2 deletions apps/workspaces/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def export_to_sage300(workspace_id: int):
accounting_summary = AccountingExportSummary.objects.get(workspace_id=workspace_id)
advance_settings = AdvancedSetting.objects.filter(workspace_id=workspace_id).first()

is_auto_export = advance_settings.schedule_is_enabled
interval_hours = advance_settings.interval_hours
is_auto_export = False
interval_hours = 0

# Set the timestamp for the last export
last_exported_at = datetime.now()
Expand Down

0 comments on commit 0e9e5e7

Please sign in to comment.