Skip to content

Commit

Permalink
Corporate card slack notification bug fix (#116)
Browse files Browse the repository at this point in the history
* Corporate card slack notification bug fix

* Comments fixed

* Comments fixed

* Comments fixed

* Comments fixed

* Comments fixed
  • Loading branch information
ruuushhh authored Aug 22, 2023
1 parent f80cbc1 commit e6883c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
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

0 comments on commit e6883c3

Please sign in to comment.