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

Corporate card slack notification bug fix #116

Merged
merged 6 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions fyle_slack_app/fyle/corporate_cards/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ def get_corporate_card_by_id(self, corporate_card_id: str) -> Dict:
response = self.connection.v1beta.spender.corporate_cards.list(query_params=query_params)
corporate_card = response['data'] if response['count'] == 1 else None
return corporate_card

def get_corporate_card_transaction(self, corporate_card_id: str) -> Dict:
query_params = {
'id': 'eq.{}'.format(corporate_card_id),
'order': 'created_at.desc',
'limit': '1',
'offset': '0'
}
response = self.connection.v1beta.admin.corporate_card_transactions.list(query_params=query_params)
corporate_card_transaction = response['data'][0]
return corporate_card_transaction
9 changes: 6 additions & 3 deletions fyle_slack_app/fyle/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,20 @@ def handle_expense_commented(self, webhook_data: Dict, user: User, slack_client:
def handle_expense_mandatory_receipt_missing(self, webhook_data: Dict, user: User, slack_client: WebClient) -> JsonResponse:
expense = webhook_data['data']

corporate_card_id = expense['matched_corporate_card_transactions'][0]['corporate_card_id']
corporate_card_id = list(expense['matched_corporate_card_transaction_ids'])[0]

corporate_card_transaction = FyleCorporateCard(user).get_corporate_card_transaction(corporate_card_id)

# Fetch corporate card
card = FyleCorporateCard(user).get_corporate_card_by_id(corporate_card_id)
card = FyleCorporateCard(user).get_corporate_card_by_id(corporate_card_transaction['corporate_card_id'])

if card and card[0] and card[0]['is_visa_enrolled'] is True:
expense_url = fyle_utils.get_fyle_resource_url(user.fyle_refresh_token, expense, 'EXPENSE')

card_expense_notification_message, title_text = notification_messages.get_expense_mandatory_receipt_missing_notification(
expense,
expense_url
expense_url,
corporate_card_transaction
)

slack_client.chat_postMessage(
Expand Down
8 changes: 4 additions & 4 deletions fyle_slack_app/slack/ui/notifications/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,10 @@ def get_card_expense_attach_receipt_action(expense_id: str) -> Dict:
return card_expense_attach_receipt_action


def get_card_expense_section_blocks(expense: Dict, title_text: str) -> List[Dict]:
def get_card_expense_section_blocks(expense: Dict, title_text: str, corporate_card_transaction: Dict) -> List[Dict]:

readable_spend_date = utils.get_formatted_datetime(expense['spent_at'], '%B %d, %Y')
card_number = expense['matched_corporate_card_transactions'][0]['corporate_card_number']
card_number = corporate_card_transaction['corporate_card']['card_number']
card_number_last_4_digits = card_number[-4:]
card_details = 'Ending {} (VISA)'.format(card_number_last_4_digits)

Expand Down Expand Up @@ -552,7 +552,7 @@ def get_card_expense_section_blocks(expense: Dict, title_text: str) -> List[Dict
return card_expense_section_block


def get_expense_mandatory_receipt_missing_notification(expense: Dict, expense_url: str) -> List[Dict]:
def get_expense_mandatory_receipt_missing_notification(expense: Dict, expense_url: str, corporate_card_transaction: Dict) -> List[Dict]:

display_amount = slack_utils.get_display_amount(expense['amount'], expense['currency'])

Expand All @@ -565,7 +565,7 @@ def get_expense_mandatory_receipt_missing_notification(expense: Dict, expense_ur
'elements': []
}

card_expense_section_block = get_card_expense_section_blocks(expense, title_text)
card_expense_section_block = get_card_expense_section_blocks(expense, title_text, corporate_card_transaction)

attach_receipt_section = get_card_expense_attach_receipt_action(expense['id'])
actions_block['elements'].append(attach_receipt_section)
Expand Down
Loading