books: Add Loader.load_fy_range() method.
This commit is contained in:
parent
43a2e1bec8
commit
96a363633f
2 changed files with 28 additions and 0 deletions
|
@ -18,13 +18,19 @@ import datetime
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from beancount import loader as bc_loader
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
|
Any,
|
||||||
Iterable,
|
Iterable,
|
||||||
Mapping,
|
Mapping,
|
||||||
NamedTuple,
|
NamedTuple,
|
||||||
Optional,
|
Optional,
|
||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
from .beancount_types import (
|
||||||
|
LoadResult,
|
||||||
|
)
|
||||||
|
|
||||||
PathLike = Union[str, Path]
|
PathLike = Union[str, Path]
|
||||||
PluginsSpec = Mapping[str, Optional[str]]
|
PluginsSpec = Mapping[str, Optional[str]]
|
||||||
|
@ -147,3 +153,18 @@ class Loader:
|
||||||
books_start,
|
books_start,
|
||||||
*(self._format_include(year) for year in years),
|
*(self._format_include(year) for year in years),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def load_fy_range(self,
|
||||||
|
from_fy: Year,
|
||||||
|
to_fy: Optional[Year]=None,
|
||||||
|
plugins: Optional[PluginsSpec]=None,
|
||||||
|
) -> LoadResult:
|
||||||
|
"""Load books for a range of fiscal years
|
||||||
|
|
||||||
|
This is a convenience wrapper to call
|
||||||
|
self.fy_range_string(from_fy, to_fy, plugins)
|
||||||
|
and load the result with beancount.loader.load_string.
|
||||||
|
"""
|
||||||
|
return bc_loader.load_string( # type:ignore[no-untyped-call, no-any-return]
|
||||||
|
self.fy_range_string(from_fy, to_fy, plugins),
|
||||||
|
)
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -74,3 +76,8 @@ def test_fy_range_string_plugins_override(conservancy_loader, plugins):
|
||||||
|
|
||||||
def test_fy_range_string_empty_range(conservancy_loader):
|
def test_fy_range_string_empty_range(conservancy_loader):
|
||||||
assert conservancy_loader.fy_range_string(2020, 2019) == ''
|
assert conservancy_loader.fy_range_string(2020, 2019) == ''
|
||||||
|
|
||||||
|
def test_load_fy_range_empty(conservancy_loader):
|
||||||
|
entries, errors, options_map = conservancy_loader.load_fy_range(2020, 2019)
|
||||||
|
assert not entries
|
||||||
|
assert options_map.get('input_hash') == hashlib.md5().hexdigest()
|
||||||
|
|
Loading…
Reference in a new issue