Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor background task completed #449

Merged
merged 8 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions apps/mappings/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from fyle_accounting_mappings.models import MappingSetting, Mapping, EmployeeMapping

from apps.tasks.models import Error
from apps.mappings.tasks import upload_attributes_to_fyle, schedule_cost_centers_creation,\
ruuushhh marked this conversation as resolved.
Show resolved Hide resolved
schedule_fyle_attributes_creation
from fyle_qbo_api.queue import schedule_cost_centers_creation, schedule_fyle_attributes_creation
from apps.mappings.tasks import upload_attributes_to_fyle
from apps.workspaces.utils import delete_cards_mapping_settings
from apps.workspaces.models import WorkspaceGeneralSettings

Expand Down
118 changes: 0 additions & 118 deletions apps/mappings/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
import traceback
from django.db.models import Q
from dateutil import parser
from datetime import datetime, timedelta

from typing import List, Dict

from django_q.models import Schedule
from django_q.tasks import Chain

from qbosdk.exceptions import WrongParamsError as QBOWrongParamsError, InvalidTokenError

from fyle.platform.exceptions import WrongParamsError, InvalidTokenError as FyleInvalidTokenError
from fyle_integrations_platform_connector import PlatformConnector
from fyle_accounting_mappings.models import MappingSetting, Mapping, DestinationAttribute, ExpenseAttribute,\
Expand Down Expand Up @@ -275,27 +270,6 @@ def auto_create_project_mappings(workspace_id: int):
post_projects_in_batches(platform, workspace_id, mapping_setting.destination_field)


def schedule_tax_groups_creation(import_tax_codes, workspace_id):
if import_tax_codes:
schedule, _ = Schedule.objects.update_or_create(
func='apps.mappings.tasks.auto_create_tax_codes_mappings',
args='{}'.format(workspace_id),
defaults={
'schedule_type': Schedule.MINUTES,
'minutes': 24 * 60,
'next_run': datetime.now()
}
)
else:
schedule: Schedule = Schedule.objects.filter(
func='apps.mappings.tasks.auto_create_tax_codes_mappings',
args='{}'.format(workspace_id),
).first()

if schedule:
schedule.delete()


def create_fyle_categories_payload(categories: List[DestinationAttribute], workspace_id: int,
updated_categories: List[ExpenseAttribute] = None):
"""
Expand Down Expand Up @@ -620,28 +594,6 @@ def async_auto_map_employees(workspace_id: int):
destination_attribute_type=destination_type
)

def schedule_auto_map_employees(employee_mapping_preference: str, workspace_id: int):
if employee_mapping_preference:
start_datetime = datetime.now()

schedule, _ = Schedule.objects.update_or_create(
func='apps.mappings.tasks.async_auto_map_employees',
args='{0}'.format(workspace_id),
defaults={
'schedule_type': Schedule.MINUTES,
'minutes': 24 * 60,
'next_run': start_datetime
}
)
else:
schedule: Schedule = Schedule.objects.filter(
func='apps.mappings.tasks.async_auto_map_employees',
args='{}'.format(workspace_id)
).first()

if schedule:
schedule.delete()


def auto_map_ccc_employees(default_ccc_account_id: str, workspace_id: int):
"""
Expand Down Expand Up @@ -706,31 +658,6 @@ def async_auto_map_ccc_account(workspace_id: int):
auto_map_ccc_employees(default_ccc_account_id, workspace_id)


def schedule_auto_map_ccc_employees(workspace_id: int):
general_settings = WorkspaceGeneralSettings.objects.get(workspace_id=workspace_id)

if general_settings.auto_map_employees and general_settings.corporate_credit_card_expenses_object != 'BILL':
start_datetime = datetime.now()

schedule, _ = Schedule.objects.update_or_create(
func='apps.mappings.tasks.async_auto_map_ccc_account',
args='{0}'.format(workspace_id),
defaults={
'schedule_type': Schedule.MINUTES,
'minutes': 24 * 60,
'next_run': start_datetime
}
)
else:
schedule: Schedule = Schedule.objects.filter(
func='apps.mappings.tasks.async_auto_map_ccc_account',
args='{}'.format(workspace_id)
).first()

if schedule:
schedule.delete()


def upload_tax_groups_to_fyle(platform_connection: PlatformConnector, workspace_id: int):
existing_tax_codes_name = ExpenseAttribute.objects.filter(
attribute_type='TAX_GROUP', workspace_id=workspace_id).values_list('value', flat=True)
Expand Down Expand Up @@ -859,27 +786,6 @@ def auto_create_cost_center_mappings(workspace_id):
post_cost_centers_in_batches(platform, workspace_id, mapping_setting.destination_field)


def schedule_cost_centers_creation(import_to_fyle, workspace_id):
if import_to_fyle:
schedule, _ = Schedule.objects.update_or_create(
func='apps.mappings.tasks.auto_create_cost_center_mappings',
args='{}'.format(workspace_id),
defaults={
'schedule_type': Schedule.MINUTES,
'minutes': 24 * 60,
'next_run': datetime.now()
}
)
else:
schedule: Schedule = Schedule.objects.filter(
func='apps.mappings.tasks.auto_create_cost_center_mappings',
args='{}'.format(workspace_id)
).first()

if schedule:
schedule.delete()


def create_fyle_expense_custom_field_payload(
qbo_attributes: List[DestinationAttribute], workspace_id: int,
fyle_attribute: str, platform: PlatformConnector, source_placeholder: str = None
Expand Down Expand Up @@ -1013,30 +919,6 @@ def async_auto_create_custom_field_mappings(workspace_id):
)


def schedule_fyle_attributes_creation(workspace_id: int):
mapping_settings = MappingSetting.objects.filter(
is_custom=True, import_to_fyle=True, workspace_id=workspace_id
).all()
if mapping_settings:
schedule, _ = Schedule.objects.get_or_create(
func='apps.mappings.tasks.async_auto_create_custom_field_mappings',
args='{0}'.format(workspace_id),
defaults={
'schedule_type': Schedule.MINUTES,
'minutes': 24 * 60,
'next_run': datetime.now() + timedelta(hours=24)
}
)
else:
schedule: Schedule = Schedule.objects.filter(
func='apps.mappings.tasks.async_auto_create_custom_field_mappings',
args='{0}'.format(workspace_id)
).first()

if schedule:
schedule.delete()


def create_fyle_merchants_payload(vendors, existing_merchants_name):
payload: List[str] = []
for vendor in vendors:
Expand Down
4 changes: 1 addition & 3 deletions apps/mappings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from django.db.models import Q

from apps.quickbooks_online.tasks import schedule_bill_payment_creation
from fyle_qbo_api.queue import schedule_bill_payment_creation, schedule_auto_map_ccc_employees
from apps.workspaces.models import WorkspaceGeneralSettings
from fyle_qbo_api.utils import assert_valid

from .tasks import schedule_auto_map_ccc_employees

from .models import GeneralMapping


Expand Down
Loading
Loading