config: fiscal_year_begin returns a FiscalYear.
This commit is contained in:
parent
5c60666619
commit
51137815d3
2 changed files with 6 additions and 3 deletions
|
@ -33,6 +33,7 @@ from typing import (
|
||||||
Type,
|
Type,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from . import books
|
||||||
from . import rtutil
|
from . import rtutil
|
||||||
|
|
||||||
class RTCredentials(NamedTuple):
|
class RTCredentials(NamedTuple):
|
||||||
|
@ -130,7 +131,7 @@ class Config:
|
||||||
config_root = self._path_from_environ('XDG_CONFIG_HOME')
|
config_root = self._path_from_environ('XDG_CONFIG_HOME')
|
||||||
return Path(config_root, name, 'config.ini')
|
return Path(config_root, name, 'config.ini')
|
||||||
|
|
||||||
def fiscal_year_begin(self) -> Tuple[int, int]:
|
def fiscal_year_begin(self) -> books.FiscalYear:
|
||||||
s = self.file_config.get('Beancount', 'fiscal year begin', fallback='3 1')
|
s = self.file_config.get('Beancount', 'fiscal year begin', fallback='3 1')
|
||||||
match = re.match(r'([01]?[0-9])(?:\s*[-./ ]\s*([0-3]?[0-9]))?$', s.strip())
|
match = re.match(r'([01]?[0-9])(?:\s*[-./ ]\s*([0-3]?[0-9]))?$', s.strip())
|
||||||
if match is None:
|
if match is None:
|
||||||
|
@ -146,7 +147,7 @@ class Config:
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise ValueError(f"fiscal year begin {s!r} is invalid date: {e.args[0]}")
|
raise ValueError(f"fiscal year begin {s!r} is invalid date: {e.args[0]}")
|
||||||
else:
|
else:
|
||||||
return (month, day)
|
return books.FiscalYear(month, day)
|
||||||
|
|
||||||
def payment_threshold(self) -> decimal.Decimal:
|
def payment_threshold(self) -> decimal.Decimal:
|
||||||
return decimal.Decimal(0)
|
return decimal.Decimal(0)
|
||||||
|
|
|
@ -378,4 +378,6 @@ def test_bad_fiscal_year_begin(value):
|
||||||
|
|
||||||
def test_default_fiscal_year_begin():
|
def test_default_fiscal_year_begin():
|
||||||
config = config_mod.Config()
|
config = config_mod.Config()
|
||||||
assert config.fiscal_year_begin() == (3, 1)
|
actual = config.fiscal_year_begin()
|
||||||
|
assert actual.month == 3
|
||||||
|
assert actual.day == 1
|
||||||
|
|
Loading…
Reference in a new issue