historical: Swap Ledger and Beancount formatters in the class hierarchy.
This makes sense for a couple of reasons: * The Beancount formatter has "less features" than the Ledger formatter, so this is a more "logical" organization of the hierarchy anyway. Note how this eliminates the need for the BeancountFormatter.__init__ override to turn off Ledger features. * Any future work will probably be focused on the Beancount formatter, so this reduces the amount of code you have to understand and hold in your head to do that.
This commit is contained in:
parent
c3fd55ec15
commit
8dede9d139
1 changed files with 11 additions and 23 deletions
|
@ -71,19 +71,15 @@ class Formatter:
|
|||
)
|
||||
|
||||
|
||||
class LedgerFormatter(Formatter):
|
||||
COST_FMT = '{{={}}}'
|
||||
class BeancountFormatter(Formatter):
|
||||
COST_FMT = '{{{}}}'
|
||||
PRICE_FMT = ' @ {}'
|
||||
|
||||
def price_rate(self, from_amt, from_curr, to_curr):
|
||||
if self.price_rates is None:
|
||||
rates = self.cost_rates
|
||||
return None
|
||||
else:
|
||||
rates = self.price_rates
|
||||
return rates.convert(from_amt, from_curr, to_curr)
|
||||
|
||||
def can_sign_currency(self, code):
|
||||
return len(babel.numbers.get_currency_symbol(code)) == 1
|
||||
return self.price_rates.convert(from_amt, from_curr, to_curr)
|
||||
|
||||
def normalize_rate(self, rate, prec=None):
|
||||
if prec is None:
|
||||
|
@ -172,26 +168,18 @@ class LedgerFormatter(Formatter):
|
|||
)
|
||||
|
||||
|
||||
class BeancountFormatter(LedgerFormatter):
|
||||
COST_FMT = '{{{}}}'
|
||||
class LedgerFormatter(BeancountFormatter):
|
||||
COST_FMT = '{{={}}}'
|
||||
|
||||
def __init__(self, cost_rates, price_rates=None,
|
||||
signed_currencies=(), base_fmt='#,##0.###',
|
||||
rate_precision=5, denomination=None):
|
||||
super().__init__(
|
||||
cost_rates,
|
||||
price_rates,
|
||||
(),
|
||||
base_fmt,
|
||||
rate_precision,
|
||||
denomination,
|
||||
)
|
||||
def can_sign_currency(self, code):
|
||||
return len(babel.numbers.get_currency_symbol(code)) == 1
|
||||
|
||||
def price_rate(self, from_amt, from_curr, to_curr):
|
||||
if self.price_rates is None:
|
||||
return None
|
||||
rates = self.cost_rates
|
||||
else:
|
||||
return self.price_rates.convert(from_amt, from_curr, to_curr)
|
||||
rates = self.price_rates
|
||||
return rates.convert(from_amt, from_curr, to_curr)
|
||||
|
||||
|
||||
class Formats(enum.Enum):
|
||||
|
|
Loading…
Reference in a new issue