def units_for(split): number = data.Decimal(split.quantity).quantize( data.Decimal(1.0) / data.Decimal(split.account.commodity.fraction)) currency = commodity_name(split.account.commodity) return data.Amount(number, currency)
def units_for(split): # I was having balance precision problems due to how beancount deal # with integer precision. So multiply quantity by 1.0 to force at # least 1 decimal place. number = split.quantity * data.Decimal('1.0') currency = split.account.commodity.mnemonic return data.Amount(number, currency)
def price_for(split): acc_comm = split.account.commodity txn_comm = split.transaction.currency if acc_comm == txn_comm: return None try: number = abs(split.value / split.quantity) * data.Decimal('1.000000') except InvalidOperation: # Skip "bad" transcations (split.value and quantity are 0) return None currency = commodity_name(txn_comm) return data.Amount(number, currency)