Cover the transfer price and the required loss price
This commit is contained in:
1 parent
d8557f0d70
commit
1cdb31b773
1 file changed
+38
-1
+38
-1
@@ -295,8 +295,45 @@ class TaxTestCase(unittest.TestCase):
|
||||
self.assertEqual(tax.btc_price_ore(buy), 100000000)
|
||||
self.assertEqual(tax.btc_price_ore(sale), 5000000000)
|
||||
|
||||
def test_btc_price_of_a_transfer_pair(self):
|
||||
source = create_market("Børs_01")
|
||||
destination = create_market("Lommebok", kind="wallet")
|
||||
# 2,0 BTC for 400 000 kr: 200 000 kr per BTC.
|
||||
create_transaction(market_id=source, date="2024-01-10",
|
||||
leg_in_sats=200000000, leg_out_ore=40000000)
|
||||
transfer = create_transaction(market_id=source, date="2024-06-01",
|
||||
type="transfer_out", leg_out_sats=100000000,
|
||||
fee_sats=1000, to_market_id=destination,
|
||||
transfer_group="group-1")
|
||||
create_transaction(market_id=destination, date="2024-06-01", type="transfer_in",
|
||||
leg_in_sats=100000000, fee_sats=0, to_market_id=source,
|
||||
transfer_group="group-1", generated=1)
|
||||
ledger.rebuild()
|
||||
parts = consumptions(transfer)
|
||||
mirror = lots_of(destination)[0]
|
||||
out_row = {
|
||||
"type": "transfer_out",
|
||||
"cost_ore": sum(part["cost_ore"] for part in parts),
|
||||
"consumed_sats": sum(part["sats"] for part in parts),
|
||||
}
|
||||
in_row = {
|
||||
"type": "transfer_in",
|
||||
"lot_cost_ore": mirror["cost_ore_original"],
|
||||
"lot_sats": mirror["sats_original"],
|
||||
}
|
||||
# Both sides carry the price of the source lot, fee or no fee.
|
||||
self.assertEqual(tax.btc_price_ore(out_row), 20000000)
|
||||
self.assertEqual(tax.btc_price_ore(in_row), 20000000)
|
||||
|
||||
def test_a_loss_needs_its_price(self):
|
||||
markets = {1: {"id": 1, "name": "Børs_01", "taxable": 1}}
|
||||
_, errors = validation.validate_transaction(
|
||||
{"date": "2024-01-01", "type": "loss", "market_id": 1,
|
||||
"leg_out_sats": "1 000"}, markets)
|
||||
self.assertEqual(errors, {"value_ore": "Fyll ut prisen i kroner."})
|
||||
|
||||
def test_btc_price_is_none_where_there_is_none(self):
|
||||
for tx_type in ("transfer_out", "transfer_in", "gift_given", "admin_cost"):
|
||||
for tx_type in ("gift_given", "admin_cost"):
|
||||
self.assertIsNone(tax.btc_price_ore({
|
||||
"type": tx_type, "leg_in_sats": None, "leg_in_ore": None,
|
||||
"leg_out_sats": 1000, "leg_out_ore": None, "value_ore": 1000000,
|
||||
|
||||
Reference in new issue
Block a user