feat(import): add currency and number format support for CSV imports #1819

Merged
danestves merged 9 commits from main into main 2025-02-11 04:31:28 +08:00
danestves commented 2025-02-07 10:04:10 +08:00 (Migrated from github.com)

Fixes #1713
/claim #1713

Before this change, importing a CSV with European-style numbers (like 1.234,56) would result in incorrect values because the parser would strip the decimal comma. Now, users can specify their number format and get accurate imports regardless of their region.

Date,Name,Amount
2023-05-01,Grocery Store,1.254,54

Before: Would parse as 125454
After: Correctly parses as 1254.54 when European format is selected

Fixes #1713 /claim #1713 Before this change, importing a CSV with European-style numbers (like `1.234,56`) would result in incorrect values because the parser would strip the decimal comma. Now, users can specify their number format and get accurate imports regardless of their region. ```csv Date,Name,Amount 2023-05-01,Grocery Store,1.254,54 ``` **Before**: Would parse as `125454` **After**: Correctly parses as `1254.54` when European format is selected
algora-pbc[bot] commented 2025-02-07 10:04:45 +08:00 (Migrated from github.com)
💵 To receive payouts, [sign up on Algora](https://console.algora.io/auth/signup), [link your Github account](https://console.algora.io/solve) and [connect with Stripe](https://console.algora.io/solve).
zachgoll (Migrated from github.com) requested changes 2025-02-08 00:35:27 +08:00
zachgoll (Migrated from github.com) left a comment

Hey @danestves thanks for the contribution!

Overall, I think the code looks good.

Could we add a few tests cases to import_interface_test.rb that verifies:

  • We're parsing these formats correctly
  • The currency logic works (user-provided column takes precedence over the default)

We may have to slightly alter the import.rb methods for better testability. We don't currently have any tests written for generate_rows_from_csv (or any of the methods that translate the config to the import rows). It would be great to have something that covers this area of the import process.

Hey @danestves thanks for the contribution! Overall, I think the code looks good. Could we add a few tests cases to `import_interface_test.rb` that verifies: - We're parsing these formats correctly - The currency logic works (user-provided column takes precedence over the default) We may have to slightly alter the `import.rb` methods for better testability. We don't currently have any tests written for `generate_rows_from_csv` (or any of the methods that translate the config to the import rows). It would be great to have something that covers this area of the import process.
zachgoll (Migrated from github.com) commented 2025-02-08 00:31:23 +08:00

I'm thinking we might want to rename this to default_currency (and remove the method that's already in the model) because a user is allowed to add a currency column in their CSV and assign a mapping to that.

If they explicitly provide us a currency column, we'll want to use that value first. If not, we use this default value.

I'm thinking we might want to rename this to `default_currency` (and remove the method that's already in the model) because a user is allowed to add a `currency` column in their CSV and assign a mapping to that. If they explicitly provide us a currency column, we'll want to use that value first. If not, we use this default value.
zachgoll (Migrated from github.com) reviewed 2025-02-08 04:35:31 +08:00
zachgoll (Migrated from github.com) commented 2025-02-08 04:35:31 +08:00

Coming back to this after looking at #1814 and I'm realizing that we might need to entirely remove this currency configuration column and just stick with the number_format.

Since the user can directly map one of their CSV columns to "Currency" and we're defaulting to the family currency anyways, I'm thinking this "Default currency" configuration option might cause more confusion than its worth.

So in summary, I think we need to:

  • Remove this currency column and the associated configuration field in the forms
  • Put the number_format config field side by side with the existing currency mapping columns added in #1814
Coming back to this after looking at #1814 and I'm realizing that we might need to entirely _remove_ this `currency` configuration column and just stick with the `number_format`. Since the user can directly map one of their CSV columns to "Currency" and we're defaulting to the family currency anyways, I'm thinking this "Default currency" configuration option might cause more confusion than its worth. So in summary, I think we need to: - Remove this `currency` column and the associated configuration field in the forms - Put the `number_format` config field side by side with the existing currency mapping columns added in #1814
danestves (Migrated from github.com) reviewed 2025-02-08 07:15:57 +08:00
danestves (Migrated from github.com) commented 2025-02-08 07:15:57 +08:00

For sure! Let me work on that!

For sure! Let me work on that!
danestves (Migrated from github.com) reviewed 2025-02-08 10:09:25 +08:00
danestves (Migrated from github.com) commented 2025-02-08 10:09:25 +08:00

Changes have been made @zachgoll also I made a little change to generate_rows_from_csv (and also added tests) we were using insert_all! which doesn't trigger validations or callbacks, and more importantly, doesn't return the created records, so:

  • I change it to create! to properly create and return row records
  • Changed from a map + bulk insert to an each loop with individual creates

That kept all the same field mappings, but now they'll be created with proper ActiveRecord objects

Changes have been made @zachgoll also I made a little change to `generate_rows_from_csv` (and also added tests) we were using `insert_all!` which doesn't trigger validations or callbacks, and more importantly, doesn't return the created records, so: - I change it to `create!` to properly create and return row records - Changed from a `map` + bulk insert to an `each` loop with individual creates That kept all the same field mappings, but now they'll be created with proper `ActiveRecord` objects
zachgoll (Migrated from github.com) approved these changes 2025-02-11 01:58:57 +08:00
zachgoll (Migrated from github.com) left a comment

Looks great! Just left one small comment about method naming, but otherwise once tests are passing I think we'll be good to merge this one.

Looks great! Just left one small comment about method naming, but otherwise once tests are passing I think we'll be good to merge this one.
@@ -177,6 +185,39 @@ class Import < ApplicationRecord
zachgoll (Migrated from github.com) commented 2025-02-11 01:55:30 +08:00

Can we set this to set_default_number_format now that we've removed currency?

Can we set this to `set_default_number_format` now that we've removed currency?
danestves (Migrated from github.com) reviewed 2025-02-11 03:04:30 +08:00
@@ -177,6 +185,39 @@ class Import < ApplicationRecord
danestves (Migrated from github.com) commented 2025-02-11 03:04:30 +08:00

This is done, changed the method name, now we just need to wait for the tests to pass

This is done, changed the method name, now we just need to wait for the tests to pass
danestves (Migrated from github.com) reviewed 2025-02-11 03:18:03 +08:00
@@ -177,6 +185,39 @@ class Import < ApplicationRecord
danestves (Migrated from github.com) commented 2025-02-11 03:18:03 +08:00

Added another commit since I forgot to change it in before_validation

Added another commit since I forgot to change it in `before_validation`
zachgoll commented 2025-02-11 04:45:57 +08:00 (Migrated from github.com)

@danestves make sure to create an Algora account to receive the bounty payout if you haven't already. Let me know if you run into any issues.

@danestves make sure to create an Algora account to receive the bounty payout if you haven't already. Let me know if you run into any issues.
danestves commented 2025-02-11 06:12:16 +08:00 (Migrated from github.com)

@danestves make sure to create an Algora account to receive the bounty payout if you haven't already. Let me know if you run into any issues.

Hey, thanks! Yes is now been processed by Stripe to my bank account right now, thanks

> @danestves make sure to create an Algora account to receive the bounty payout if you haven't already. Let me know if you run into any issues. Hey, thanks! Yes is now been processed by Stripe to my bank account right now, thanks
verymilan commented 2025-02-16 21:49:43 +08:00 (Migrated from github.com)

This is a very promising update! However it does not work for me. For some reason, it just jumps back to the default of 1,234.56 and ignores my selection. (at least i think so as it is on that value when i go back to "configure" after discovering the wrongly parsed numbers)

30eur are formatted 30,00 (– becoming 3000 for example)
1100eur are formatted 1100,00

This is a very promising update! However it does not work for me. For some reason, it just jumps back to the default of `1,234.56` and ignores my selection. (at least i think so as it is on that value when i go back to "configure" after discovering the wrongly parsed numbers) 30eur are formatted `30,00` (– becoming `3000` for example) 1100eur are formatted `1100,00`
zachgoll commented 2025-02-21 21:50:03 +08:00 (Migrated from github.com)

@verymilan fix going in here:

https://github.com/maybe-finance/maybe/pull/1876

@verymilan fix going in here: https://github.com/maybe-finance/maybe/pull/1876
Sign in to join this conversation.