Skip to content

Commit

Permalink
serialisation: serialise custom values
Browse files Browse the repository at this point in the history
  • Loading branch information
yagebu committed Jan 2, 2025
1 parent a910c45 commit cde3f06
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/fava/serialisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from fava.beans import create
from fava.beans.abc import Amount
from fava.beans.abc import Balance
from fava.beans.abc import Custom
from fava.beans.abc import Directive
from fava.beans.abc import Posting
from fava.beans.abc import Transaction
Expand Down Expand Up @@ -60,6 +61,15 @@ def _(entry: Transaction) -> Any:
return ret


@serialise.register(Custom)
def _(entry: Custom) -> Any:
"""Serialise an entry."""
ret = entry._asdict() # type: ignore[attr-defined]
ret["t"] = "Custom"
ret["values"] = [v.value for v in entry.values]
return ret


@serialise.register(Balance)
def _(entry: Balance) -> Any:
"""Serialise an entry."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
[
{
"date": "2012-12-12",
"meta": {
"filename": "<string>",
"lineno": 20
},
"t": "Custom",
"type": "string",
"values": [
{
"currency": "EUR",
"number": 1
},
false
]
},
{
"account": "Assets:Cash",
"booking": "Booking.STRICT",
Expand Down Expand Up @@ -138,7 +154,7 @@
"date": "2019-12-12",
"meta": {
"filename": "<string>",
"lineno": 21
"lineno": 22
},
"name": "query name",
"query_string": "journal",
Expand Down
1 change: 1 addition & 0 deletions tests/test_serialisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_serialise_entry_types(
2018-12-15 commodity USD
2018-12-16 price USD 1 EUR
2012-12-12 custom "string" 1 EUR FALSE
2019-12-12 query "query name" "journal"
"""
Expand Down

0 comments on commit cde3f06

Please sign in to comment.