def test_delete__replace_existing_split__split_with_transaction( self, book_transactions ): s = len(book_transactions.splits) transaction = book_transactions.transactions(description="my revenue") split = transaction.splits(value=1000) split_guid = split.guid assert len(transaction.splits) == 2 splits = list(transaction.splits) del transaction.splits[:] splits = [ Split( account=split.account, value=split.value * 2, quantity=split.quantity * 2, transaction=transaction, ) for split in splits ] assert len(transaction.splits) == 2 transaction.splits[:] = splits assert split.transaction is None assert len(transaction.splits) == 2 book_transactions.flush() book_transactions.save() # check that previous split has been deleted with pytest.raises(KeyError, match="Could not find object with {'guid'"): split = book_transactions.splits(guid=split_guid) ns = len(book_transactions.splits) assert ns == s
def test_delete_existing_transaction(self, book_transactions): l = len(book_transactions.transactions) s = len(book_transactions.splits) tr = book_transactions.transactions(description="my revenue") book_transactions.delete(tr) book_transactions.save() nl = len(book_transactions.transactions) ns = len(book_transactions.splits) assert nl == l - 1 assert ns == s - 2
def test_delete_existing_transaction(self, book_transactions): l = len(book_transactions.transactions) s = len(book_transactions.splits) tr = book_transactions.transactions(description="my revenue") book_transactions.delete(tr) book_transactions.save() nl = len(book_transactions.transactions) ns = len(book_transactions.splits) assert nl == l - 1 assert ns == s - 2
def test_delete__replace_existing_split(self, book_transactions): s = len(book_transactions.splits) transaction = book_transactions.transactions(description="my revenue") split = transaction.splits(value=1000) assert len(transaction.splits) == 2 splits = [ Split( account=split.account, value=split.value, quantity=split.quantity, ) for split in list(transaction.splits) ] assert len(transaction.splits) == 2 transaction.splits[:] = splits assert split.transaction is None assert len(transaction.splits) == 2 book_transactions.flush() book_transactions.save() ns = len(book_transactions.splits) assert ns == s