reports: Separate methods for Balances to get posting classification.
For easier subclass customization.
This commit is contained in:
parent
69f597a47c
commit
f7883ac314
1 changed files with 14 additions and 8 deletions
|
@ -353,18 +353,24 @@ class Balances:
|
|||
fund = Fund.UNRESTRICTED
|
||||
else:
|
||||
fund = Fund.RESTRICTED
|
||||
try:
|
||||
classification_s = post.account.meta['classification']
|
||||
if isinstance(classification_s, str):
|
||||
classification = data.Account(classification_s)
|
||||
else:
|
||||
raise TypeError()
|
||||
except (KeyError, TypeError):
|
||||
classification = post.account
|
||||
classification = self._get_classification(post)
|
||||
post_meta = post.meta.get(post_meta_key)
|
||||
key = BalanceKey(post.account, classification, period, fund, post_meta)
|
||||
self.balances[key] += post.at_cost()
|
||||
|
||||
def _get_classification(self, post: data.Posting) -> data.Account:
|
||||
try:
|
||||
return self._get_meta_account(post.account.meta, 'classification')
|
||||
except (KeyError, TypeError):
|
||||
return post.account
|
||||
|
||||
def _get_meta_account(self, meta: Mapping[MetaKey, MetaValue], key: MetaKey) -> data.Account:
|
||||
value = meta[key]
|
||||
if isinstance(value, str):
|
||||
return data.Account(value)
|
||||
else:
|
||||
raise TypeError(f"{key!r} is not a string but a {type(value).__name__}")
|
||||
|
||||
def total(self,
|
||||
account: Union[None, str, Collection[str]]=None,
|
||||
classification: Optional[str]=None,
|
||||
|
|
Loading…
Reference in a new issue