Skip to content

Commit a8a1e3d

Browse files
Save budget currency data (#113)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 28e2a18 commit a8a1e3d

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

sqlite_export_for_ynab/_main.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,35 @@ def insert_budgets(
211211
cur: sqlite3.Cursor, budgets: list[dict[str, Any]], lkos: dict[str, int]
212212
) -> None:
213213
cur.executemany(
214-
"INSERT OR REPLACE INTO budgets (id, name, last_knowledge_of_server) VALUES (?, ?, ?)",
215-
((bid := b["id"], b["name"], lkos[bid]) for b in budgets),
214+
"""
215+
INSERT OR REPLACE INTO budgets (
216+
id
217+
, name
218+
, currency_format_currency_symbol
219+
, currency_format_decimal_digits
220+
, currency_format_decimal_separator
221+
, currency_format_display_symbol
222+
, currency_format_group_separator
223+
, currency_format_iso_code
224+
, currency_format_symbol_first
225+
, last_knowledge_of_server
226+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
227+
""",
228+
(
229+
(
230+
bid := b["id"],
231+
b["name"],
232+
b["currency_format"]["currency_symbol"],
233+
b["currency_format"]["decimal_digits"],
234+
b["currency_format"]["decimal_separator"],
235+
b["currency_format"]["display_symbol"],
236+
b["currency_format"]["group_separator"],
237+
b["currency_format"]["iso_code"],
238+
b["currency_format"]["symbol_first"],
239+
lkos[bid],
240+
)
241+
for b in budgets
242+
),
216243
)
217244

218245

sqlite_export_for_ynab/ddl/create-relations.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CREATE TABLE IF NOT EXISTS budgets (
22
id TEXT PRIMARY KEY
33
, name TEXT
4+
, currency_format_currency_symbol TEXT
5+
, currency_format_decimal_digits INT
6+
, currency_format_decimal_separator TEXT
7+
, currency_format_display_symbol BOOLEAN
8+
, currency_format_group_separator TEXT
9+
, currency_format_iso_code TEXT
10+
, currency_format_symbol_first BOOLEAN
411
, last_knowledge_of_server INT
512
)
613
;

testing/fixtures.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,30 @@
1818
{
1919
"id": BUDGET_ID_1,
2020
"name": "Budget 1",
21+
"currency_format": {
22+
"currency_symbol": "$",
23+
"decimal_digits": 2,
24+
"decimal_separator": ".",
25+
"display_symbol": True,
26+
"example_format": "123,456.78",
27+
"group_separator": ",",
28+
"iso_code": "USD",
29+
"symbol_first": True,
30+
},
2131
},
2232
{
2333
"id": BUDGET_ID_2,
2434
"name": "Budget 2",
35+
"currency_format": {
36+
"currency_symbol": "$",
37+
"decimal_digits": 2,
38+
"decimal_separator": ".",
39+
"display_symbol": True,
40+
"example_format": "123,456.78",
41+
"group_separator": ",",
42+
"iso_code": "USD",
43+
"symbol_first": True,
44+
},
2545
},
2646
]
2747

tests/_main_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,25 @@ def test_insert_budgets(cur):
107107
{
108108
"id": BUDGET_ID_1,
109109
"name": BUDGETS[0]["name"],
110+
"currency_format_currency_symbol": "$",
111+
"currency_format_decimal_digits": 2,
112+
"currency_format_decimal_separator": ".",
113+
"currency_format_display_symbol": 1,
114+
"currency_format_group_separator": ",",
115+
"currency_format_iso_code": "USD",
116+
"currency_format_symbol_first": 1,
110117
"last_knowledge_of_server": LKOS[BUDGET_ID_1],
111118
},
112119
{
113120
"id": BUDGET_ID_2,
114121
"name": BUDGETS[1]["name"],
122+
"currency_format_currency_symbol": "$",
123+
"currency_format_decimal_digits": 2,
124+
"currency_format_decimal_separator": ".",
125+
"currency_format_display_symbol": 1,
126+
"currency_format_group_separator": ",",
127+
"currency_format_iso_code": "USD",
128+
"currency_format_symbol_first": 1,
115129
"last_knowledge_of_server": LKOS[BUDGET_ID_2],
116130
},
117131
]

0 commit comments

Comments
 (0)