diff --git a/src/fava/serialisation.py b/src/fava/serialisation.py index bbec34952..461dc4743 100644 --- a/src/fava/serialisation.py +++ b/src/fava/serialisation.py @@ -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 @@ -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.""" diff --git a/tests/__snapshots__/test_serialisation-test_serialise_entry_types.json b/tests/__snapshots__/test_serialisation-test_serialise_entry_types.json index 31a9cf711..8c817fb25 100644 --- a/tests/__snapshots__/test_serialisation-test_serialise_entry_types.json +++ b/tests/__snapshots__/test_serialisation-test_serialise_entry_types.json @@ -1,4 +1,20 @@ [ + { + "date": "2012-12-12", + "meta": { + "filename": "", + "lineno": 20 + }, + "t": "Custom", + "type": "string", + "values": [ + { + "currency": "EUR", + "number": 1 + }, + false + ] + }, { "account": "Assets:Cash", "booking": "Booking.STRICT", @@ -138,7 +154,7 @@ "date": "2019-12-12", "meta": { "filename": "", - "lineno": 21 + "lineno": 22 }, "name": "query name", "query_string": "journal", diff --git a/tests/test_serialisation.py b/tests/test_serialisation.py index 89d1e2adf..66399e3ce 100644 --- a/tests/test_serialisation.py +++ b/tests/test_serialisation.py @@ -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" """