New issue 208: cost_to_str does not print total-cost-only CostSpecs
https://bitbucket.org/blais/beancount/issues/208/cost_to_str-does-not-print-total-cost-only
Robert Sesek:
I'm writing some scripts to convert my existing accounting spreadsheets into Beancount. One issue I ran into is when converting dividend reinvestments for funds, the transactions sometimes do not balance when using the reported unit price and number of shares.
E.g., "Transaction does not balance: (0.01646 USD)" for this transaction:
```
2017-12-27 * "VXUS" "Reinvest"
Assets:Investments:Vanguard:RothIRA:VXUS 1.433 VXUS {56.62 USD}
Income:Investments:Vanguard:RothIRA:VXUS:Div -81.12 USD
```
My solution is to instead have the unit-cost price be inferred from total cost and just attaching/ignoring the reported price, e.g.
```
2017-12-27 * "VXUS" "Reinvest"
Assets:Investments:Vanguard:RothIRA:VXUS 1.433 VXUS {# 81.12 USD} @ 56.62 USD
Income:Investments:Vanguard:RothIRA:VXUS:Div -81.12 USD
```
However, when trying to generate that posting using the Beancount API:
```python
asset = data.Posting('Assets:Investments:Vanguard:RothIRA:VXUS',
Amount(D('1.433'), 'VXUS'),
CostSpec(None, D('81.12'), 'USD', None, None, False),
Amount(D('56.62'), 'USD'),
None, None)
# Deliberately missing the sweep account for simplicty.
print_entry(data.Transaction(None, '2017-12-27', '*', 'VXUS', 'Reinvest', None, None, [asset]))
```
It gets rendered as:
```
2017-12-27 * "VXUS" "Reinvest"
Assets:Investments:Vanguard:RothIRA:VXUS 1.433 VXUS {} @ 56.62 USD
```
There is an issue in beancount.core.position.cost_to_str(), where it only prints the cost if the number_unit is present, ignoring number_total if it is not.