Skip to content

Commit

Permalink
added more actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Sep 12, 2024
1 parent 5f33e7a commit af12a54
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions apps/spotlight/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from . import llm



@dataclass
class ActionResponse:
message: str = None
Expand Down Expand Up @@ -71,7 +70,11 @@ def _get_action_function_from_code(cls, *, code: str) -> Callable:
"set_customer_field_mapping_to_project": cls.set_customer_field_mapping_to_project,
"set_customer_field_mapping_to_cost_center": cls.set_customer_field_mapping_to_cost_center,
"set_class_field_mapping_to_project": cls.set_class_field_mapping_to_project,
"set_class_field_mapping_to_cost_center": cls.set_class_field_mapping_to_cost_center
"set_class_field_mapping_to_cost_center": cls.set_class_field_mapping_to_cost_center,
"set_corporate_credit_card_expenses_export_credit_card_purchase": cls.set_cc_export_to_corporate_card_purchase,
"set_corporate_credit_card_expenses_export_journal_entry": cls.set_cc_export_to_journal_entry,
"set_corporate_credit_card_expenses_export_grouping_report": cls.set_cc_grouping_to_report,
"set_corporate_credit_card_expenses_export_grouping_expense": cls.set_cc_grouping_to_expense,
}
return code_to_function_map[code]

Expand Down Expand Up @@ -127,6 +130,60 @@ def trigger_export(cls, *, workspace_id: int):
return ActionResponse(message="Export triggered successfully", is_success=True)
return ActionResponse(message="Export triggered failed", is_success=False)


@classmethod
def set_cc_export_to_corporate_card_purchase(cls, *, workspace_id: int):
with transaction.atomic():
export_settings = ExportSettings.objects.filter(workspace_id=workspace_id).first()
if export_settings:
export_settings.credit_card_expense_export_type = 'CREDIT_CARD_PURCHASE'
export_settings.save()
return ActionResponse(message="Successfully set corporate card expense as Credit Card Purchase", is_success=True)

return ActionResponse(message="Export settings doesn't exists!", is_success=False)


@classmethod
def set_cc_export_to_journal_entry(cls, *, workspace_id: int):
with transaction.atomic():
export_settings = ExportSettings.objects.filter(workspace_id=workspace_id).first()
if export_settings:
export_settings.credit_card_expense_export_type = 'JOURNAL_ENTRY'
export_settings.save()
return ActionResponse(message="Successfully set corporate card expense as JOURNAL ENTRY", is_success=True)

return ActionResponse(message="Export settings doesn't exists!", is_success=False)

@classmethod
def set_cc_grouping_to_report(cls, *, workspace_id: int):
with transaction.atomic():
export_settings = ExportSettings.objects.filter(workspace_id=workspace_id).first()
if export_settings:
if export_settings.credit_card_expense_export_type == 'CREDIT_CARD_PURCHASE':
return ActionResponse(message='For Corporate Credit Purchase Export type expenses cannot be grouped by report', is_success=False)
else:
export_settings.credit_card_expense_grouped_by = 'REPORT'
export_settings.save()
return ActionResponse(message='Succesfully set corporate card group by to Report', is_success=True)

return ActionResponse(message="Export settings doesn't exists!", is_success=False)


@classmethod
def set_cc_grouping_to_expense(cls, *, workspace_id: int):
with transaction.atomic():
export_settings = ExportSettings.objects.filter(workspace_id=workspace_id).first()
if export_settings:
if export_settings.credit_card_expense_export_type == 'CREDIT_CARD_PURCHASE':
return ActionResponse(message='Already set to expense', is_success=True)
else:
export_settings.credit_card_expense_grouped_by = 'EXPENSE'
export_settings.save()
return ActionResponse(message='Succesfully set corporate card group by to EXPENSE', is_success=True)

return ActionResponse(message="Export settings doesn't exists!", is_success=False)


@classmethod
def set_customer_field_mapping_to_project(cls, *, workspace_id: int):
access_token = cls.get_access_token(workspace_id=workspace_id)
Expand Down

0 comments on commit af12a54

Please sign in to comment.