def test_change_cdty_split_price(self, book_transactions): tr = book_transactions.transactions(description="my purchase of stock") sp = tr.splits(account=book_transactions.accounts(name="broker")) assert len(book_transactions.prices) == 6 p = [p for p in book_transactions.prices if p.date.day == 29][0] assert p.value == (sp.value / sp.quantity).quantize( Decimal("0.000001")) print(book_transactions.prices) # changing the quantity of the split should change the existing price sp.quantity = (5, 1) print(tr.post_date, tr.enter_date) print(Transaction._post_date, Transaction.enter_date) print(book_transactions.prices) book_transactions.validate() print(book_transactions.prices) assert len(book_transactions.prices) == 6 assert p.value == (sp.value / sp.quantity).quantize( Decimal("0.000001")) # changing the post date of the transaction of the split should create a new price tr.post_date = date(2015, 1, 29) book_transactions.validate() assert len(book_transactions.prices) == 7
def test_change_cdty_split_price(self, book_transactions): tr = book_transactions.transactions(description="my purchase of stock") sp = tr.splits(account=book_transactions.accounts(name="broker")) assert len(book_transactions.prices) == 6 p = [p for p in book_transactions.prices if p.date.day == 29][0] p_expected = (sp.value / sp.quantity).quantize(Decimal("0.000001")) assert p.value == p_expected # changing the quantity of the split should NOT change the existing price sp.quantity = (5, 1) book_transactions.validate() p_not_expected = (sp.value / sp.quantity).quantize(Decimal("0.000001")) assert len(book_transactions.prices) == 6 assert p.value == p_expected assert p_expected != p_not_expected # changing the post date of the transaction of the split should create a new price tr.post_date = date(2015, 1, 29) book_transactions.validate() book_transactions.flush() assert len(book_transactions.prices) == 7
def test_tag_split_zero_value(self, book_transactions): broker = book_transactions.accounts(name="broker") asset = book_transactions.accounts.get(name="asset") currency = book_transactions.default_currency # Give away 250 shares for free. quantity = Decimal(-250) splits = [ Split(asset, 0), Split(broker, 0, quantity=quantity), ] Transaction(currency, description="donation", splits=splits) book_transactions.validate()
def test_tag_split_zero_quantity(self, book_transactions): broker = book_transactions.accounts(name="broker") asset = book_transactions.accounts.get(name="asset") inc = book_transactions.accounts.get(name="inc") currency = book_transactions.default_currency value = Decimal(250) splits = [ Split(asset, value), Split(inc, -value), Split(broker, value=0, quantity=0), # tag split for assigning dividend income to stock ] Transaction(currency, description='Dividend income', splits=splits) book_transactions.validate()
def test_change_cdty_split_price(self, book_transactions): tr = book_transactions.transactions(description="my purchase of stock") sp = tr.splits(account=book_transactions.accounts(name="broker")) assert len(book_transactions.prices) == 6 p = [p for p in book_transactions.prices if p.date.day == 29][0] assert p.value == (sp.value / sp.quantity).quantize(Decimal("0.000001")) # changing the quantity of the split should change the existing price sp.quantity = (5, 1) book_transactions.validate() assert len(book_transactions.prices) == 6 assert p.value == (sp.value / sp.quantity).quantize(Decimal("0.000001")) # changing the post date of the transaction of the split should create a new price tr.post_date = datetime(2015, 1, 29, tzinfo=tr.post_date.tzinfo) book_transactions.validate() assert len(book_transactions.prices) == 7
def test_tag_split_zero_quantity_with_value(self, book_transactions): broker = book_transactions.accounts(name="broker") inc = book_transactions.accounts.get(name="inc") value = Decimal(250) # Transaction recording capital gains. splits = [ Split(broker, value, quantity=0), Split(inc, -value), ] Transaction(inc.commodity, description="Capital gains", splits=splits) book_transactions.validate() # Transaction recording capital loss. splits = [ Split(broker, -value, quantity=0), Split(inc, value), ] Transaction(inc.commodity, description="Capital loss", splits=splits) book_transactions.validate() # Do the same tests with a -0.0 quantity. This Decimal has is_signed=True. mzero = Decimal("-0.00") # Transaction recording capital gains. splits = [ Split(broker, value, quantity=mzero), Split(inc, -value), ] Transaction(inc.commodity, description="Capital gains", splits=splits) book_transactions.validate() # Transaction recording capital loss. splits = [ Split(broker, -value, quantity=mzero), Split(inc, value), ] Transaction(inc.commodity, description="Capital loss", splits=splits) book_transactions.validate()