From 9a6d5d1a53dc971ba2d3c257e1d2d93ac932eccb Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Wed, 17 Feb 2021 03:02:32 +0100 Subject: [PATCH] ofx: support non-sale transfers out This works with transactions like a charitable donation or a brokerage transfer which don't involve liquidating the asset that is being transferred out. --- beancount_import/source/ofx.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/beancount_import/source/ofx.py b/beancount_import/source/ofx.py index 4ec275dc..a7dedcc8 100644 --- a/beancount_import/source/ofx.py +++ b/beancount_import/source/ofx.py @@ -916,14 +916,14 @@ def get_subaccount_cash(inv401ksource: Optional[str] = None) -> str: units = normalize_fraction(raw.units) if quantity_round_digits is not None: units = round(units, quantity_round_digits) - unitprice = normalize_fraction(raw.unitprice) + if raw.unitprice is not None: + unitprice = normalize_fraction(raw.unitprice) cost_spec = None price = None is_sale = False if raw.trantype in SELL_TYPES or (raw.trantype == 'TRANSFER' and units < ZERO): - is_sale = True units = -abs(units) # For sell transactions, rely on beancount to determine the matching lot. cost_spec = CostSpec( @@ -933,7 +933,9 @@ def get_subaccount_cash(inv401ksource: Optional[str] = None) -> str: date=None, label=None, merge=False) - price = Amount(number=unitprice, currency=self.currency) + if unitprice != ZERO: + is_sale = True + price = Amount(number=unitprice, currency=self.currency) elif raw.trantype == 'TRANSFER' and units > ZERO: # Transfer in. # OFX does not specify the lot information, so it will have to be manually fixed.