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

Fixed transaction dates in bank sync with MBANK_RETAIL_BREXPLPW #4493

Merged
merged 9 commits into from
Mar 4, 2025

Conversation

szymon-romanko
Copy link
Contributor

I've noticed while syncing with mBank Retail Poland (mbank_retail_brexplpw), that bookingDate and valueDate are swapped in their API.
When inspecting API response from gocardless, bookingDate would always come after valueDate, so I fixed it per bank by overwriting normalizeTransaction method in packages/sync-server/src/app-gocardless/banks/mbank_retail_brexplpw.js.

Copy link

netlify bot commented Mar 1, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 3853cd8
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67c6ed7291a83d0008264ec8
😎 Deploy Preview https://deploy-preview-4493.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@szymon-romanko szymon-romanko marked this pull request as ready for review March 1, 2025 13:09
@actual-github-bot actual-github-bot bot changed the title [WIP] Fixed transaction dates in bank sync with MBANK_RETAIL_BREXPLPW Fixed transaction dates in bank sync with MBANK_RETAIL_BREXPLPW Mar 1, 2025
Copy link
Contributor

coderabbitai bot commented Mar 1, 2025

Walkthrough

The pull request introduces a new method normalizeTransaction to the exported object in the mbank_retail_brexplpw.js file. This method addresses an issue with the GoCardless API where the bookingDate and valueDate are swapped. It takes two parameters: transaction and booked. The method creates a copy of the transaction object named editedTrans and determines the correct date to use by prioritizing transaction.valueDate, followed by transaction.valueDateTime, transaction.bookingDate, and transaction.bookingDateTime. The selected date is assigned to editedTrans.date, and the method calls the parent method Fallback.normalizeTransaction, passing the original transaction, booked, and the modified editedTrans as arguments. The existing methods sortTransactions and calculateStartingBalance remain unchanged.

Suggested labels

:sparkles: Merged

Suggested reviewers

  • matt-fidd

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4b090a and 648c09c.

📒 Files selected for processing (1)
  • packages/sync-server/src/app-gocardless/banks/mbank_retail_brexplpw.js (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/sync-server/src/app-gocardless/banks/mbank_retail_brexplpw.js (1)
Learnt from: matt-fidd
PR: actualbudget/actual#4253
File: packages/sync-server/src/app-gocardless/banks/integration-bank.js:68-71
Timestamp: 2025-02-11T17:28:02.196Z
Learning: In the integration-bank.js normalizeTransaction method, mutating the original transaction object by adding remittanceInformationUnstructuredArrayString and remittanceInformationStructuredArrayString properties is acceptable.
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: build (macos-latest)
  • GitHub Check: Build Docker image (alpine)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Wait for Netlify build to finish
  • GitHub Check: Analyze
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Build Docker image (ubuntu)
🔇 Additional comments (2)
packages/sync-server/src/app-gocardless/banks/mbank_retail_brexplpw.js (2)

11-18: Well-documented implementation with clear explanation of the issue.

The comment thoroughly explains the problem, reasoning, and solution approach, which is excellent for future maintainers. It clearly describes the observed inconsistency in the API response where bookingDate and valueDate are swapped for the mBank Retail Poland integration.


19-31:

✅ Verification successful

Good implementation that addresses the date normalization issue.

The implementation correctly addresses the issue by prioritizing valueDate over bookingDate in date selection. Creating a copy of the transaction object rather than mutating the original is a good practice, and passing both to the parent method maintains compatibility with the rest of the system.

The fallback chain for date selection is comprehensive, ensuring that an appropriate date value is always used.


🏁 Script executed:

#!/bin/bash
# Let's verify the parent method signature to confirm it can accept the third parameter

# Check the Fallback.normalizeTransaction method signature in integration-bank.js
cat packages/sync-server/src/app-gocardless/banks/integration-bank.js | grep -A 20 "normalizeTransaction"

Length of output: 779


Verified: Date Normalization Implementation Confirmed

The Fallback.normalizeTransaction method’s signature clearly supports the third parameter, and the approach in mbank_retail_brexplpw.js correctly creates a non-mutative copy of the transaction with an explicitly set date. This design ensures that the valueDate (and its fallback value, valueDateTime) are prioritized over booking dates, while maintaining compatibility with the parent method’s logic.

  • The transaction copy (editedTrans) preserves the original object.
  • The date assignment order in mbank_retail_brexplpw.js guarantees that valueDate and valueDateTime take precedence, as intended.
  • The parent method in integration-bank.js accepts the third parameter, confirming that the additional data is handled correctly.

Overall, this is a solid implementation.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@matt-fidd
Copy link
Contributor

👋 Hi! Could you share a snippet of the transaction data sent back by GoCardless please? Only the date information is really important so you can remove/redact anything else.

@matt-fidd matt-fidd self-assigned this Mar 3, 2025
@szymon-romanko
Copy link
Contributor Author

Hi, thanks for your review, below I'm posting GoCardless API responses for example transactions from mBank Retail Poland (mbank_retail_brexplpw) (the one I'm fixing) and from Revolut (to show how other banks are handled). I've removed all non-date fields

mBank Retail

{
  "bookingDate": "2025-03-01",
  "valueDate": "2025-02-27",
}

Revolut

{
  "bookingDate": "2025-02-28",
  "valueDate": "2025-03-01",
  "bookingDateTime": "2025-02-28T19:33:14.396808Z",
  "valueDateTime": "2025-03-01T05:46:41.247084Z",
}

Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small tweak to the implementation to make it work with the bank sync mapping on the front end, other than that it looks good!

@matt-fidd
Copy link
Contributor

Hi, thanks for your review, below I'm posting GoCardless API responses for example transactions from mBank Retail Poland (mbank_retail_brexplpw) (the one I'm fixing) and from Revolut (to show how other banks are handled). I've removed all non-date fields
...

Makes sense, thank you.

…xplpw.js

Co-authored-by: Matt Fiddaman <github@m.fiddaman.uk>
Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for this

@matt-fidd matt-fidd merged commit 9e82032 into actualbudget:master Mar 4, 2025
22 checks passed
@szymon-romanko szymon-romanko deleted the mbank_api branch March 4, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants