ofxstatement-nordigen 0.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ofxstatement-nordigen might be problematic. Click here for more details.

Files changed (16) hide show
  1. {ofxstatement_nordigen-0.1/src/ofxstatement_nordigen.egg-info → ofxstatement_nordigen-0.1.2}/PKG-INFO +13 -4
  2. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/README.rst +12 -3
  3. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/pyproject.toml +1 -1
  4. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/src/ofxstatement_nordigen/plugin.py +23 -5
  5. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/src/ofxstatement_nordigen/schemas.py +12 -11
  6. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2/src/ofxstatement_nordigen.egg-info}/PKG-INFO +13 -4
  7. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/tests/test_sample.py +23 -4
  8. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/tests/test_schemas.py +17 -0
  9. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/MANIFEST.in +0 -0
  10. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/setup.cfg +0 -0
  11. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/src/ofxstatement_nordigen/__init__.py +0 -0
  12. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/src/ofxstatement_nordigen.egg-info/SOURCES.txt +0 -0
  13. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/src/ofxstatement_nordigen.egg-info/dependency_links.txt +0 -0
  14. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/src/ofxstatement_nordigen.egg-info/entry_points.txt +0 -0
  15. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/src/ofxstatement_nordigen.egg-info/requires.txt +0 -0
  16. {ofxstatement_nordigen-0.1 → ofxstatement_nordigen-0.1.2}/src/ofxstatement_nordigen.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ofxstatement-nordigen
3
- Version: 0.1
3
+ Version: 0.1.2
4
4
  Summary: ofxstatement plugin for Nordigen bank statements
5
5
  Author-email: Jimmy Stammers <jimmy.stammers@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/jstammers/ofxstatement-nordigen/
@@ -57,18 +57,18 @@ To verify that the plugin is installed correctly, you can run:
57
57
 
58
58
  ofxstatement --list-plugins
59
59
 
60
- This should list the `nordigen` plugin among other plugins.
60
+ This should list the ``nordigen`` plugin among other plugins.
61
61
 
62
62
  Usage
63
63
  ================
64
64
 
65
- To use the plugin, you can run the `ofxstatement` command with the `--plugin` option:
65
+ To use the plugin, you can run the ``ofxstatement`` command with the ``--plugin`` option:
66
66
 
67
67
  .. code-block:: shell
68
68
 
69
69
  ofxstatement convert -t nordigen <input_file> <output_file>
70
70
 
71
- Replace `<input_file>` with the path to your input file and `<output_file>` with the desired output file name.
71
+ Replace ``<input_file>`` with the path to your input file and ``<output_file>`` with the desired output file name.
72
72
 
73
73
  The input file should be a JSON of transactions from GoCardless that has the schema defined `here`_.
74
74
 
@@ -76,6 +76,15 @@ The input file should be a JSON of transactions from GoCardless that has the sch
76
76
 
77
77
  The output file will be an OFX file that can be imported into GnuCash or other financial software.
78
78
 
79
+ Configuration
80
+ ================
81
+
82
+ Configuration can be edited using the ``ofxstatement edit-config`` command.
83
+ The following parameters are available:
84
+
85
+ - ``account_id``: The account ID to use for the transactions. This is required.
86
+ - ``currency``: The currency to use for the account. If not specified, the currency will be determined from the transactions.
87
+
79
88
  After you are done
80
89
  ==================
81
90
 
@@ -35,18 +35,18 @@ To verify that the plugin is installed correctly, you can run:
35
35
 
36
36
  ofxstatement --list-plugins
37
37
 
38
- This should list the `nordigen` plugin among other plugins.
38
+ This should list the ``nordigen`` plugin among other plugins.
39
39
 
40
40
  Usage
41
41
  ================
42
42
 
43
- To use the plugin, you can run the `ofxstatement` command with the `--plugin` option:
43
+ To use the plugin, you can run the ``ofxstatement`` command with the ``--plugin`` option:
44
44
 
45
45
  .. code-block:: shell
46
46
 
47
47
  ofxstatement convert -t nordigen <input_file> <output_file>
48
48
 
49
- Replace `<input_file>` with the path to your input file and `<output_file>` with the desired output file name.
49
+ Replace ``<input_file>`` with the path to your input file and ``<output_file>`` with the desired output file name.
50
50
 
51
51
  The input file should be a JSON of transactions from GoCardless that has the schema defined `here`_.
52
52
 
@@ -54,6 +54,15 @@ The input file should be a JSON of transactions from GoCardless that has the sch
54
54
 
55
55
  The output file will be an OFX file that can be imported into GnuCash or other financial software.
56
56
 
57
+ Configuration
58
+ ================
59
+
60
+ Configuration can be edited using the ``ofxstatement edit-config`` command.
61
+ The following parameters are available:
62
+
63
+ - ``account_id``: The account ID to use for the transactions. This is required.
64
+ - ``currency``: The currency to use for the account. If not specified, the currency will be determined from the transactions.
65
+
57
66
  After you are done
58
67
  ==================
59
68
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ofxstatement-nordigen"
7
- version = "0.1"
7
+ version = "0.1.2"
8
8
  authors = [
9
9
  { name="Jimmy Stammers", email="jimmy.stammers@gmail.com" },
10
10
  ]
@@ -1,6 +1,6 @@
1
1
  import json
2
- from typing import Iterable
3
-
2
+ from typing import Iterable, Optional
3
+ from datetime import datetime
4
4
  from ofxstatement.plugin import Plugin
5
5
  from ofxstatement.parser import StatementParser
6
6
  from ofxstatement.statement import Statement, StatementLine
@@ -12,15 +12,24 @@ class NordigenPlugin(Plugin):
12
12
  """Retrieves Nordigen transactions and converts them to OFX format."""
13
13
 
14
14
  def get_parser(self, filename: str) -> "NordigenParser":
15
- return NordigenParser(filename)
15
+ default_ccy = self.settings.get("currency")
16
+ account_id = self.settings.get("account")
17
+ return NordigenParser(filename, default_ccy, account_id)
16
18
 
17
19
 
18
20
  class NordigenParser(StatementParser[str]):
19
- def __init__(self, filename: str) -> None:
21
+ def __init__(
22
+ self,
23
+ filename: str,
24
+ currency: Optional[str] = None,
25
+ account_id: Optional[str] = None,
26
+ ) -> None:
20
27
  super().__init__()
21
28
  if not filename.endswith(".json"):
22
29
  raise ValueError("Only JSON files are supported")
23
30
  self.filename = filename
31
+ self.currency = currency
32
+ self.account_id = account_id
24
33
 
25
34
  def parse(self) -> Statement:
26
35
  """Main entry point for parsers
@@ -29,7 +38,16 @@ class NordigenParser(StatementParser[str]):
29
38
  process the file.
30
39
  """
31
40
  with open(self.filename, "r"):
32
- return super().parse()
41
+ statement = super().parse()
42
+ dates = [
43
+ line.date for line in statement.lines if isinstance(line.date, datetime)
44
+ ]
45
+ if len(dates) > 0:
46
+ statement.start_date = min(dates)
47
+ statement.end_date = max(dates)
48
+ statement.account_id = self.account_id
49
+ statement.currency = self.currency or statement.currency
50
+ return statement
33
51
 
34
52
  def split_records(self) -> Iterable[str]:
35
53
  """Return iterable object consisting of a line per transaction"""
@@ -22,24 +22,25 @@ class Amount(BaseModel):
22
22
  return value
23
23
 
24
24
 
25
- class InstructedAmount(Amount):
26
- targetCurrency: Optional[Currency] = None
25
+ class Account(BaseModel):
26
+ bban: Optional[str] = None
27
+
28
+
29
+ class CurrencyExchange(BaseModel):
27
30
  sourceCurrency: Optional[Currency] = None
31
+ targetCurrency: Optional[Currency] = None
32
+ unitCurrency: Optional[Currency] = None
28
33
  exchangeRate: Optional[float] = None
34
+ instructedAmount: Optional[Amount] = None
29
35
 
30
- @field_validator("targetCurrency", "sourceCurrency", mode="before")
36
+ @field_validator("sourceCurrency", "targetCurrency", "unitCurrency", mode="before")
31
37
  def validate_currency(cls, value):
32
38
  if isinstance(value, str):
33
39
  return Currency(value)
34
40
  return value
35
41
 
36
-
37
- class Account(BaseModel):
38
- bban: Optional[str] = None
39
-
40
-
41
- class ReportExchangeRate(BaseModel):
42
- instructedAmount: Optional[InstructedAmount] = None
42
+ class Config:
43
+ arbitrary_types_allowed = True
43
44
 
44
45
 
45
46
  class NordigenTransactionModel(BaseModel):
@@ -56,7 +57,7 @@ class NordigenTransactionModel(BaseModel):
56
57
  creditorAgent: Optional[str] = None
57
58
  creditorId: Optional[str] = None
58
59
  creditorName: Optional[str] = None
59
- currencyExchange: Optional[Union[ReportExchangeRate, InstructedAmount]] = None
60
+ currencyExchange: Optional[CurrencyExchange] = None
60
61
  debtorAccount: Optional[Account] = None
61
62
  debtorAgent: Optional[str] = None
62
63
  debtorName: Optional[str] = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ofxstatement-nordigen
3
- Version: 0.1
3
+ Version: 0.1.2
4
4
  Summary: ofxstatement plugin for Nordigen bank statements
5
5
  Author-email: Jimmy Stammers <jimmy.stammers@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/jstammers/ofxstatement-nordigen/
@@ -57,18 +57,18 @@ To verify that the plugin is installed correctly, you can run:
57
57
 
58
58
  ofxstatement --list-plugins
59
59
 
60
- This should list the `nordigen` plugin among other plugins.
60
+ This should list the ``nordigen`` plugin among other plugins.
61
61
 
62
62
  Usage
63
63
  ================
64
64
 
65
- To use the plugin, you can run the `ofxstatement` command with the `--plugin` option:
65
+ To use the plugin, you can run the ``ofxstatement`` command with the ``--plugin`` option:
66
66
 
67
67
  .. code-block:: shell
68
68
 
69
69
  ofxstatement convert -t nordigen <input_file> <output_file>
70
70
 
71
- Replace `<input_file>` with the path to your input file and `<output_file>` with the desired output file name.
71
+ Replace ``<input_file>`` with the path to your input file and ``<output_file>`` with the desired output file name.
72
72
 
73
73
  The input file should be a JSON of transactions from GoCardless that has the schema defined `here`_.
74
74
 
@@ -76,6 +76,15 @@ The input file should be a JSON of transactions from GoCardless that has the sch
76
76
 
77
77
  The output file will be an OFX file that can be imported into GnuCash or other financial software.
78
78
 
79
+ Configuration
80
+ ================
81
+
82
+ Configuration can be edited using the ``ofxstatement edit-config`` command.
83
+ The following parameters are available:
84
+
85
+ - ``account_id``: The account ID to use for the transactions. This is required.
86
+ - ``currency``: The currency to use for the account. If not specified, the currency will be determined from the transactions.
87
+
79
88
  After you are done
80
89
  ==================
81
90
 
@@ -6,6 +6,24 @@ from ofxstatement_nordigen.plugin import NordigenPlugin, NordigenParser
6
6
  from ofxstatement import ofx
7
7
 
8
8
 
9
+ def test_config_sets_account_and_currency() -> None:
10
+ """Test that account and currency are set correctly when provided in config."""
11
+ # Create a plugin with specific account and currency settings
12
+ settings = {"account": "test-account-123", "currency": "EUR"}
13
+ plugin = NordigenPlugin(UI(), settings)
14
+
15
+ here = os.path.dirname(__file__)
16
+ sample_filename = os.path.join(here, "sample-statement.json")
17
+ parser = plugin.get_parser(sample_filename)
18
+
19
+ assert parser.account_id == settings["account"]
20
+ assert parser.currency == settings["currency"]
21
+
22
+ statement = parser.parse()
23
+ assert statement.account_id == settings["account"]
24
+ assert statement.currency == settings["currency"]
25
+
26
+
9
27
  def test_sample() -> None:
10
28
  plugin = NordigenPlugin(UI(), {})
11
29
  here = os.path.dirname(__file__)
@@ -15,6 +33,8 @@ def test_sample() -> None:
15
33
  parser = plugin.get_parser(sample_filename)
16
34
  statement = parser.parse()
17
35
  assert len(statement.lines) > 0
36
+ assert statement.start_date is not None
37
+ assert statement.end_date is not None
18
38
 
19
39
 
20
40
  @pytest.mark.parametrize("filename", ["test_date.json"])
@@ -30,13 +50,12 @@ def test_parse_record(filename: str) -> None:
30
50
  writer = ofx.OfxWriter(statement)
31
51
  result = writer.toxml(pretty=True)
32
52
 
33
- # Get everything between the <STMTTRNRS> and </STMTTRNRS> tags
53
+ # Get everything between the <STMTTRN> and </STMTTRN> tags
34
54
  result = result[
35
- result.index("<STMTTRNRS>") : result.index("</STMTTRNRS>") + len("</STMTTRNRS>")
55
+ result.index("<STMTTRN>") : result.index("</STMTTRN>") + len("</STMTTRN>")
36
56
  ]
37
57
  expected = expected[
38
- expected.index("<STMTTRNRS>") : expected.index("</STMTTRNRS>")
39
- + len("</STMTTRNRS>")
58
+ expected.index("<STMTTRN>") : expected.index("</STMTTRN>") + len("</STMTTRN>")
40
59
  ]
41
60
 
42
61
  assert result == expected
@@ -42,8 +42,25 @@ from ofxstatement_nordigen.schemas import NordigenTransactionModel
42
42
  },
43
43
  "internalTransactionId": "anonymized_internal_transaction_id",
44
44
  },
45
+ {
46
+ "transactionId": "anonymized_transaction_id",
47
+ "bookingDate": "2025-04-05",
48
+ "bookingDateTime": "2025-05-05T07:20:42.19Z",
49
+ "transactionAmount": {"amount": "-100.0000", "currency": "GBP"},
50
+ "currencyExchange": {
51
+ "instructedAmount": {"amount": "204.5010", "currency": "AUD"},
52
+ "sourceCurrency": "AUD",
53
+ "exchangeRate": "2.04501",
54
+ "unitCurrency": "GBP",
55
+ "targetCurrency": "GBP",
56
+ },
57
+ "remittanceInformationUnstructured": "anonymized_remittance_information",
58
+ "proprietaryBankTransactionCode": "anonymized_code",
59
+ "internalTransactionId": "anonymized_internal_transaction_id",
60
+ },
45
61
  ],
46
62
  )
47
63
  def test_go_cardless_transaction_model(data):
48
64
  validated = NordigenTransactionModel(**data)
65
+ print(validated)
49
66
  assert validated is not None