|
3 | 3 | * User Triggered Async Tasks |
4 | 4 | * Schedule Triggered Async Tasks |
5 | 5 | """ |
| 6 | +import logging |
6 | 7 | from django_q.tasks import async_task |
7 | 8 | from apps.fyle.tasks import ( |
8 | 9 | import_credit_card_expenses, |
9 | 10 | import_reimbursable_expenses |
10 | 11 | ) |
11 | 12 | from apps.workspaces.models import Workspace |
12 | 13 | from apps.tasks.models import AccountingExport |
| 14 | +from apps.fyle.helpers import assert_valid_request |
| 15 | + |
| 16 | +logger = logging.getLogger(__name__) |
| 17 | +logger.level = logging.INFO |
13 | 18 |
|
14 | 19 |
|
15 | 20 | def queue_import_reimbursable_expenses(workspace_id: int, synchronous: bool = False): |
@@ -60,14 +65,20 @@ def queue_import_credit_card_expenses(workspace_id: int, synchronous: bool = Fal |
60 | 65 | import_credit_card_expenses(workspace_id, accounting_export) |
61 | 66 |
|
62 | 67 |
|
63 | | -def async_handle_webhook_callback(body: dict) -> None: |
| 68 | +def async_handle_webhook_callback(body: dict, workspace_id: int) -> None: |
64 | 69 | """ |
65 | 70 | Async'ly import and export expenses |
66 | | - :param body: bodys |
| 71 | + :param body: body |
67 | 72 | :return: None |
68 | 73 | """ |
69 | 74 | if body.get('action') == 'ACCOUNTING_EXPORT_INITIATED' and body.get('data'): |
70 | 75 | org_id = body['data']['org_id'] |
71 | | - |
| 76 | + assert_valid_request(workspace_id=workspace_id, org_id=org_id) |
72 | 77 | workspace = Workspace.objects.get(org_id=org_id) |
73 | 78 | async_task('apps.workspaces.tasks.run_import_export', workspace.id) |
| 79 | + |
| 80 | + elif body.get('action') == 'UPDATED_AFTER_APPROVAL' and body.get('data') and body.get('resource') == 'EXPENSE': |
| 81 | + org_id = body['data']['org_id'] |
| 82 | + logger.info("| Updating non-exported expenses through webhook | Content: {{WORKSPACE_ID: {} Payload: {}}}".format(workspace_id, body.get('data'))) |
| 83 | + assert_valid_request(workspace_id=workspace_id, org_id=org_id) |
| 84 | + async_task('apps.fyle.tasks.update_non_exported_expenses', body['data']) |
0 commit comments